Fix #1275 (converting opf to epub)

This commit is contained in:
Kovid Goyal 2008-11-17 16:59:37 -08:00
parent a4efa9b305
commit e6d872c317
2 changed files with 8 additions and 7 deletions

View File

@ -30,7 +30,7 @@ def detect(aBuf):
# Added by Kovid
ENCODING_PATS = [
re.compile(r'<[^<>]+encoding=[\'"](.*?)[\'"][^<>]*>', re.IGNORECASE),
re.compile(r'<\?[^<>]+encoding=[\'"](.*?)[\'"][^<>]*>', re.IGNORECASE),
re.compile(r'<meta.*?content=[\'"].*?charset=([^\s\'"]+).*?[\'"].*?>', re.IGNORECASE)
]
ENTITY_PATTERN = re.compile(r'&(\S+?);')

View File

@ -273,8 +273,9 @@ class Spine(ResourceCollection):
for itemref in itemrefs:
idref = itemref.get('idref', None)
if idref is not None:
r = Spine.Item(s.manifest.id_for_path,
s.manifest.path_for_id(idref), is_path=True)
path = s.manifest.path_for_id(idref)
if path:
r = Spine.Item(s.manifest.id_for_path, path, is_path=True)
r.is_linear = itemref.get('linear', 'yes') == 'yes'
s.append(r)
return s
@ -439,7 +440,7 @@ class OPF(object):
stream = open(stream, 'rb')
self.basedir = self.base_dir = basedir
raw, self.encoding = xml_to_unicode(stream.read(), strip_encoding_pats=True, resolve_entities=True)
raw = raw[raw.find('<'):]
self.root = etree.fromstring(raw, self.PARSER)
self.metadata = self.metadata_path(self.root)
if not self.metadata: