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
+10 -10
View File
@@ -6,7 +6,6 @@ from functools import partial
from ebook_converter.utils.icu import safe_chr, ord_string
from ebook_converter.utils.fonts.sfnt.container import Sfnt
from ebook_converter.utils.fonts.sfnt.errors import UnsupportedFont, NoGlyphs
from ebook_converter.polyglot.builtins import iteritems, itervalues
__license__ = 'GPL v3'
@@ -17,7 +16,7 @@ __docformat__ = 'restructuredtext en'
def resolve_glyphs(loca, glyf, character_map, extra_glyphs):
unresolved_glyphs = set(itervalues(character_map)) | extra_glyphs
unresolved_glyphs = set(character_map.values()) | extra_glyphs
unresolved_glyphs.add(0) # We always want the .notdef glyph
resolved_glyphs = {}
@@ -33,7 +32,7 @@ def resolve_glyphs(loca, glyf, character_map, extra_glyphs):
if gid not in resolved_glyphs:
unresolved_glyphs.add(gid)
return OrderedDict(sorted(iteritems(resolved_glyphs), key=itemgetter(0)))
return OrderedDict(sorted(resolved_glyphs.items(), key=itemgetter(0)))
def subset_truetype(sfnt, character_map, extra_glyphs):
@@ -52,7 +51,7 @@ def subset_truetype(sfnt, character_map, extra_glyphs):
'set, subsetting it is pointless')
# Keep only character codes that have resolved glyphs
for code, glyph_id in tuple(iteritems(character_map)):
for code, glyph_id in tuple(character_map.items()):
if glyph_id not in resolved_glyphs:
del character_map[code]
@@ -154,7 +153,7 @@ def subset(raw, individual_chars, ranges=(), warnings=None):
gsub = sfnt[b'GSUB']
try:
gsub.decompile()
extra_glyphs = gsub.all_substitutions(itervalues(character_map))
extra_glyphs = gsub.all_substitutions(character_map.values())
except UnsupportedFont as e:
warn('Usupported GSUB table: %s'%e)
except Exception:
@@ -175,7 +174,7 @@ def subset(raw, individual_chars, ranges=(), warnings=None):
if b'kern' in sfnt:
try:
sfnt[b'kern'].restrict_to_glyphs(frozenset(itervalues(character_map)))
sfnt[b'kern'].restrict_to_glyphs(frozenset(character_map.values()))
except UnsupportedFont as e:
warn('kern table unsupported, ignoring: %s'%e)
except Exception:
@@ -214,8 +213,8 @@ def print_stats(old_stats, new_stats):
prints('Table', ' ', '%10s'%'Size', ' ', 'Percent', ' ', '%10s'%'New Size',
' New Percent')
prints('='*80)
old_total = sum(itervalues(old_stats))
new_total = sum(itervalues(new_stats))
old_total = sum(old_stats.values())
new_total = sum(new_stats.values())
tables = sorted(old_stats, key=lambda x:old_stats[x],
reverse=True)
for table in tables:
@@ -350,7 +349,8 @@ def all():
print('Failed!')
failed.append((font['full_name'], font['path'], str(e)))
else:
averages.append(sum(itervalues(new_stats))/sum(itervalues(old_stats)) * 100)
averages.append(sum(new_stats.values()) /
sum(old_stats.values()) * 100)
print('Reduced to:', '%.1f'%averages[-1] , '%')
if unsupported:
print('\n\nUnsupported:')
@@ -359,7 +359,7 @@ def all():
print()
if warnings:
print('\n\nWarnings:')
for name, w in iteritems(warnings):
for name, w in warnings.items():
if w:
print(name)
print('', '\n\t'.join(w), sep='\t')