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/') \
|
elif self.media_type.startswith('application/') \
|
||||||
and self.media_type.endswith('+xml'):
|
and self.media_type.endswith('+xml'):
|
||||||
data = etree.fromstring(data, parser=XML_PARSER)
|
data = etree.fromstring(data, parser=XML_PARSER)
|
||||||
|
self._data = data
|
||||||
return data
|
return data
|
||||||
def fset(self, value):
|
def fset(self, value):
|
||||||
self._data = value
|
self._data = value
|
||||||
@ -476,6 +477,12 @@ class TOC(object):
|
|||||||
node = TOC(title, href, klass, id)
|
node = TOC(title, href, klass, id)
|
||||||
self.nodes.append(node)
|
self.nodes.append(node)
|
||||||
return node
|
return node
|
||||||
|
|
||||||
|
def iterdescendents(self):
|
||||||
|
for node in self.nodes:
|
||||||
|
yield node
|
||||||
|
for child in node.iterdescendents():
|
||||||
|
yield child
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
for node in self.nodes:
|
for node in self.nodes:
|
||||||
|
@ -128,7 +128,7 @@ class UnBinary(object):
|
|||||||
self.dir = os.path.dirname(path)
|
self.dir = os.path.dirname(path)
|
||||||
buf = StringIO()
|
buf = StringIO()
|
||||||
self.binary_to_text(bin, buf)
|
self.binary_to_text(bin, buf)
|
||||||
self.raw = buf.getvalue().lstrip().decode('utf-8')
|
self.raw = buf.getvalue().lstrip()
|
||||||
self.escape_reserved()
|
self.escape_reserved()
|
||||||
self._tree = None
|
self._tree = None
|
||||||
|
|
||||||
@ -157,6 +157,9 @@ class UnBinary(object):
|
|||||||
return '/'.join(relpath)
|
return '/'.join(relpath)
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
|
return self.raw.decode('utf-8')
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
return self.raw
|
return self.raw
|
||||||
|
|
||||||
def tree():
|
def tree():
|
||||||
@ -837,7 +840,7 @@ class LitReader(object):
|
|||||||
content += etree.tostring(unbin.tree,
|
content += etree.tostring(unbin.tree,
|
||||||
encoding='ascii', pretty_print=True)
|
encoding='ascii', pretty_print=True)
|
||||||
else:
|
else:
|
||||||
content += unicode(unbin)
|
content += str(unbin)
|
||||||
else:
|
else:
|
||||||
internal = '/'.join(('/data', entry.internal))
|
internal = '/'.join(('/data', entry.internal))
|
||||||
content = self._litfile.get_file(internal)
|
content = self._litfile.get_file(internal)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user