mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Use same decoding logic for OPF as for (X)HTML.
This commit is contained in:
parent
7b2064221e
commit
cecfa09b95
@ -1009,13 +1009,16 @@ class OEBBook(object):
|
|||||||
return nroot
|
return nroot
|
||||||
|
|
||||||
def _read_opf(self, opfpath):
|
def _read_opf(self, opfpath):
|
||||||
opf = self.container.read(opfpath)
|
data = self.container.read(opfpath)
|
||||||
|
data = self.decode(data)
|
||||||
|
data = XMLDECL_RE.sub('', data)
|
||||||
|
data = data.replace('\r\n', '\n').replace('\r', '\n')
|
||||||
try:
|
try:
|
||||||
opf = etree.fromstring(opf)
|
opf = etree.fromstring(data)
|
||||||
except etree.XMLSyntaxError:
|
except etree.XMLSyntaxError:
|
||||||
repl = lambda m: ENTITYDEFS.get(m.group(1), m.group(0))
|
repl = lambda m: ENTITYDEFS.get(m.group(1), m.group(0))
|
||||||
opf = ENTITY_RE.sub(repl, opf)
|
data = ENTITY_RE.sub(repl, data)
|
||||||
opf = etree.fromstring(opf)
|
opf = etree.fromstring(data)
|
||||||
self.logger.warn('OPF contains invalid HTML named entities')
|
self.logger.warn('OPF contains invalid HTML named entities')
|
||||||
ns = namespace(opf.tag)
|
ns = namespace(opf.tag)
|
||||||
if ns not in ('', OPF1_NS, OPF2_NS):
|
if ns not in ('', OPF1_NS, OPF2_NS):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user