mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 10:44:09 -04:00
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:
parent
f207feb95f
commit
d2670e18e3
@ -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:
|
||||
|
@ -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")
|
||||
|
Loading…
x
Reference in New Issue
Block a user