From c8688930ad487c4de049268d65724386b9894cbe Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 25 Mar 2019 15:39:39 +0530 Subject: [PATCH] Fix various itervalues() that dict_fixes missed --- src/calibre/customize/__init__.py | 4 ++-- src/calibre/devices/smart_device_app/driver.py | 4 ++-- src/calibre/ebooks/mobi/debug/mobi8.py | 4 ++-- src/calibre/ebooks/pdf/render/engine.py | 4 ++-- src/calibre/gui2/actions/__init__.py | 2 +- src/calibre/gui2/store/loader.py | 4 ++-- src/calibre/srv/utils.py | 3 ++- src/calibre/utils/fonts/sfnt/subset.py | 14 +++++++------- src/calibre/utils/winreg/default_programs.py | 6 +++--- src/calibre/utils/winreg/lib.py | 5 +++-- src/duktape/__init__.py | 2 +- 11 files changed, 27 insertions(+), 25 deletions(-) diff --git a/src/calibre/customize/__init__.py b/src/calibre/customize/__init__.py index 15568991f7..d69a338d82 100644 --- a/src/calibre/customize/__init__.py +++ b/src/calibre/customize/__init__.py @@ -212,7 +212,7 @@ class Plugin(object): # {{{ For example to load an image:: pixmap = QPixmap() - next(pixmap.loadFromData(self.load_resources(['images/icon.png']).itervalues()) + next(pixmap.loadFromData(self.load_resources(['images/icon.png']).values()) icon = QIcon(pixmap) :param names: List of paths to resources in the ZIP file using / as separator @@ -744,7 +744,7 @@ class ViewerPlugin(Plugin): # {{{ def load_fonts(): from PyQt5.Qt import QFontDatabase font_data = get_resources(['myfont1.ttf', 'myfont2.ttf']) - for raw in font_data.itervalues(): + for raw in font_data.values(): QFontDatabase.addApplicationFontFromData(raw) ''' pass diff --git a/src/calibre/devices/smart_device_app/driver.py b/src/calibre/devices/smart_device_app/driver.py index 366a5dd467..03e15227e5 100644 --- a/src/calibre/devices/smart_device_app/driver.py +++ b/src/calibre/devices/smart_device_app/driver.py @@ -37,7 +37,7 @@ from calibre.utils.filenames import ascii_filename as sanitize, shorten_componen from calibre.utils.mdns import (publish as publish_zeroconf, unpublish as unpublish_zeroconf, get_all_ips) from calibre.utils.socket_inheritance import set_socket_inherit -from polyglot.builtins import unicode_type, iteritems +from polyglot.builtins import unicode_type, iteritems, itervalues from polyglot import queue @@ -758,7 +758,7 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin): def _uuid_in_cache(self, uuid, ext): try: - for b in self.device_book_cache.itervalues(): + for b in itervalues(self.device_book_cache): metadata = b['book'] if metadata.get('uuid', '') != uuid: continue diff --git a/src/calibre/ebooks/mobi/debug/mobi8.py b/src/calibre/ebooks/mobi/debug/mobi8.py index f8eef4fade..5e282fe39e 100644 --- a/src/calibre/ebooks/mobi/debug/mobi8.py +++ b/src/calibre/ebooks/mobi/debug/mobi8.py @@ -19,7 +19,7 @@ from calibre.ebooks.mobi.utils import read_font_record, decode_tbs, RECORD_SIZE from calibre.ebooks.mobi.debug import format_bytes from calibre.ebooks.mobi.reader.headers import NULL_INDEX from calibre.utils.imghdr import what -from polyglot.builtins import zip, iteritems +from polyglot.builtins import zip, iteritems, itervalues class FDST(object): @@ -256,7 +256,7 @@ class MOBIFile(object): desc = ['Record #%d'%i] for s, strand in enumerate(strands): desc.append('Strand %d'%s) - for entries in strand.itervalues(): + for entries in itervalues(strand): for e in entries: desc.append( ' %s%d [%-9s] parent: %s (%d) Geometry: (%d, %d)'%( diff --git a/src/calibre/ebooks/pdf/render/engine.py b/src/calibre/ebooks/pdf/render/engine.py index ac823c2328..8cb0343df3 100644 --- a/src/calibre/ebooks/pdf/render/engine.py +++ b/src/calibre/ebooks/pdf/render/engine.py @@ -20,7 +20,7 @@ from calibre.ebooks.pdf.render.common import inch, A4, fmtnum from calibre.ebooks.pdf.render.graphics import convert_path, Graphics from calibre.utils.fonts.sfnt.container import Sfnt, UnsupportedFont from calibre.utils.fonts.sfnt.metrics import FontMetrics -from polyglot.builtins import codepoint_to_chr +from polyglot.builtins import codepoint_to_chr, itervalues Point = namedtuple('Point', 'x y') ColorState = namedtuple('ColorState', 'color opacity do') @@ -340,7 +340,7 @@ class PdfEngine(QPaintEngine): self.pdf.links.add_outline(toc) def add_links(self, current_item, start_page, links, anchors): - for pos in anchors.itervalues(): + for pos in itervalues(anchors): pos['left'], pos['top'] = self.pdf_system.map(pos['left'], pos['top']) for link in links: pos = link[1] diff --git a/src/calibre/gui2/actions/__init__.py b/src/calibre/gui2/actions/__init__.py index 92c59c3444..7647cbfd82 100644 --- a/src/calibre/gui2/actions/__init__.py +++ b/src/calibre/gui2/actions/__init__.py @@ -278,7 +278,7 @@ class InterfaceAction(QObject): For example to load an image:: pixmap = QPixmap() - next(pixmap.loadFromData(self.load_resources(['images/icon.png']).itervalues())) + next(pixmap.loadFromData(self.load_resources(['images/icon.png']).values())) icon = QIcon(pixmap) :param names: List of paths to resources in the ZIP file using / as separator diff --git a/src/calibre/gui2/store/loader.py b/src/calibre/gui2/store/loader.py index 3f6ac0b2f6..47cf8b37e3 100644 --- a/src/calibre/gui2/store/loader.py +++ b/src/calibre/gui2/store/loader.py @@ -17,7 +17,7 @@ from calibre.constants import numeric_version, DEBUG from calibre.gui2.store import StorePlugin from calibre.utils.config import JSONConfig from polyglot.urllib import urlencode -from polyglot.builtins import iteritems +from polyglot.builtins import iteritems, itervalues class VersionMismatch(ValueError): @@ -179,7 +179,7 @@ class Stores(OrderedDict): exec(src, namespace) ver = namespace['store_version'] cls = None - for x in namespace.itervalues(): + for x in itervalues(namespace): if (isinstance(x, type) and issubclass(x, StorePlugin) and x is not StorePlugin): cls = x diff --git a/src/calibre/srv/utils.py b/src/calibre/srv/utils.py index aa79d5c147..7e74d2b057 100644 --- a/src/calibre/srv/utils.py +++ b/src/calibre/srv/utils.py @@ -67,7 +67,8 @@ class MultiDict(dict): # {{{ iteritems = items def values(self, duplicates=True): - for v in dict.itervalues(self): + f = dict.values if ispy3 else dict.itervalues + for v in f(self): if duplicates: for x in v: yield x diff --git a/src/calibre/utils/fonts/sfnt/subset.py b/src/calibre/utils/fonts/sfnt/subset.py index 1af743c763..956248bb10 100644 --- a/src/calibre/utils/fonts/sfnt/subset.py +++ b/src/calibre/utils/fonts/sfnt/subset.py @@ -15,13 +15,13 @@ from functools import partial from calibre.utils.icu import safe_chr, ord_string from calibre.utils.fonts.sfnt.container import Sfnt from calibre.utils.fonts.sfnt.errors import UnsupportedFont, NoGlyphs -from polyglot.builtins import unicode_type, range, iteritems +from polyglot.builtins import unicode_type, range, iteritems, itervalues # TrueType outlines {{{ def resolve_glyphs(loca, glyf, character_map, extra_glyphs): - unresolved_glyphs = set(character_map.itervalues()) | extra_glyphs + unresolved_glyphs = set(itervalues(character_map)) | extra_glyphs unresolved_glyphs.add(0) # We always want the .notdef glyph resolved_glyphs = {} @@ -155,7 +155,7 @@ def subset(raw, individual_chars, ranges=(), warnings=None): gsub = sfnt[b'GSUB'] try: gsub.decompile() - extra_glyphs = gsub.all_substitutions(character_map.itervalues()) + extra_glyphs = gsub.all_substitutions(itervalues(character_map)) except UnsupportedFont as e: warn('Usupported GSUB table: %s'%e) except Exception as e: @@ -176,7 +176,7 @@ def subset(raw, individual_chars, ranges=(), warnings=None): if b'kern' in sfnt: try: - sfnt[b'kern'].restrict_to_glyphs(frozenset(character_map.itervalues())) + sfnt[b'kern'].restrict_to_glyphs(frozenset(itervalues(character_map))) except UnsupportedFont as e: warn('kern table unsupported, ignoring: %s'%e) except Exception as e: @@ -215,8 +215,8 @@ def print_stats(old_stats, new_stats): prints('Table', ' ', '%10s'%'Size', ' ', 'Percent', ' ', '%10s'%'New Size', ' New Percent') prints('='*80) - old_total = sum(old_stats.itervalues()) - new_total = sum(new_stats.itervalues()) + old_total = sum(itervalues(old_stats)) + new_total = sum(itervalues(new_stats)) tables = sorted(old_stats, key=lambda x:old_stats[x], reverse=True) for table in tables: @@ -351,7 +351,7 @@ def all(): print ('Failed!') failed.append((font['full_name'], font['path'], unicode_type(e))) else: - averages.append(sum(new_stats.itervalues())/sum(old_stats.itervalues()) * 100) + averages.append(sum(itervalues(new_stats))/sum(itervalues(old_stats)) * 100) print ('Reduced to:', '%.1f'%averages[-1] , '%') if unsupported: print ('\n\nUnsupported:') diff --git a/src/calibre/utils/winreg/default_programs.py b/src/calibre/utils/winreg/default_programs.py index 0d1bfda7a4..8cb073bbf4 100644 --- a/src/calibre/utils/winreg/default_programs.py +++ b/src/calibre/utils/winreg/default_programs.py @@ -121,7 +121,7 @@ def register(): key.set_default_value(r'shell\open\command', '"%s" "%%1"' % exe) with Key('FileAssociations', root=key) as fak, Key('MimeAssociations', root=key) as mak: - # previous_associations = set(fak.itervalues()) + # previous_associations = set(fak.values()) for ext, prog_id in iteritems(prog_id_map): mt = ext_map[ext] fak.set('.' + ext, prog_id) @@ -207,7 +207,7 @@ def get_prog_id_map(base, key_path): desc = k.get_mui_string('ApplicationDescription') if desc is None: return desc, ans - for ext, prog_id in k.itervalues(sub_key='FileAssociations', get_data=True): + for ext, prog_id in k.values(sub_key='FileAssociations', get_data=True): ans[ext[1:].lower()] = prog_id return desc, ans @@ -275,7 +275,7 @@ def find_programs(extensions): continue raise with k: - for name, key_path in k.itervalues(get_data=True): + for name, key_path in k.values(get_data=True): try: app_desc, prog_id_map = get_prog_id_map(base, key_path) except Exception: diff --git a/src/calibre/utils/winreg/lib.py b/src/calibre/utils/winreg/lib.py index 741f470deb..5a3fe4dfef 100644 --- a/src/calibre/utils/winreg/lib.py +++ b/src/calibre/utils/winreg/lib.py @@ -334,6 +334,7 @@ class Key(object): finally: if sub_key is not None: RegCloseKey(key) + values = itervalues def __enter__(self): return self @@ -359,13 +360,13 @@ class Key(object): if __name__ == '__main__': from pprint import pprint k = Key(open_at=r'Software\RegisteredApplications', root=HKLM) - pprint(tuple(k.itervalues(get_data=True))) + pprint(tuple(k.values(get_data=True))) k = Key(r'Software\calibre\winregtest') k.set('Moose.Cat.1') k.set('unicode test', 'fällen粗楷体简a\U0001f471') k.set('none test') k.set_default_value(r'other\key', '%PATH%', has_expansions=True) - pprint(tuple(k.itervalues(get_data=True))) + pprint(tuple(k.values(get_data=True))) pprint(k.get('unicode test')) k.set_default_value(r'delete\me\please', 'xxx') pprint(tuple(k.iterkeynames(get_last_write_times=True))) diff --git a/src/duktape/__init__.py b/src/duktape/__init__.py index c1e10543aa..f4f7032444 100644 --- a/src/duktape/__init__.py +++ b/src/duktape/__init__.py @@ -366,7 +366,7 @@ def test_build(): def load_tests(loader, suite, pattern): from duktape import tests - for x in vars(tests).itervalues(): + for x in vars(tests).values(): if isinstance(x, type) and issubclass(x, unittest.TestCase): tests = loader.loadTestsFromTestCase(x) suite.addTests(tests)