1
0
mirror of https://github.com/gryf/ebook-converter.git synced 2026-04-23 14:41:30 +02:00

Removed iteritems and itervalues, which are redundant

This commit is contained in:
2020-04-21 18:20:08 +02:00
parent 9e076e0af4
commit 3234e4de27
82 changed files with 382 additions and 457 deletions
@@ -49,7 +49,6 @@ from ebook_converter.utils.ipc.simple_worker import WorkerError, fork_job
from ebook_converter.utils.logging import default_log
from ebook_converter.utils.xml_parse import safe_xml_fromstring
from ebook_converter.utils.zipfile import ZipFile
from ebook_converter.polyglot.builtins import iteritems
exists, join, relpath = os.path.exists, os.path.join, os.path.relpath
@@ -306,7 +305,7 @@ class Container(ContainerBase): # {{{
'tweak_mode': self.tweak_mode,
'name_path_map': {
name:os.path.join(dest_dir, os.path.relpath(path, self.root))
for name, path in iteritems(self.name_path_map)}
for name, path in self.name_path_map.items()}
}
def clone_data(self, dest_dir):
@@ -667,7 +666,7 @@ class Container(ContainerBase): # {{{
for item in self.opf_xpath('//opf:manifest/opf:item[@href and @media-type]'):
ans[item.get('media-type').lower()].append(self.href_to_name(
item.get('href'), self.opf_name))
return {mt:tuple(v) for mt, v in iteritems(ans)}
return {mt:tuple(v) for mt, v in ans.items()}
def manifest_items_with_property(self, property_name):
' All manifest items that have the specified property '
@@ -685,7 +684,7 @@ class Container(ContainerBase): # {{{
predicate = predicate.__eq__
elif hasattr(predicate, '__contains__'):
predicate = predicate.__contains__
for mt, names in iteritems(self.manifest_type_map):
for mt, names in self.manifest_type_map.items():
if predicate(mt):
for name in names:
yield name
@@ -807,7 +806,7 @@ class Container(ContainerBase): # {{{
the form (name, linear). Will raise an error if one of the names is not
present in the manifest. '''
imap = self.manifest_id_map
imap = {name:item_id for item_id, name in iteritems(imap)}
imap = {name:item_id for item_id, name in imap.items()}
items = [item for item, name, linear in self.spine_iter]
tail, last_tail = (items[0].tail, items[-1].tail) if items else ('\n ', '\n ')
tuple(map(self.remove_from_xml, items))
@@ -1071,7 +1070,7 @@ class Container(ContainerBase): # {{{
if set(self.name_path_map) != set(other.name_path_map):
return 'Set of files is not the same'
mismatches = []
for name, path in iteritems(self.name_path_map):
for name, path in self.name_path_map.items():
opath = other.name_path_map[name]
with open(path, 'rb') as f1, open(opath, 'rb') as f2:
if f1.read() != f2.read():
@@ -1275,7 +1274,7 @@ class EpubContainer(Container):
return
package_id = raw_unique_identifier = idpf_key = None
for attrib, val in iteritems(self.opf.attrib):
for attrib, val in self.opf.attrib.items():
if attrib.endswith('unique-identifier'):
package_id = val
break
@@ -1304,7 +1303,7 @@ class EpubContainer(Container):
self.log.exception('Failed to parse obfuscation key')
key = None
for font, alg in iteritems(fonts):
for font, alg in fonts.items():
tkey = key if alg == ADOBE_OBFUSCATION else idpf_key
if not tkey:
raise ObfuscationKeyMissing('Failed to find obfuscation key')
@@ -1374,7 +1373,7 @@ class EpubContainer(Container):
et = et.encode('ascii')
f.write(et)
zip_rebuilder(self.root, outpath)
for name, data in iteritems(restore_fonts):
for name, data in restore_fonts.items():
with self.open(name, 'wb') as f:
f.write(data)