mirror of
https://github.com/gryf/ebook-converter.git
synced 2026-04-21 05:31:30 +02:00
Removed iteritems and itervalues, which are redundant
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import codecs, shutil, os, posixpath
|
||||
from ebook_converter.polyglot.builtins import iteritems, itervalues
|
||||
from functools import partial
|
||||
from collections import Counter, defaultdict
|
||||
import urllib.parse
|
||||
@@ -115,7 +114,7 @@ def replace_links(container, link_map, frag_map=lambda name, frag:frag, replace_
|
||||
:param replace_in_opf: If False, links are not replaced in the OPF file.
|
||||
|
||||
'''
|
||||
for name, media_type in iteritems(container.mime_map):
|
||||
for name, media_type in container.mime_map.items():
|
||||
if name == container.opf_name and not replace_in_opf:
|
||||
continue
|
||||
repl = LinkReplacer(name, container, link_map, frag_map)
|
||||
@@ -131,7 +130,7 @@ def replace_ids(container, id_map):
|
||||
|
||||
'''
|
||||
changed = False
|
||||
for name, media_type in iteritems(container.mime_map):
|
||||
for name, media_type in container.mime_map.items():
|
||||
repl = IdReplacer(name, container, id_map)
|
||||
container.replace_links(name, repl)
|
||||
if name == container.opf_name:
|
||||
@@ -183,19 +182,19 @@ def rename_files(container, file_map):
|
||||
:param file_map: A mapping of old canonical name to new canonical name, for
|
||||
example: :code:`{'text/chapter1.html': 'chapter1.html'}`.
|
||||
'''
|
||||
overlap = set(file_map).intersection(set(itervalues(file_map)))
|
||||
overlap = set(file_map).intersection(set(file_map.values()))
|
||||
if overlap:
|
||||
raise ValueError('Circular rename detected. The files %s are both rename targets and destinations' % ', '.join(overlap))
|
||||
for name, dest in iteritems(file_map):
|
||||
for name, dest in file_map.items():
|
||||
if container.exists(dest):
|
||||
if name != dest and name.lower() == dest.lower():
|
||||
# A case change on an OS with a case insensitive file-system.
|
||||
continue
|
||||
raise ValueError('Cannot rename {0} to {1} as {1} already exists'.format(name, dest))
|
||||
if len(tuple(itervalues(file_map))) != len(set(itervalues(file_map))):
|
||||
if len(file_map.values()) != len(set(file_map.values())):
|
||||
raise ValueError('Cannot rename, the set of destination files contains duplicates')
|
||||
link_map = {}
|
||||
for current_name, new_name in iteritems(file_map):
|
||||
for current_name, new_name in file_map.items():
|
||||
container.rename(current_name, new_name)
|
||||
if new_name != container.opf_name: # OPF is handled by the container
|
||||
link_map[current_name] = new_name
|
||||
@@ -217,7 +216,7 @@ def replace_file(container, name, path, basename, force_mt=None):
|
||||
rename_files(container, {name:nname})
|
||||
mt = force_mt or container.guess_type(nname)
|
||||
container.mime_map[nname] = mt
|
||||
for itemid, q in iteritems(container.manifest_id_map):
|
||||
for itemid, q in container.manifest_id_map.items():
|
||||
if q == nname:
|
||||
for item in container.opf_xpath('//opf:manifest/opf:item[@href and @id="%s"]' % itemid):
|
||||
item.set('media-type', mt)
|
||||
@@ -252,7 +251,7 @@ def get_recommended_folders(container, names):
|
||||
recommended folder is assumed to be the folder containing the OPF file. '''
|
||||
from ebook_converter.ebooks.oeb.polish.utils import guess_type
|
||||
counts = defaultdict(Counter)
|
||||
for name, mt in iteritems(container.mime_map):
|
||||
for name, mt in container.mime_map.items():
|
||||
folder = name.rpartition('/')[0] if '/' in name else ''
|
||||
counts[mt_to_category(container, mt)][folder] += 1
|
||||
|
||||
@@ -261,7 +260,7 @@ def get_recommended_folders(container, names):
|
||||
except KeyError:
|
||||
opf_folder = ''
|
||||
|
||||
recommendations = {category:counter.most_common(1)[0][0] for category, counter in iteritems(counts)}
|
||||
recommendations = {category:counter.most_common(1)[0][0] for category, counter in counts.items()}
|
||||
return {n:recommendations.get(mt_to_category(container, guess_type(os.path.basename(n))), opf_folder) for n in names}
|
||||
|
||||
|
||||
@@ -348,7 +347,7 @@ def remove_links_to(container, predicate):
|
||||
stylepath = XPath('//h:style')
|
||||
styleattrpath = XPath('//*[@style]')
|
||||
changed = set()
|
||||
for name, mt in iteritems(container.mime_map):
|
||||
for name, mt in container.mime_map.items():
|
||||
removed = False
|
||||
if mt in OEB_DOCS:
|
||||
root = container.parsed(name)
|
||||
|
||||
Reference in New Issue
Block a user