Fix various itervalues() that dict_fixes missed

This commit is contained in:
Kovid Goyal 2019-03-25 15:39:39 +05:30
parent 0fcad5f21f
commit c8688930ad
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
11 changed files with 27 additions and 25 deletions

View File

@ -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

View File

@ -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

View File

@ -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)'%(

View File

@ -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]

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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:')

View File

@ -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:

View File

@ -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)))

View File

@ -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)