diff --git a/setup/build_environment.py b/setup/build_environment.py index 42e5206236..bba262dc7c 100644 --- a/setup/build_environment.py +++ b/setup/build_environment.py @@ -1,7 +1,6 @@ #!/usr/bin/env python2 # vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai -from __future__ import with_statement -from __future__ import print_function +from __future__ import with_statement, print_function __license__ = 'GPL v3' __copyright__ = '2009, Kovid Goyal ' @@ -85,7 +84,7 @@ def readvar(name): pyqt = {x:readvar(y) for x, y in ( ('inc', 'QT_INSTALL_HEADERS'), ('lib', 'QT_INSTALL_LIBS') )} -qt = {x:readvar(y) for x, y in {'libs':'QT_INSTALL_LIBS', 'plugins':'QT_INSTALL_PLUGINS'}.iteritems()} +qt = {x:readvar(y) for x, y in {'libs':'QT_INSTALL_LIBS', 'plugins':'QT_INSTALL_PLUGINS'}.items()} qmakespec = readvar('QMAKE_SPEC') if iswindows else None pyqt['sip_bin'] = os.environ.get('SIP_BIN', 'sip') diff --git a/setup/resources.py b/setup/resources.py index 55febce79a..44ec0dbe57 100644 --- a/setup/resources.py +++ b/setup/resources.py @@ -1,7 +1,6 @@ #!/usr/bin/env python2 # vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai -from __future__ import with_statement -from __future__ import print_function +from __future__ import with_statement, print_function __license__ = 'GPL v3' __copyright__ = '2009, Kovid Goyal ' @@ -13,6 +12,7 @@ from itertools import chain is_ci = os.environ.get('CI', '').lower() == 'true' from setup import Command, basenames, __appname__, download_securely +from polyglot.builtins import itervalues, iteritems def get_opts_from_parser(parser): @@ -114,7 +114,7 @@ class Coffee(Command): # {{{ if updated: hashes = {} with zipfile.ZipFile(dest, 'w', zipfile.ZIP_STORED) as zf: - for raw, zi, sig in sorted(chain(updated.itervalues(), existing.itervalues()), key=lambda x: x[1].filename): + for raw, zi, sig in sorted(chain(itervalues(updated), itervalues(existing)), key=lambda x: x[1].filename): zf.writestr(zi, raw) hashes[zi.filename] = sig zf.comment = json.dumps(hashes) @@ -222,7 +222,7 @@ class Kakasi(Command): # {{{ from calibre.utils.serialize import msgpack_dumps with open(out, 'wb') as f: dic = {} - for k, v in self.records.iteritems(): + for k, v in iteritems(self.records): dic[k] = compress(msgpack_dumps(v)) f.write(msgpack_dumps(dic)) @@ -394,8 +394,8 @@ class Resources(Command): # {{{ json.dump(function_dict, open(dest, 'wb'), indent=4) self.info('\tCreating user-manual-translation-stats.json') d = {} - for lc, stats in json.load(open(self.j(self.d(self.SRC), 'manual', 'locale', 'completed.json'))).iteritems(): - total = sum(stats.itervalues()) + for lc, stats in iteritems(json.load(open(self.j(self.d(self.SRC), 'manual', 'locale', 'completed.json')))): + total = sum(itervalues(stats)) d[lc] = stats['translated'] / float(total) json.dump(d, open(self.j(self.RESOURCES, 'user-manual-translation-stats.json'), 'wb'), indent=4) diff --git a/setup/translations.py b/setup/translations.py index 0619a4c386..9cce93c98f 100644 --- a/setup/translations.py +++ b/setup/translations.py @@ -1,7 +1,6 @@ #!/usr/bin/env python2 # vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai -from __future__ import with_statement -from __future__ import print_function +from __future__ import with_statement, print_function __license__ = 'GPL v3' __copyright__ = '2009, Kovid Goyal ' @@ -14,6 +13,7 @@ from functools import partial from setup import Command, __appname__, __version__, require_git_master, build_cache_dir, edit_file from setup.parallel_build import parallel_check_output +from polyglot.builtins import iteritems is_ci = os.environ.get('CI', '').lower() == 'true' @@ -359,7 +359,7 @@ class Translations(POT): # {{{ 'en_GB', 'en_CA', 'en_AU', 'si', 'ur', 'sc', 'ltg', 'nds', 'te', 'yi', 'fo', 'sq', 'ast', 'ml', 'ku', 'fr_CA', 'him', 'jv', 'ka', 'fur', 'ber', 'my', 'fil', 'hy', 'ug'} - for f, (locale, dest) in fmap.iteritems(): + for f, (locale, dest) in iteritems(fmap): iscpo = {'bn':'bn_IN', 'zh_HK':'zh_CN'}.get(locale, locale) iso639 = self.j(self.TRANSLATIONS, 'iso_639', '%s.po'%iscpo) if os.path.exists(iso639): @@ -407,7 +407,7 @@ class Translations(POT): # {{{ raw = None po_data = data.decode('utf-8') data = json.loads(msgfmt(po_data)) - translated_entries = {k:v for k, v in data['entries'].iteritems() if v and sum(map(len, v))} + translated_entries = {k:v for k, v in iteritems(data['entries']) if v and sum(map(len, v))} data[u'entries'] = translated_entries data[u'hash'] = h.hexdigest() cdata = b'{}' @@ -488,7 +488,7 @@ class Translations(POT): # {{{ files.append((f, d)) self.compile_group(files, handle_stats=handle_stats) - for locale, translated in stats.iteritems(): + for locale, translated in iteritems(stats): if translated >= 20: with open(os.path.join(tdir, locale + '.mo'), 'rb') as f: raw = f.read() @@ -542,7 +542,7 @@ class Translations(POT): # {{{ stats['untranslated'] += nums[1] self.compile_group(files, handle_stats=handle_stats) - for locale, stats in all_stats.iteritems(): + for locale, stats in iteritems(all_stats): with open(self.j(srcbase, locale, 'stats.json'), 'wb') as f: json.dump(stats, f) total = stats['translated'] + stats['untranslated'] @@ -621,7 +621,7 @@ class GetTranslations(Translations): # {{{ changes[slug].add(lang) if changed: f.save() - for slug, languages in changes.iteritems(): + for slug, languages in iteritems(changes): print('Pushing fixes for languages: %s in %s' % (', '.join(languages), slug)) self.tx('push -r calibre.%s -t -l %s' % (slug, ','.join(languages))) diff --git a/setup/upload.py b/setup/upload.py index b9687f2213..e62f8b7607 100644 --- a/setup/upload.py +++ b/setup/upload.py @@ -10,6 +10,7 @@ import os, subprocess, hashlib, shutil, glob, stat, sys, time, json from subprocess import check_call from tempfile import NamedTemporaryFile, mkdtemp, gettempdir from zipfile import ZipFile +from polyglot.builtins import iteritems from polyglot.urllib import urlopen, urlencode if __name__ == '__main__': @@ -237,7 +238,7 @@ class UploadInstallers(Command): # {{{ print('\nRecording dist sizes') args = [ '%s:%s:%s' % (__version__, fname, size) - for fname, size in sizes.iteritems() + for fname, size in iteritems(sizes) ] check_call(['ssh', 'code', '/usr/local/bin/dist_sizes'] + args) @@ -257,7 +258,7 @@ class UploadInstallers(Command): # {{{ ) with open(os.path.join(tdir, 'fmap'), 'wb') as fo: - for f, desc in files.iteritems(): + for f, desc in iteritems(files): fo.write('%s: %s\n' % (f, desc)) while True: diff --git a/src/polyglot/builtins.py b/src/polyglot/builtins.py index f54eb25807..6f4fc35ddd 100644 --- a/src/polyglot/builtins.py +++ b/src/polyglot/builtins.py @@ -23,6 +23,16 @@ if is_py3: zip = __builtins__['zip'] map = __builtins__['map'] filter = __builtins__['filter'] + + def iteritems(d): + return iter(d.items()) + + def itervalues(d): + return iter(d.values()) + + def iterkeys(d): + return iter(d) + else: exec("""def reraise(tp, value, tb=None): try: @@ -32,3 +42,12 @@ else: """) from future_builtins import zip, map, filter # noqa + + def iteritems(d): + return d.iteritems() + + def iterkeys(d): + return d.iterkeys() + + def itervalues(d): + return d.itervalues()