mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
Fix a handful of additional encoding issues. I don't like patching
cssutils, but cssutils as-is insists on decoding the contents of @imported files itself. Another option would be to just encode everything back into UTF-8 and then let cssutils decode it again, but that seems even worse than a two-line patch.
This commit is contained in:
parent
168ef41787
commit
beb45413fe
@ -474,7 +474,7 @@ class LitWriter(object):
|
|||||||
name = '/data/' + item.id
|
name = '/data/' + item.id
|
||||||
data = item.data
|
data = item.data
|
||||||
secnum = 0
|
secnum = 0
|
||||||
if not isinstance(data, basestring):
|
if isinstance(data, etree._Element):
|
||||||
self._add_folder(name)
|
self._add_folder(name)
|
||||||
rebin = ReBinary(data, item, self._oeb, map=HTML_MAP)
|
rebin = ReBinary(data, item, self._oeb, map=HTML_MAP)
|
||||||
self._add_file(name + '/ahc', rebin.ahc, 0)
|
self._add_file(name + '/ahc', rebin.ahc, 0)
|
||||||
@ -483,6 +483,8 @@ class LitWriter(object):
|
|||||||
data = rebin.content
|
data = rebin.content
|
||||||
name = name + '/content'
|
name = name + '/content'
|
||||||
secnum = 1
|
secnum = 1
|
||||||
|
elif isinstance(data, unicode):
|
||||||
|
data = data.encode('utf-8')
|
||||||
self._add_file(name, data, secnum)
|
self._add_file(name, data, secnum)
|
||||||
item.size = len(data)
|
item.size = len(data)
|
||||||
|
|
||||||
|
@ -173,7 +173,7 @@ class Stylizer(object):
|
|||||||
return (None, None)
|
return (None, None)
|
||||||
data = hrefs[path].data
|
data = hrefs[path].data
|
||||||
data = XHTML_CSS_NAMESPACE + data
|
data = XHTML_CSS_NAMESPACE + data
|
||||||
return (None, data)
|
return ('utf-8', data)
|
||||||
|
|
||||||
def flatten_rule(self, rule, href, index):
|
def flatten_rule(self, rule, href, index):
|
||||||
results = []
|
results = []
|
||||||
|
@ -840,7 +840,9 @@ def _readUrl(url, fetcher=None, overrideEncoding=None, parentEncoding=None):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
# encoding may still be wrong if encoding *is lying*!
|
# encoding may still be wrong if encoding *is lying*!
|
||||||
if content is not None:
|
if isinstance(content, unicode):
|
||||||
|
decodedCssText = content
|
||||||
|
elif content is not None:
|
||||||
decodedCssText = codecs.lookup("css")[1](content, encoding=encoding)[0]
|
decodedCssText = codecs.lookup("css")[1](content, encoding=encoding)[0]
|
||||||
else:
|
else:
|
||||||
decodedCssText = None
|
decodedCssText = None
|
||||||
|
Loading…
x
Reference in New Issue
Block a user