use list instead of get_children

This commit is contained in:
j 2024-06-08 12:23:25 +01:00
parent d29309e8b3
commit 37410d6089

View file

@ -68,17 +68,17 @@ def cover(path):
if manifest: if manifest:
manifest = manifest[0] manifest = manifest[0]
if metadata and manifest: if metadata and manifest:
for e in metadata.getchildren(): for e in list(metadata):
if e.tag == '{http://www.idpf.org/2007/opf}meta' and e.attrib.get('name') == 'cover': if e.tag == '{http://www.idpf.org/2007/opf}meta' and e.attrib.get('name') == 'cover':
cover_id = e.attrib['content'] cover_id = e.attrib['content']
for e in manifest.getchildren(): for e in list(manifest):
if e.attrib['id'] == cover_id: if e.attrib['id'] == cover_id:
filename = unquote(e.attrib['href']) filename = unquote(e.attrib['href'])
filename = normpath(os.path.join(os.path.dirname(opf[0]), filename)) filename = normpath(os.path.join(os.path.dirname(opf[0]), filename))
if filename in files: if filename in files:
return use(filename) return use(filename)
if manifest: if manifest:
images = [e for e in manifest.getchildren() if 'image' in e.attrib['media-type']] images = [e for e in list(manifest) if 'image' in e.attrib['media-type']]
if images: if images:
image_data = [] image_data = []
for e in images: for e in images:
@ -89,7 +89,7 @@ def cover(path):
if image_data: if image_data:
image_data.sort(key=lambda name: z.getinfo(name).file_size) image_data.sort(key=lambda name: z.getinfo(name).file_size)
return use(image_data[-1]) return use(image_data[-1])
for e in manifest.getchildren(): for e in list(manifest):
if 'html' in e.attrib['media-type']: if 'html' in e.attrib['media-type']:
filename = unquote(e.attrib['href']) filename = unquote(e.attrib['href'])
filename = normpath(os.path.join(os.path.dirname(opf[0]), filename)) filename = normpath(os.path.join(os.path.dirname(opf[0]), filename))
@ -118,7 +118,7 @@ def info(epub):
metadata = info.findall('{http://www.idpf.org/2007/opf}metadata') metadata = info.findall('{http://www.idpf.org/2007/opf}metadata')
if metadata: if metadata:
metadata = metadata[0] metadata = metadata[0]
for e in metadata.getchildren(): for e in list(metadata):
if e.text and e.text.strip() and e.text not in ('unknown', 'none'): if e.text and e.text.strip() and e.text not in ('unknown', 'none'):
key = e.tag.split('}')[-1] key = e.tag.split('}')[-1]
key = { key = {
@ -148,7 +148,7 @@ def info(epub):
for point in nav_map.findall('{http://www.daisy.org/z3986/2005/ncx/}navPoint'): for point in nav_map.findall('{http://www.daisy.org/z3986/2005/ncx/}navPoint'):
label = point.find('{http://www.daisy.org/z3986/2005/ncx/}navLabel') label = point.find('{http://www.daisy.org/z3986/2005/ncx/}navLabel')
if label: if label:
txt = label.getchildren()[0].text txt = list(label)[0].text
if txt: if txt:
contents.append(txt) contents.append(txt)
if contents: if contents: