Fix errors when using strftime with unicode strings on non-utf-8 windows systems. Fixes #1749219 [conversion error - failure to fetch news from nyt](https://bugs.launchpad.net/calibre/+bug/1749219)

This commit is contained in:
Kovid Goyal 2018-02-14 02:35:47 +05:30
parent f207feb95f
commit d2670e18e3
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 2 additions and 8 deletions

View File

@ -544,7 +544,7 @@ def strftime(fmt, t=None):
ans = None
if iswindows:
if isinstance(fmt, unicode):
fmt = fmt.encode('mbcs')
fmt = fmt.encode('mbcs', 'replace')
fmt = fmt.replace(b'%e', b'%#d')
ans = plugins['winutil'][0].strftime(fmt, t)
else:

View File

@ -11,7 +11,7 @@ from lxml.html.builder import HTML, HEAD, TITLE, STYLE, DIV, BODY, \
STRONG, BR, SPAN, A, HR, UL, LI, H2, H3, IMG, P as PT, \
TABLE, TD, TR
from calibre import preferred_encoding, strftime, isbytestring
from calibre import strftime, isbytestring
def CLASS(*args, **kwargs): # class is a reserved word in Python
@ -88,8 +88,6 @@ class IndexTemplate(Template):
def _generate(self, title, masthead, datefmt, feeds, extra_css=None, style=None):
self.IS_HTML = False
if isinstance(datefmt, unicode):
datefmt = datefmt.encode(preferred_encoding)
date = strftime(datefmt)
head = HEAD(TITLE(title))
if style:
@ -245,11 +243,7 @@ class NavBarTemplate(Template):
class TouchscreenIndexTemplate(Template):
def _generate(self, title, masthead, datefmt, feeds, extra_css=None, style=None):
self.IS_HTML = False
if isinstance(datefmt, unicode):
datefmt = datefmt.encode(preferred_encoding)
date = '%s, %s %s, %s' % (strftime('%A'), strftime('%B'), strftime('%d').lstrip('0'), strftime('%Y'))
masthead_p = etree.Element("p")
masthead_p.set("style","text-align:center")