mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix some str vs. unicode issues. Re-add dropped TOC.iterdescendents() method.
This commit is contained in:
parent
83470f3d6b
commit
0c7a0b831d
@ -247,6 +247,7 @@ class Manifest(object):
|
||||
elif self.media_type.startswith('application/') \
|
||||
and self.media_type.endswith('+xml'):
|
||||
data = etree.fromstring(data, parser=XML_PARSER)
|
||||
self._data = data
|
||||
return data
|
||||
def fset(self, value):
|
||||
self._data = value
|
||||
@ -477,6 +478,12 @@ class TOC(object):
|
||||
self.nodes.append(node)
|
||||
return node
|
||||
|
||||
def iterdescendents(self):
|
||||
for node in self.nodes:
|
||||
yield node
|
||||
for child in node.iterdescendents():
|
||||
yield child
|
||||
|
||||
def __iter__(self):
|
||||
for node in self.nodes:
|
||||
yield node
|
||||
|
@ -128,7 +128,7 @@ class UnBinary(object):
|
||||
self.dir = os.path.dirname(path)
|
||||
buf = StringIO()
|
||||
self.binary_to_text(bin, buf)
|
||||
self.raw = buf.getvalue().lstrip().decode('utf-8')
|
||||
self.raw = buf.getvalue().lstrip()
|
||||
self.escape_reserved()
|
||||
self._tree = None
|
||||
|
||||
@ -157,6 +157,9 @@ class UnBinary(object):
|
||||
return '/'.join(relpath)
|
||||
|
||||
def __unicode__(self):
|
||||
return self.raw.decode('utf-8')
|
||||
|
||||
def __str__(self):
|
||||
return self.raw
|
||||
|
||||
def tree():
|
||||
@ -837,7 +840,7 @@ class LitReader(object):
|
||||
content += etree.tostring(unbin.tree,
|
||||
encoding='ascii', pretty_print=True)
|
||||
else:
|
||||
content += unicode(unbin)
|
||||
content += str(unbin)
|
||||
else:
|
||||
internal = '/'.join(('/data', entry.internal))
|
||||
content = self._litfile.get_file(internal)
|
||||
|
Loading…
x
Reference in New Issue
Block a user