From 5918acabad520a5cda58a304e9780d8587e810db Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 25 Mar 2019 16:03:25 +0530 Subject: [PATCH] Misc fixes for the last py3 porting merge --- setup.cfg | 2 -- setup/resources.py | 2 +- src/calibre/__init__.py | 1 + src/calibre/customize/__init__.py | 2 +- src/calibre/ebooks/oeb/polish/check/links.py | 2 +- src/calibre/ebooks/pdf/reflow.py | 3 ++- src/calibre/ebooks/unihandecode/pykakasi/j2h.py | 2 +- src/calibre/gui2/actions/__init__.py | 2 +- src/calibre/gui2/actions/save_to_disk.py | 2 +- src/calibre/gui2/device.py | 4 ++-- 10 files changed, 11 insertions(+), 11 deletions(-) diff --git a/setup.cfg b/setup.cfg index 2198e55434..af4550aa0a 100644 --- a/setup.cfg +++ b/setup.cfg @@ -2,8 +2,6 @@ max-line-length = 160 builtins = _,dynamic_property,__,P,I,lopen,icu_lower,icu_upper,icu_title,ngettext,connect_lambda ignore = E12,E203,E22,E231,E241,E401,E402,E731,W391,E722,E741,W504 -per-file-ignores = - src/polyglot/*:F401 [yapf] based_on_style = pep8 diff --git a/setup/resources.py b/setup/resources.py index 9855dad9dc..edaf56d01c 100644 --- a/setup/resources.py +++ b/setup/resources.py @@ -270,7 +270,7 @@ class RecentUAs(Command): # {{{ from setup.browser_data import get_data data = get_data() with open(self.UA_PATH, 'wb') as f: - f.write(json.dumps(data, indent=2).encode('utf-8')) + f.write(json.dumps(data, indent=2, ensure_ascii=False).encode('utf-8')) # }}} diff --git a/src/calibre/__init__.py b/src/calibre/__init__.py index e17ab12edb..867163fc2b 100644 --- a/src/calibre/__init__.py +++ b/src/calibre/__init__.py @@ -193,6 +193,7 @@ def prints(*args, **kwargs): Returns the number of bytes written. ''' file = kwargs.get('file', sys.stdout) + file = getattr(file, 'buffer', file) sep = bytes(kwargs.get('sep', ' ')) end = bytes(kwargs.get('end', '\n')) enc = 'utf-8' if 'CALIBRE_WORKER' in os.environ else preferred_encoding diff --git a/src/calibre/customize/__init__.py b/src/calibre/customize/__init__.py index d69a338d82..8125b3cc5f 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']).values()) + pixmap.loadFromData(tuple(self.load_resources(['images/icon.png']).values())[0]) icon = QIcon(pixmap) :param names: List of paths to resources in the ZIP file using / as separator diff --git a/src/calibre/ebooks/oeb/polish/check/links.py b/src/calibre/ebooks/oeb/polish/check/links.py index 610585677e..0e541e1fe5 100644 --- a/src/calibre/ebooks/oeb/polish/check/links.py +++ b/src/calibre/ebooks/oeb/polish/check/links.py @@ -18,7 +18,7 @@ from calibre.ebooks.oeb.polish.replace import remove_links_to from calibre.ebooks.oeb.polish.cover import get_raster_cover_name from calibre.ebooks.oeb.polish.utils import guess_type, actual_case_for_name, corrected_case_for_name from calibre.ebooks.oeb.polish.check.base import BaseError, WARN, INFO -from polyglot.builtins import iteritems, map, range +from polyglot.builtins import iteritems, map, range, itervalues from polyglot.urllib import urlparse from polyglot.queue import Queue, Empty diff --git a/src/calibre/ebooks/pdf/reflow.py b/src/calibre/ebooks/pdf/reflow.py index 0016dc5400..a7708ea8ce 100644 --- a/src/calibre/ebooks/pdf/reflow.py +++ b/src/calibre/ebooks/pdf/reflow.py @@ -7,6 +7,7 @@ __copyright__ = '2009, Kovid Goyal ' __docformat__ = 'restructuredtext en' import sys, os, numbers +from itertools import count from lxml import etree @@ -623,7 +624,7 @@ class PDFDocument(object): self.opts, self.log = opts, log parser = etree.XMLParser(recover=True) self.root = etree.fromstring(xml, parser=parser) - idc = iter(range(sys.maxint)) + idc = count() self.fonts = [] self.font_map = {} diff --git a/src/calibre/ebooks/unihandecode/pykakasi/j2h.py b/src/calibre/ebooks/unihandecode/pykakasi/j2h.py index ddf0f23860..79cd2c29ac 100644 --- a/src/calibre/ebooks/unihandecode/pykakasi/j2h.py +++ b/src/calibre/ebooks/unihandecode/pykakasi/j2h.py @@ -72,7 +72,7 @@ class J2H (object): if len(text) >= length: if text.startswith(k): for (yomi, tail) in v: - if tail is '': + if tail == '': if max_len < length: Hstr = yomi max_len = length diff --git a/src/calibre/gui2/actions/__init__.py b/src/calibre/gui2/actions/__init__.py index 7647cbfd82..59049a1a07 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']).values())) + pixmap.loadFromData(tuple(self.load_resources(['images/icon.png']).values())[0]) icon = QIcon(pixmap) :param names: List of paths to resources in the ZIP file using / as separator diff --git a/src/calibre/gui2/actions/save_to_disk.py b/src/calibre/gui2/actions/save_to_disk.py index 0a41ed191b..0802211a48 100644 --- a/src/calibre/gui2/actions/save_to_disk.py +++ b/src/calibre/gui2/actions/save_to_disk.py @@ -7,7 +7,7 @@ __docformat__ = 'restructuredtext en' import os, numbers from functools import partial -from polyglot.builtins itervalues, import map +from polyglot.builtins import itervalues, map from calibre.utils.config import prefs diff --git a/src/calibre/gui2/device.py b/src/calibre/gui2/device.py index dcc8b1a6fc..13717fdc49 100644 --- a/src/calibre/gui2/device.py +++ b/src/calibre/gui2/device.py @@ -355,7 +355,7 @@ class DeviceManager(Thread): # {{{ # anything besides set a flag that the right thread will see. self.connected_device.unmount_device() - def next(self): + def next_job(self): if not self.job_steps.empty(): try: return self.job_steps.get_nowait() @@ -411,7 +411,7 @@ class DeviceManager(Thread): # {{{ do_sleep = True while True: - job = next(self) + job = self.next_job() if job is not None: do_sleep = False self.current_job = job