Assign opf, opf_filepath normally instead of mutating in method.
This commit is contained in:
parent
6386f25cd4
commit
1f1b36b173
1 changed files with 6 additions and 8 deletions
14
epubfile.py
14
epubfile.py
|
@ -311,10 +311,9 @@ class Epub:
|
||||||
|
|
||||||
self._original_path = _original_epub_filepath or self.root_directory.absolute_path
|
self._original_path = _original_epub_filepath or self.root_directory.absolute_path
|
||||||
|
|
||||||
self.opf_filepath = None
|
opfs = self.get_opfs()
|
||||||
self.opf = None
|
self.opf_filepath = opfs[0]
|
||||||
|
self.opf = self.read_opf(self.opf_filepath)
|
||||||
self.read_opf(self.get_opfs()[0])
|
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f'Epub({repr(self.root_directory.absolute_path)})'
|
return f'Epub({repr(self.root_directory.absolute_path)})'
|
||||||
|
@ -402,10 +401,10 @@ class Epub:
|
||||||
# parsing only the metadata block, but loses all namespaces when parsing
|
# parsing only the metadata block, but loses all namespaces when parsing
|
||||||
# the whole doc. 'lxml' wraps the content in <html><body> and also
|
# the whole doc. 'lxml' wraps the content in <html><body> and also
|
||||||
# botches the metas so it's not any better than html.parser.
|
# botches the metas so it's not any better than html.parser.
|
||||||
self.opf = bs4.BeautifulSoup(rootfile_xml, 'html.parser')
|
opf = bs4.BeautifulSoup(rootfile_xml, 'html.parser')
|
||||||
|
|
||||||
# Let's fix those metas.
|
# Let's fix those metas.
|
||||||
metas = self.opf.select('meta')
|
metas = opf.select('meta')
|
||||||
for meta in metas:
|
for meta in metas:
|
||||||
neighbor = meta.next
|
neighbor = meta.next
|
||||||
if neighbor.parent != meta.parent:
|
if neighbor.parent != meta.parent:
|
||||||
|
@ -415,8 +414,7 @@ class Epub:
|
||||||
continue
|
continue
|
||||||
meta.append(neighbor.extract().strip())
|
meta.append(neighbor.extract().strip())
|
||||||
|
|
||||||
self.opf_filepath = rootfile
|
return opf
|
||||||
return self.opf
|
|
||||||
|
|
||||||
def write_container_xml(self, container):
|
def write_container_xml(self, container):
|
||||||
if isinstance(container, bs4.BeautifulSoup):
|
if isinstance(container, bs4.BeautifulSoup):
|
||||||
|
|
Loading…
Reference in a new issue