From 24cd46cc70ab13f8e615b50fcd632ccc879df959 Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Mon, 5 Aug 2019 16:07:00 -0400 Subject: [PATCH 01/10] misc cleanup set([]) --- src/calibre/gui2/actions/catalog.py | 2 +- src/calibre/gui2/actions/delete.py | 2 +- src/calibre/gui2/actions/view.py | 2 +- src/calibre/gui2/device.py | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/calibre/gui2/actions/catalog.py b/src/calibre/gui2/actions/catalog.py index 67cf726202..8430b69dfb 100644 --- a/src/calibre/gui2/actions/catalog.py +++ b/src/calibre/gui2/actions/catalog.py @@ -85,7 +85,7 @@ class GenerateCatalogAction(InterfaceAction): id = self.gui.library_view.model().add_catalog(job.catalog_file_path, job.catalog_title) self.gui.library_view.model().beginResetModel(), self.gui.library_view.model().endResetModel() if job.catalog_sync: - sync = dynamic.get('catalogs_to_be_synced', set([])) + sync = dynamic.get('catalogs_to_be_synced', set()) sync.add(id) dynamic.set('catalogs_to_be_synced', sync) self.gui.status_bar.show_message(_('Catalog generated.'), 3000) diff --git a/src/calibre/gui2/actions/delete.py b/src/calibre/gui2/actions/delete.py index 7a04addcb3..4e6317b28a 100644 --- a/src/calibre/gui2/actions/delete.py +++ b/src/calibre/gui2/actions/delete.py @@ -165,7 +165,7 @@ class DeleteAction(InterfaceAction): if not rows or len(rows) == 0: d = error_dialog(self.gui, err_title, _('No book selected')) d.exec_() - return set([]) + return set() return set(map(self.gui.library_view.model().id, rows)) def remove_format_by_id(self, book_id, fmt): diff --git a/src/calibre/gui2/actions/view.py b/src/calibre/gui2/actions/view.py index 9ad6954d28..c5fcfbeaae 100644 --- a/src/calibre/gui2/actions/view.py +++ b/src/calibre/gui2/actions/view.py @@ -166,7 +166,7 @@ class ViewAction(InterfaceAction): rows = [r.row() for r in rows] book_ids = [db.id(r) for r in rows] formats = [[x.upper() for x in db.new_api.formats(book_id)] for book_id in book_ids] - all_fmts = set([]) + all_fmts = set() for x in formats: if x: for f in x: diff --git a/src/calibre/gui2/device.py b/src/calibre/gui2/device.py index bd0ba2e47d..ef0f0117d6 100644 --- a/src/calibre/gui2/device.py +++ b/src/calibre/gui2/device.py @@ -1343,7 +1343,7 @@ class DeviceMixin(object): # {{{ self.iactions['Convert Books'].auto_convert_catalogs(auto, format) files = [f for f in files if f is not None] if not files: - dynamic.set('catalogs_to_be_synced', set([])) + dynamic.set('catalogs_to_be_synced', set()) return metadata = self.library_view.model().metadata_for(ids) names = [] @@ -1355,7 +1355,7 @@ class DeviceMixin(object): # {{{ names.append('%s_%d%s'%(prefix, id, os.path.splitext(files[-1])[1])) self.update_thumbnail(mi) - dynamic.set('catalogs_to_be_synced', set([])) + dynamic.set('catalogs_to_be_synced', set()) if files: remove = [] space = {self.location_manager.free[0] : None, From d0a30b1f84fd53d513475ef950bdf10c734017b8 Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Mon, 5 Aug 2019 16:09:30 -0400 Subject: [PATCH 02/10] py3: add string_or_unicode to polyglot To facilitate universal __future__s, we prefer native_string_type to str. Since we cannot compare things as instance(f, (str, unicode_type)) and it gets a bit ridiculous to compare: from polyglot.builtins import native_string_type, unicode_type isinstance(f, (native_string_type, unicode_type)) allow using isinstance(f, string_or_unicode) instead. This matches the existing string_or_bytes comparator. --- src/polyglot/builtins.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/polyglot/builtins.py b/src/polyglot/builtins.py index bf036ff459..cb78f7f822 100644 --- a/src/polyglot/builtins.py +++ b/src/polyglot/builtins.py @@ -72,6 +72,7 @@ if is_py3: codepoint_to_chr = chr unicode_type = str string_or_bytes = str, bytes + string_or_unicode = str long_type = int raw_input = input getcwd = os.getcwd @@ -126,6 +127,7 @@ else: codepoint_to_chr = unichr unicode_type = unicode string_or_bytes = unicode, bytes + string_or_unicode = str, unicode long_type = long exec_path = execfile raw_input = builtins.raw_input From 96c71e7ae4eb74f96f405ef9b43656e5d365a97a Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Thu, 8 Aug 2019 21:43:33 -0400 Subject: [PATCH 03/10] QbyteArray().data() is always bytes and does not need to be cast to it a dbus.ByteArray() can simply be initialized from the QByteArray directly. --- src/calibre/ebooks/__init__.py | 2 +- src/calibre/ebooks/pdf/render/serialize.py | 2 +- src/calibre/gui2/__init__.py | 2 +- src/calibre/gui2/dbus_export/utils.py | 2 +- src/calibre/gui2/library/alternate_views.py | 2 +- src/calibre/utils/wmf/__init__.py | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/calibre/ebooks/__init__.py b/src/calibre/ebooks/__init__.py index 87e017f12d..34b5904d8f 100644 --- a/src/calibre/ebooks/__init__.py +++ b/src/calibre/ebooks/__init__.py @@ -67,7 +67,7 @@ class HTMLRenderer(object): buf = QBuffer(ba) buf.open(QBuffer.WriteOnly) image.save(buf, 'JPEG') - self.data = bytes(ba.data()) + self.data = ba.data() except Exception as e: self.exception = e self.traceback = traceback.format_exc() diff --git a/src/calibre/ebooks/pdf/render/serialize.py b/src/calibre/ebooks/pdf/render/serialize.py index dae0cd773a..492edaacb6 100644 --- a/src/calibre/ebooks/pdf/render/serialize.py +++ b/src/calibre/ebooks/pdf/render/serialize.py @@ -464,7 +464,7 @@ class PDFStream(object): ba = QByteArray() buf = QBuffer(ba) image.save(buf, 'jpeg', 94) - data = bytes(ba.data()) + data = ba.data() if has_alpha: soft_mask = self.write_image(tmask, w, h, 8) diff --git a/src/calibre/gui2/__init__.py b/src/calibre/gui2/__init__.py index e656ca1386..2c7815716c 100644 --- a/src/calibre/gui2/__init__.py +++ b/src/calibre/gui2/__init__.py @@ -687,7 +687,7 @@ def pixmap_to_data(pixmap, format='JPEG', quality=None): buf = QBuffer(ba) buf.open(QBuffer.WriteOnly) pixmap.save(buf, format, quality=quality) - return bytes(ba.data()) + return ba.data() def decouple(prefix): diff --git a/src/calibre/gui2/dbus_export/utils.py b/src/calibre/gui2/dbus_export/utils.py index 722dab73e4..e1245782c6 100644 --- a/src/calibre/gui2/dbus_export/utils.py +++ b/src/calibre/gui2/dbus_export/utils.py @@ -128,7 +128,7 @@ def icon_to_dbus_menu_icon(icon, size=32): buf = QBuffer(ba) buf.open(QBuffer.WriteOnly) icon.pixmap(32).save(buf, 'PNG') - return dbus.ByteArray(bytes((ba.data()))) + return dbus.ByteArray(ba) def setup_for_cli_run(): diff --git a/src/calibre/gui2/library/alternate_views.py b/src/calibre/gui2/library/alternate_views.py index 08cb1b6e64..bf78e5791e 100644 --- a/src/calibre/gui2/library/alternate_views.py +++ b/src/calibre/gui2/library/alternate_views.py @@ -76,7 +76,7 @@ def image_to_data(image): # {{{ buf.open(QBuffer.WriteOnly) if not image.save(buf, CACHE_FORMAT): raise EncodeError('Failed to encode thumbnail') - ret = bytes(ba.data()) + ret = ba.data() buf.close() return ret # }}} diff --git a/src/calibre/utils/wmf/__init__.py b/src/calibre/utils/wmf/__init__.py index ee9b608729..d8f7e34800 100644 --- a/src/calibre/utils/wmf/__init__.py +++ b/src/calibre/utils/wmf/__init__.py @@ -68,4 +68,4 @@ def to_png(bmp): buf = QBuffer(ba) buf.open(QBuffer.WriteOnly) i.save(buf, 'png') - return bytes(ba.data()) + return ba.data() From 2fe269a1619c0dcce9ce508b2b135a3e067a5a6f Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Thu, 8 Aug 2019 22:10:13 -0400 Subject: [PATCH 04/10] Use https urls where possible. --- src/calibre/gui2/__init__.py | 2 +- src/calibre/gui2/store/stores/whsmith_uk_plugin.py | 6 +++--- src/calibre/gui2/store/stores/woblink_plugin.py | 8 ++++---- src/calibre/gui2/store/stores/wolnelektury_plugin.py | 10 +++++----- src/calibre/gui2/store/stores/xinxii_plugin.py | 8 ++++---- src/calibre/gui2/tweak_book/spell.py | 2 +- src/calibre/utils/ipc/launch.py | 2 +- 7 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/calibre/gui2/__init__.py b/src/calibre/gui2/__init__.py index 2c7815716c..091b5b1919 100644 --- a/src/calibre/gui2/__init__.py +++ b/src/calibre/gui2/__init__.py @@ -903,7 +903,7 @@ class Application(QApplication): 'calibre versions newer than 2.0 do not run on Windows XP. This is' ' because the graphics toolkit calibre uses (Qt 5) crashes a lot' ' on Windows XP. We suggest you stay with calibre 1.48' - ' which works well on Windows XP.') % 'http://download.calibre-ebook.com/1.48.0/', show=True) + ' which works well on Windows XP.') % 'https://download.calibre-ebook.com/1.48.0/', show=True) raise SystemExit(1) if iswindows: diff --git a/src/calibre/gui2/store/stores/whsmith_uk_plugin.py b/src/calibre/gui2/store/stores/whsmith_uk_plugin.py index 094a1b57a2..966ad70201 100644 --- a/src/calibre/gui2/store/stores/whsmith_uk_plugin.py +++ b/src/calibre/gui2/store/stores/whsmith_uk_plugin.py @@ -28,7 +28,7 @@ from calibre.gui2.store.web_store_dialog import WebStoreDialog class WHSmithUKStore(BasicStoreConfig, StorePlugin): def open(self, parent=None, detail_item=None, external=False): - url = 'http://www.whsmith.co.uk/' + url = 'https://www.whsmith.co.uk/' url_details = '' if external or self.config.get('open_external', False): @@ -45,7 +45,7 @@ class WHSmithUKStore(BasicStoreConfig, StorePlugin): d.exec_() def search(self, query, max_results=10, timeout=60): - url = ('http://www.whsmith.co.uk/search?keywordCategoryId=wc_dept_ebooks&results=60' + url = ('https://www.whsmith.co.uk/search?keywordCategoryId=wc_dept_ebooks&results=60' '&page=1&keywords=' + quote(query)) br = browser() @@ -59,7 +59,7 @@ class WHSmithUKStore(BasicStoreConfig, StorePlugin): id_ = ''.join(data.xpath('./a[@class="product_image_wrap"]/@href')) if not id_: continue - id_ = 'http://www.whsmith.co.uk' + id_ + id_ = 'https://www.whsmith.co.uk' + id_ cover_url = ''.join(data.xpath('.//img[@class="product_image"]/@src')) title = ''.join(data.xpath('.//h4[@class="product_title"]/text()')) author = ', '.join(data.xpath('.//span[@class="product_second"]/text()')) diff --git a/src/calibre/gui2/store/stores/woblink_plugin.py b/src/calibre/gui2/store/stores/woblink_plugin.py index fe27ee501a..8a64362713 100644 --- a/src/calibre/gui2/store/stores/woblink_plugin.py +++ b/src/calibre/gui2/store/stores/woblink_plugin.py @@ -36,7 +36,7 @@ def as_base64(data): def search(query, max_results=10, timeout=60): - url = 'http://woblink.com/publication/ajax?mode=none&query=' + quote_plus(query) + url = 'https://woblink.com/publication/ajax?mode=none&query=' + quote_plus(query) if max_results > 10: if max_results > 20: url += '&limit=30' @@ -47,7 +47,7 @@ def search(query, max_results=10, timeout=60): rq = Request(url, headers={ 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', 'X-Requested-With': 'XMLHttpRequest', - 'Referrer':'http://woblink.com/ebooki-kategorie', + 'Referrer':'https://woblink.com/ebooki-kategorie', 'Cache-Control':'max-age=0', }, data=urlencode({ 'nw_filtry_filtr_zakrescen_formularz[min]':'0', @@ -89,13 +89,13 @@ class WoblinkStore(BasicStoreConfig, StorePlugin): def open(self, parent=None, detail_item=None, external=False): aff_root = 'https://www.a4b-tracking.com/pl/stat-click-text-link/16/58/' - url = 'http://woblink.com/publication' + url = 'https://woblink.com/publication' aff_url = aff_root + as_base64(url) detail_url = None if detail_item: - detail_url = aff_root + as_base64('http://woblink.com' + detail_item) + detail_url = aff_root + as_base64('https://woblink.com' + detail_item) if external or self.config.get('open_external', False): open_url(QUrl(url_slash_cleaner(detail_url if detail_url else aff_url))) diff --git a/src/calibre/gui2/store/stores/wolnelektury_plugin.py b/src/calibre/gui2/store/stores/wolnelektury_plugin.py index aa33d532ce..0c7dfba06e 100644 --- a/src/calibre/gui2/store/stores/wolnelektury_plugin.py +++ b/src/calibre/gui2/store/stores/wolnelektury_plugin.py @@ -29,7 +29,7 @@ class WolneLekturyStore(BasicStoreConfig, StorePlugin): def open(self, parent=None, detail_item=None, external=False): - url = 'http://wolnelektury.pl' + url = 'https://wolnelektury.pl' detail_url = None if detail_item: @@ -44,7 +44,7 @@ class WolneLekturyStore(BasicStoreConfig, StorePlugin): d.exec_() def search(self, query, max_results=10, timeout=60): - url = 'http://wolnelektury.pl/szukaj?q=' + quote_plus(query) + url = 'https://wolnelektury.pl/szukaj?q=' + quote_plus(query) br = browser() @@ -69,13 +69,13 @@ class WolneLekturyStore(BasicStoreConfig, StorePlugin): s = SearchResult() for link in data.xpath('.//div[@class="book-box-formats"]/span/a'): ext = ''.join(link.xpath('./text()')) - href = 'http://wolnelektury.pl' + link.get('href') + href = 'https://wolnelektury.pl' + link.get('href') s.downloads[ext] = href - s.cover_url = 'http://wolnelektury.pl' + cover_url.strip() + s.cover_url = 'https://wolnelektury.pl' + cover_url.strip() s.title = title.strip() s.author = author s.price = price - s.detail_item = 'http://wolnelektury.pl' + id + s.detail_item = 'https://wolnelektury.pl' + id s.formats = ', '.join(s.downloads.keys()) s.drm = SearchResult.DRM_UNLOCKED diff --git a/src/calibre/gui2/store/stores/xinxii_plugin.py b/src/calibre/gui2/store/stores/xinxii_plugin.py index 0c5286d096..ae7ff386d5 100644 --- a/src/calibre/gui2/store/stores/xinxii_plugin.py +++ b/src/calibre/gui2/store/stores/xinxii_plugin.py @@ -23,10 +23,10 @@ from calibre.gui2.store.search_result import SearchResult class XinXiiStore(BasicStoreConfig, OpenSearchOPDSStore): - open_search_url = 'http://www.xinxii.com/catalog-search/' - web_url = 'http://xinxii.com/' + open_search_url = 'https://www.xinxii.com/catalog-search/' + web_url = 'https://xinxii.com/' - # http://www.xinxii.com/catalog/ + # https://www.xinxii.com/catalog/ def search(self, query, max_results=10, timeout=60): ''' @@ -42,7 +42,7 @@ class XinXiiStore(BasicStoreConfig, OpenSearchOPDSStore): function so this one is modified to remove parts that are used. ''' - url = 'http://www.xinxii.com/catalog-search/query/?keywords=' + quote_plus(query) + url = 'https://www.xinxii.com/catalog-search/query/?keywords=' + quote_plus(query) counter = max_results br = browser() diff --git a/src/calibre/gui2/tweak_book/spell.py b/src/calibre/gui2/tweak_book/spell.py index 88026a6c00..858c35370b 100644 --- a/src/calibre/gui2/tweak_book/spell.py +++ b/src/calibre/gui2/tweak_book/spell.py @@ -67,7 +67,7 @@ class AddDictionary(QDialog): # {{{ download more dictionaries from the LibreOffice extensions repository. The dictionary will download as an .oxt file. Simply specify the path to the downloaded .oxt file here to add the dictionary to {0}.''').format( - __appname__, 'http://extensions.libreoffice.org/extension-center?getCategories=Dictionary&getCompatibility=any&sort_on=positive_ratings')+'

') # noqa + __appname__, 'https://extensions.libreoffice.org/extension-center?getCategories=Dictionary&getCompatibility=any&sort_on=positive_ratings')+'

') # noqa la.setWordWrap(True) la.setOpenExternalLinks(True) la.setMinimumWidth(450) diff --git a/src/calibre/utils/ipc/launch.py b/src/calibre/utils/ipc/launch.py index 219969842c..03df14c538 100644 --- a/src/calibre/utils/ipc/launch.py +++ b/src/calibre/utils/ipc/launch.py @@ -23,7 +23,7 @@ if iswindows: except: raise RuntimeError('NUL file missing in windows. This indicates a' ' corrupted windows. You should contact Microsoft' - ' for assistance and/or follow the steps described here: http://bytes.com/topic/net/answers/264804-compile-error-null-device-missing') + ' for assistance and/or follow the steps described here: https://bytes.com/topic/net/answers/264804-compile-error-null-device-missing') def renice(niceness): From af81778588051fbf2606dacea2bdd2c13d9001e3 Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Thu, 8 Aug 2019 22:56:38 -0400 Subject: [PATCH 05/10] remove unworking, unlisted recipe from 2011 This was incorrectly named *.py, so it was never added to builtin_recipes.zip and could not be used. Attempting to rename and use it yields 404 errors for each feed, so it cannot be trivially rescued; therefore, delete it. --- recipes/sltrib.py | 56 ----------------------------------------------- 1 file changed, 56 deletions(-) delete mode 100644 recipes/sltrib.py diff --git a/recipes/sltrib.py b/recipes/sltrib.py deleted file mode 100644 index a6701ae296..0000000000 --- a/recipes/sltrib.py +++ /dev/null @@ -1,56 +0,0 @@ -from calibre.web.feeds.news import BasicNewsRecipe - -class AdvancedUserRecipe1278347258(BasicNewsRecipe): - title = u'Salt Lake City Tribune' - __author__ = 'Charles Holbert' - oldest_article = 7 - max_articles_per_feed = 100 - - description = '''Utah's independent news source since 1871''' - publisher = 'http://www.sltrib.com/' - category = 'news, Utah, SLC' - language = 'en' - encoding = 'utf-8' - #delay = 1 - #simultaneous_downloads = 1 - remove_javascript = True - use_embedded_content = False - no_stylesheets = True - - #masthead_url = 'http://www.sltrib.com/csp/cms/sites/sltrib/assets/images/logo_main.png' - #cover_url = 'http://webmedia.newseum.org/newseum-multimedia/dfp/jpg9/lg/UT_SLT.jpg' - - keep_only_tags = [dict(name='div',attrs={'id':'imageBox'}) - ,dict(name='div',attrs={'class':'headline'}) - ,dict(name='div',attrs={'class':'byline'}) - ,dict(name='p',attrs={'class':'TEXT_w_Indent'})] - - feeds = [(u'SL Tribune Today', u'http://www.sltrib.com/csp/cms/sites/sltrib/RSS/rss.csp?cat=All'), - (u'Utah News', u'http://www.sltrib.com/csp/cms/sites/sltrib/RSS/rss.csp?cat=UtahNews'), - (u'Business News', u'http://www.sltrib.com/csp/cms/sites/sltrib/RSS/rss.csp?cat=Money'), - (u'Technology', u'http://www.sltrib.com/csp/cms/sites/sltrib/RSS/rss.csp?cat=Technology'), - (u'Most Popular', u'http://www.sltrib.com/csp/cms/sites/sltrib/RSS/rsspopular.csp'), - (u'Sports', u'http://www.sltrib.com/csp/cms/sites/sltrib/RSS/rss.csp?cat=Sports')] - - extra_css = ''' - .headline{font-family:Arial,Helvetica,sans-serif; font-size:xx-large; font-weight: bold; color:#0E5398;} - .byline{font-family:Arial,Helvetica,sans-serif; color:#333333; font-size:xx-small;} - .storytext{font-family:Arial,Helvetica,sans-serif; font-size:medium;} - ''' - - def print_version(self, url): - seg = url.split('/') - x = seg[5].split('-') - baseURL = 'http://www.sltrib.com/csp/cms/sites/sltrib/pages/printerfriendly.csp?id=' - s = baseURL + x[0] - return s - - def get_cover_url(self): - cover_url = None - href = 'http://www.newseum.org/todaysfrontpages/hr.asp?fpVname=UT_SLT&ref_pge=lst' - soup = self.index_to_soup(href) - div = soup.find('div',attrs={'class':'tfpLrgView_container'}) - if div: - cover_url = div.img['src'] - return cover_url - From f7aa4cda793af99c0e642eacdc211af2acbffbb9 Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Thu, 8 Aug 2019 23:16:43 -0400 Subject: [PATCH 06/10] simplify path construction with os.path.join --- src/calibre/gui2/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/calibre/gui2/main.py b/src/calibre/gui2/main.py index c330e948ca..9bc121171e 100644 --- a/src/calibre/gui2/main.py +++ b/src/calibre/gui2/main.py @@ -136,7 +136,7 @@ def get_default_library_path(): fname.encode(filesystem_encoding) except Exception: fname = 'Calibre Library' - x = os.path.expanduser('~'+os.sep+fname) + x = os.path.expanduser(os.path.join('~', fname)) if not os.path.exists(x): try: os.makedirs(x) From 6ce8e018012d47ca28b204dc5523e1732c31f34b Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Wed, 14 Aug 2019 17:53:33 -0400 Subject: [PATCH 07/10] py3: use for loop/hardcode instead of map to process many arguments Even though we adapted to python3 by using a tuple to ensure the function is actually applied, this still uses a surprising language feature then allocate a tuple that is immediately tossed away. --- src/calibre/gui2/actions/add.py | 3 ++- src/calibre/gui2/actions/device.py | 11 +++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/calibre/gui2/actions/add.py b/src/calibre/gui2/actions/add.py index d833efcb78..8e41690e2c 100644 --- a/src/calibre/gui2/actions/add.py +++ b/src/calibre/gui2/actions/add.py @@ -331,7 +331,8 @@ class AddAction(InterfaceAction): create_book(mi, pt.name, fmt=empty_format) fmts = [pt.name] ids.append(db.import_book(mi, fmts)) - tuple(map(os.remove, orig_fmts)) + for path in orig_fmts: + os.remove(path) self.refresh_gui(num) if ids: ids.reverse() diff --git a/src/calibre/gui2/actions/device.py b/src/calibre/gui2/actions/device.py index 99769c5cba..a71d7ebeb3 100644 --- a/src/calibre/gui2/actions/device.py +++ b/src/calibre/gui2/actions/device.py @@ -12,7 +12,7 @@ from calibre.gui2.actions import InterfaceAction from calibre.gui2.dialogs.smartdevice import SmartdeviceDialog from calibre.utils.icu import primary_sort_key from calibre.utils.smtp import config as email_config -from polyglot.builtins import unicode_type, map +from polyglot.builtins import unicode_type class ShareConnMenu(QMenu): # {{{ @@ -111,7 +111,8 @@ class ShareConnMenu(QMenu): # {{{ (alias or account) + ' ' + _('(delete from library)')) self.email_to_menu.addAction(action1) self.email_to_and_delete_menu.addAction(action2) - tuple(map(self.memory.append, (action1, action2))) + self.memory.append(action1) + self.memory.append(action2) if default: ac = DeviceAction(dest, False, False, I('mail.png'), _('Email to') + ' ' +(alias or @@ -127,12 +128,14 @@ class ShareConnMenu(QMenu): # {{{ _('Select recipients') + ' ' + _('(delete from library)')) self.email_to_menu.addAction(action1) self.email_to_and_delete_menu.addAction(action2) - tuple(map(self.memory.append, (action1, action2))) + self.memory.append(action1) + self.memory.append(action2) tac1 = DeviceAction('choosemail:', False, False, I('mail.png'), _('Email to selected recipients...')) self.addAction(tac1) tac1.a_s.connect(sync_menu.action_triggered) - self.memory.append(tac1), self.email_actions.append(tac1) + self.memory.append(tac1) + self.email_actions.append(tac1) ac = self.addMenu(self.email_to_and_delete_menu) self.email_actions.append(ac) action1.a_s.connect(sync_menu.action_triggered) From 074e3ff829518db1cb8e089d2ff213944ef3c241 Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Wed, 14 Aug 2019 19:05:48 -0400 Subject: [PATCH 08/10] py3: use QByteArray().data() to get bytestring instead of str() b'1' can be mapped into an int, but 'b"1"' cannot. Also rename one instance -- the QMimeData class requires using the data() method to retrieve content, and QByteArray uses data() to retrieve the raw bytes, but once we get to data.data().data() it's a bit ridiculous. So make the first one be called md, as is used in other mime handling code too. --- src/calibre/gui2/actions/convert.py | 2 +- src/calibre/gui2/actions/delete.py | 2 +- src/calibre/gui2/actions/edit_metadata.py | 2 +- src/calibre/gui2/actions/embed.py | 2 +- src/calibre/gui2/actions/mark_books.py | 2 +- src/calibre/gui2/actions/polish.py | 2 +- src/calibre/gui2/actions/toc_edit.py | 2 +- src/calibre/gui2/actions/tweak_epub.py | 2 +- src/calibre/gui2/actions/unpack_book.py | 2 +- src/calibre/gui2/bars.py | 12 ++++++------ src/calibre/gui2/tag_browser/model.py | 4 ++-- 11 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/calibre/gui2/actions/convert.py b/src/calibre/gui2/actions/convert.py index 310582865f..de31d199a6 100644 --- a/src/calibre/gui2/actions/convert.py +++ b/src/calibre/gui2/actions/convert.py @@ -40,7 +40,7 @@ class ConvertAction(InterfaceAction): def drop_event(self, event, mime_data): mime = 'application/calibre+from_library' if mime_data.hasFormat(mime): - self.dropped_ids = tuple(map(int, str(mime_data.data(mime)).split())) + self.dropped_ids = tuple(map(int, mime_data.data(mime).data().split())) QTimer.singleShot(1, self.do_drop) return True return False diff --git a/src/calibre/gui2/actions/delete.py b/src/calibre/gui2/actions/delete.py index 4e6317b28a..f41810b3a8 100644 --- a/src/calibre/gui2/actions/delete.py +++ b/src/calibre/gui2/actions/delete.py @@ -106,7 +106,7 @@ class DeleteAction(InterfaceAction): def drop_event(self, event, mime_data): mime = 'application/calibre+from_library' if mime_data.hasFormat(mime): - self.dropped_ids = tuple(map(int, str(mime_data.data(mime)).split())) + self.dropped_ids = tuple(map(int, mime_data.data(mime).data().split())) QTimer.singleShot(1, self.do_drop) return True return False diff --git a/src/calibre/gui2/actions/edit_metadata.py b/src/calibre/gui2/actions/edit_metadata.py index 8a11468de7..d0fcc7c624 100644 --- a/src/calibre/gui2/actions/edit_metadata.py +++ b/src/calibre/gui2/actions/edit_metadata.py @@ -51,7 +51,7 @@ class EditMetadataAction(InterfaceAction): def drop_event(self, event, mime_data): mime = 'application/calibre+from_library' if mime_data.hasFormat(mime): - self.dropped_ids = tuple(map(int, str(mime_data.data(mime)).split())) + self.dropped_ids = tuple(map(int, mime_data.data(mime).data().split())) QTimer.singleShot(1, self.do_drop) return True return False diff --git a/src/calibre/gui2/actions/embed.py b/src/calibre/gui2/actions/embed.py index 40bceae49e..39aae059c0 100644 --- a/src/calibre/gui2/actions/embed.py +++ b/src/calibre/gui2/actions/embed.py @@ -37,7 +37,7 @@ class EmbedAction(InterfaceAction): def drop_event(self, event, mime_data): mime = 'application/calibre+from_library' if mime_data.hasFormat(mime): - self.dropped_ids = tuple(map(int, str(mime_data.data(mime)).split())) + self.dropped_ids = tuple(map(int, mime_data.data(mime).data().split())) QTimer.singleShot(1, self.do_drop) return True return False diff --git a/src/calibre/gui2/actions/mark_books.py b/src/calibre/gui2/actions/mark_books.py index e8e5fd720f..2a95c7c2b9 100644 --- a/src/calibre/gui2/actions/mark_books.py +++ b/src/calibre/gui2/actions/mark_books.py @@ -39,7 +39,7 @@ class MarkBooksAction(InterfaceAction): def drop_event(self, event, mime_data): mime = 'application/calibre+from_library' if mime_data.hasFormat(mime): - self.dropped_ids = tuple(map(int, str(mime_data.data(mime)).split())) + self.dropped_ids = tuple(map(int, mime_data.data(mime).data().split())) QTimer.singleShot(1, self.do_drop) return True return False diff --git a/src/calibre/gui2/actions/polish.py b/src/calibre/gui2/actions/polish.py index 64224bdd79..7ad22efcec 100644 --- a/src/calibre/gui2/actions/polish.py +++ b/src/calibre/gui2/actions/polish.py @@ -420,7 +420,7 @@ class PolishAction(InterfaceAction): def drop_event(self, event, mime_data): mime = 'application/calibre+from_library' if mime_data.hasFormat(mime): - self.dropped_ids = tuple(map(int, str(mime_data.data(mime)).split())) + self.dropped_ids = tuple(map(int, mime_data.data(mime).data().split())) QTimer.singleShot(1, self.do_drop) return True return False diff --git a/src/calibre/gui2/actions/toc_edit.py b/src/calibre/gui2/actions/toc_edit.py index dd4ef8c1a8..c39f3dc2ee 100644 --- a/src/calibre/gui2/actions/toc_edit.py +++ b/src/calibre/gui2/actions/toc_edit.py @@ -87,7 +87,7 @@ class ToCEditAction(InterfaceAction): def drop_event(self, event, mime_data): mime = 'application/calibre+from_library' if mime_data.hasFormat(mime): - self.dropped_ids = tuple(map(int, str(mime_data.data(mime)).split())) + self.dropped_ids = tuple(map(int, mime_data.data(mime).data().split())) QTimer.singleShot(1, self.do_drop) return True return False diff --git a/src/calibre/gui2/actions/tweak_epub.py b/src/calibre/gui2/actions/tweak_epub.py index 6650b891b2..a0d9f1c0a2 100644 --- a/src/calibre/gui2/actions/tweak_epub.py +++ b/src/calibre/gui2/actions/tweak_epub.py @@ -74,7 +74,7 @@ class TweakEpubAction(InterfaceAction): def drop_event(self, event, mime_data): mime = 'application/calibre+from_library' if mime_data.hasFormat(mime): - self.dropped_ids = tuple(map(int, str(mime_data.data(mime)).split())) + self.dropped_ids = tuple(map(int, mime_data.data(mime).data().split())) QTimer.singleShot(1, self.do_drop) return True return False diff --git a/src/calibre/gui2/actions/unpack_book.py b/src/calibre/gui2/actions/unpack_book.py index e92627ea57..e666c1a108 100644 --- a/src/calibre/gui2/actions/unpack_book.py +++ b/src/calibre/gui2/actions/unpack_book.py @@ -308,7 +308,7 @@ class UnpackBookAction(InterfaceAction): def drop_event(self, event, mime_data): mime = 'application/calibre+from_library' if mime_data.hasFormat(mime): - self.dropped_ids = tuple(map(int, str(mime_data.data(mime)).split())) + self.dropped_ids = tuple(map(int, mime_data.data(mime).data().split())) QTimer.singleShot(1, self.do_drop) return True return False diff --git a/src/calibre/gui2/bars.py b/src/calibre/gui2/bars.py index 7d62a358b6..7df3a5f338 100644 --- a/src/calibre/gui2/bars.py +++ b/src/calibre/gui2/bars.py @@ -286,10 +286,10 @@ class ToolBar(QToolBar): # {{{ event.ignore() def dropEvent(self, event): - data = event.mimeData() + md = event.mimeData() mime = 'application/calibre+from_library' - if data.hasFormat(mime): - ids = list(map(int, str(data.data(mime)).split())) + if md.hasFormat(mime): + ids = list(map(int, md.data(mime).data().split())) tgt = None for ac in self.location_manager.available_actions: w = self.widgetForAction(ac) @@ -303,8 +303,8 @@ class ToolBar(QToolBar): # {{{ return mime = 'application/calibre+from_device' - if data.hasFormat(mime): - paths = [unicode_type(u.toLocalFile()) for u in data.urls()] + if md.hasFormat(mime): + paths = [unicode_type(u.toLocalFile()) for u in md.urls()] if paths: self.gui.iactions['Add Books'].add_books_from_device( self.gui.current_view(), paths=paths) @@ -312,7 +312,7 @@ class ToolBar(QToolBar): # {{{ return # Give added_actions an opportunity to process the drag&drop event - if self.check_iactions_for_drag(event, data, 'drop_event'): + if self.check_iactions_for_drag(event, md, 'drop_event'): event.accept() else: event.ignore() diff --git a/src/calibre/gui2/tag_browser/model.py b/src/calibre/gui2/tag_browser/model.py index 4602e503e4..6bb903c3c9 100644 --- a/src/calibre/gui2/tag_browser/model.py +++ b/src/calibre/gui2/tag_browser/model.py @@ -857,7 +857,7 @@ class TagsModel(QAbstractItemModel): # {{{ fm['datatype'] == 'composite' and fm['display'].get('make_category', False)))): mime = 'application/calibre+from_library' - ids = list(map(int, str(md.data(mime)).split())) + ids = list(map(int, md.data(mime).data().split())) self.handle_drop(node, ids) return True elif node.type == TagTreeItem.CATEGORY: @@ -871,7 +871,7 @@ class TagsModel(QAbstractItemModel): # {{{ (fm_src['datatype'] == 'composite' and fm_src['display'].get('make_category', False))): mime = 'application/calibre+from_library' - ids = list(map(int, str(md.data(mime)).split())) + ids = list(map(int, md.data(mime).data().split())) self.handle_user_category_drop(node, ids, md.column_name) return True return False From 1cd54361c0d5647ad7c19c05df2df258d9b84663 Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Mon, 19 Aug 2019 17:28:31 -0400 Subject: [PATCH 09/10] micro-optimize: use sorted(generator) instead of sorted(newlist) Or just use the initial value. --- src/calibre/gui2/catalog/catalog_epub_mobi.py | 2 +- src/calibre/gui2/device_drivers/configwidget.py | 2 +- src/calibre/gui2/dialogs/catalog.py | 2 +- src/calibre/gui2/dialogs/metadata_bulk.py | 4 ++-- src/calibre/utils/unrar.py | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/calibre/gui2/catalog/catalog_epub_mobi.py b/src/calibre/gui2/catalog/catalog_epub_mobi.py index 2f7555d269..1b9c66f9ae 100644 --- a/src/calibre/gui2/catalog/catalog_epub_mobi.py +++ b/src/calibre/gui2/catalog/catalog_epub_mobi.py @@ -615,7 +615,7 @@ class PluginWidget(QWidget,Ui_Form): # Populate the Presets combo box self.presets = JSONConfig("catalog_presets") self.preset_field.addItem("") - self.preset_field_values = sorted([p for p in self.presets], key=sort_key) + self.preset_field_values = sorted(self.presets, key=sort_key) self.preset_field.addItems(self.preset_field_values) def preset_change(self, item_name): diff --git a/src/calibre/gui2/device_drivers/configwidget.py b/src/calibre/gui2/device_drivers/configwidget.py index 61458c0871..a6be604f38 100644 --- a/src/calibre/gui2/device_drivers/configwidget.py +++ b/src/calibre/gui2/device_drivers/configwidget.py @@ -156,7 +156,7 @@ class ConfigWidget(QWidget, Ui_ConfigWidget): formats = set(self.format_map()) extra = formats - set(self.calibre_known_formats) if extra: - fmts = sorted([x.upper() for x in extra]) + fmts = sorted((x.upper() for x in extra)) if not question_dialog(self, _('Unknown formats'), _('You have enabled the {0} formats for' ' your {1}. The {1} may not support them.' diff --git a/src/calibre/gui2/dialogs/catalog.py b/src/calibre/gui2/dialogs/catalog.py index f10eab4384..11ec86e87d 100644 --- a/src/calibre/gui2/dialogs/catalog.py +++ b/src/calibre/gui2/dialogs/catalog.py @@ -96,7 +96,7 @@ class Catalog(QDialog, Ui_Dialog): self.widgets = sorted(self.widgets, key=lambda x: x.TITLE) # Generate a sorted list of installed catalog formats/sync_enabled pairs - fmts = sorted([x[0] for x in self.fmts]) + fmts = sorted((x[0] for x in self.fmts)) self.sync_enabled_formats = [] for fmt in self.fmts: diff --git a/src/calibre/gui2/dialogs/metadata_bulk.py b/src/calibre/gui2/dialogs/metadata_bulk.py index bd90a71d03..11bda1a892 100644 --- a/src/calibre/gui2/dialogs/metadata_bulk.py +++ b/src/calibre/gui2/dialogs/metadata_bulk.py @@ -743,7 +743,7 @@ class MetadataBulkDialog(QDialog, Ui_MetadataBulkDialog): self.queries = JSONConfig("search_replace_queries") self.saved_search_name = '' self.query_field.addItem("") - self.query_field_values = sorted([q for q in self.queries], key=sort_key) + self.query_field_values = sorted(self.queries, key=sort_key) self.query_field.addItems(self.query_field_values) self.query_field.currentIndexChanged[str].connect(self.s_r_query_change) self.query_field.setCurrentIndex(0) @@ -1323,7 +1323,7 @@ class MetadataBulkDialog(QDialog, Ui_MetadataBulkDialog): self.query_field.blockSignals(True) self.query_field.clear() self.query_field.addItem('') - self.query_field_values = sorted([q for q in self.queries], key=sort_key) + self.query_field_values = sorted(self.queries, key=sort_key) self.query_field.addItems(self.query_field_values) self.query_field.blockSignals(False) self.query_field.setCurrentIndex(self.query_field.findText(name)) diff --git a/src/calibre/utils/unrar.py b/src/calibre/utils/unrar.py index 9f7054f1b6..7b196dbd11 100644 --- a/src/calibre/utils/unrar.py +++ b/src/calibre/utils/unrar.py @@ -90,10 +90,10 @@ def extract_member( def extract_first_alphabetically(stream): from calibre.libunzip import sort_key - names_ = sorted([ + names_ = sorted(( x for x in names(stream) if os.path.splitext(x)[1][1:].lower() in { - 'png', 'jpg', 'jpeg', 'gif', 'webp'}], + 'png', 'jpg', 'jpeg', 'gif', 'webp'}), key=sort_key) return extract_member(stream, name=names_[0], match=None) From 80beb72b65a96914c44e391bcd19131469821243 Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Mon, 5 Aug 2019 16:14:38 -0400 Subject: [PATCH 10/10] py3: more work toward universal __future__s --- src/calibre/gui2/__init__.py | 50 ++-- src/calibre/gui2/actions/__init__.py | 5 +- src/calibre/gui2/actions/add.py | 1 + src/calibre/gui2/actions/add_to_library.py | 1 + src/calibre/gui2/actions/annotate.py | 1 + src/calibre/gui2/actions/catalog.py | 1 + src/calibre/gui2/actions/choose_library.py | 6 +- src/calibre/gui2/actions/convert.py | 1 + src/calibre/gui2/actions/copy_to_library.py | 1 + src/calibre/gui2/actions/delete.py | 1 + src/calibre/gui2/actions/device.py | 1 + src/calibre/gui2/actions/edit_collections.py | 1 + src/calibre/gui2/actions/edit_metadata.py | 5 +- src/calibre/gui2/actions/fetch_news.py | 1 + src/calibre/gui2/actions/help.py | 4 +- src/calibre/gui2/actions/next_match.py | 1 + src/calibre/gui2/actions/open.py | 3 +- src/calibre/gui2/actions/preferences.py | 1 + src/calibre/gui2/actions/restart.py | 3 +- src/calibre/gui2/actions/save_to_disk.py | 4 +- src/calibre/gui2/actions/show_book_details.py | 1 + src/calibre/gui2/actions/show_quickview.py | 1 + .../gui2/actions/show_template_tester.py | 1 + src/calibre/gui2/actions/similar_books.py | 1 + src/calibre/gui2/actions/tweak_epub.py | 1 + src/calibre/gui2/actions/unpack_book.py | 1 + src/calibre/gui2/actions/view.py | 1 + src/calibre/gui2/catalog/catalog_bibtex.py | 5 +- src/calibre/gui2/catalog/catalog_csv_xml.py | 5 +- src/calibre/gui2/catalog/catalog_epub_mobi.py | 250 +++++++++--------- src/calibre/gui2/comments_editor.py | 43 +-- src/calibre/gui2/convert/azw3_output.py | 2 +- src/calibre/gui2/convert/comic_input.py | 2 +- src/calibre/gui2/convert/docx_output.py | 1 + src/calibre/gui2/convert/epub_output.py | 2 +- src/calibre/gui2/convert/fb2_input.py | 1 + src/calibre/gui2/convert/fb2_output.py | 1 + src/calibre/gui2/convert/htmlz_output.py | 1 + src/calibre/gui2/convert/lrf_output.py | 2 +- src/calibre/gui2/convert/mobi_output.py | 2 +- src/calibre/gui2/convert/pdb_output.py | 1 + src/calibre/gui2/convert/txtz_output.py | 1 + src/calibre/gui2/device.py | 15 +- src/calibre/gui2/notify.py | 4 +- src/calibre/gui2/search_box.py | 10 +- src/calibre/gui2/tools.py | 2 + src/calibre/gui2/widgets.py | 31 +-- 47 files changed, 257 insertions(+), 223 deletions(-) diff --git a/src/calibre/gui2/__init__.py b/src/calibre/gui2/__init__.py index 091b5b1919..7812dfe1c0 100644 --- a/src/calibre/gui2/__init__.py +++ b/src/calibre/gui2/__init__.py @@ -1,6 +1,10 @@ +from __future__ import absolute_import, division, print_function, unicode_literals + __license__ = 'GPL v3' __copyright__ = '2008, Kovid Goyal ' + """ The GUI """ + import glob import os import signal @@ -354,7 +358,7 @@ def is_widescreen(): global _is_widescreen if _is_widescreen is None: try: - _is_widescreen = float(available_width())/available_height() > 1.4 + _is_widescreen = available_width()/available_height() > 1.4 except: _is_widescreen = False return _is_widescreen @@ -736,7 +740,7 @@ class Translator(QTranslator): try: src = unicode_type(args[1]) except: - return u'' + return '' t = _ return t(src) @@ -766,8 +770,8 @@ def load_builtin_fonts(): if fid > -1: fam = QFontDatabase.applicationFontFamilies(fid) fam = set(map(unicode_type, fam)) - if u'calibre Symbols' in fam: - _rating_font = u'calibre Symbols' + if 'calibre Symbols' in fam: + _rating_font = 'calibre Symbols' def setup_gui_option_parser(parser): @@ -881,7 +885,7 @@ class Application(QApplication): self.line_height = max(12, QFontMetrics(self.font()).lineSpacing()) dl = QLocale(get_lang()) - if unicode_type(dl.bcp47Name()) != u'C': + if unicode_type(dl.bcp47Name()) != 'C': QLocale.setDefault(dl) global gui_thread, qt_app gui_thread = QThread.currentThread() @@ -978,22 +982,22 @@ class Application(QApplication): icon_map = self.__icon_map_memory_ = {} pcache = {} for k, v in iteritems({ - 'DialogYesButton': u'ok.png', - 'DialogNoButton': u'window-close.png', - 'DialogCloseButton': u'window-close.png', - 'DialogOkButton': u'ok.png', - 'DialogCancelButton': u'window-close.png', - 'DialogHelpButton': u'help.png', - 'DialogOpenButton': u'document_open.png', - 'DialogSaveButton': u'save.png', - 'DialogApplyButton': u'ok.png', - 'DialogDiscardButton': u'trash.png', - 'MessageBoxInformation': u'dialog_information.png', - 'MessageBoxWarning': u'dialog_warning.png', - 'MessageBoxCritical': u'dialog_error.png', - 'MessageBoxQuestion': u'dialog_question.png', - 'BrowserReload': u'view-refresh.png', - 'LineEditClearButton': u'clear_left.png', + 'DialogYesButton': 'ok.png', + 'DialogNoButton': 'window-close.png', + 'DialogCloseButton': 'window-close.png', + 'DialogOkButton': 'ok.png', + 'DialogCancelButton': 'window-close.png', + 'DialogHelpButton': 'help.png', + 'DialogOpenButton': 'document_open.png', + 'DialogSaveButton': 'save.png', + 'DialogApplyButton': 'ok.png', + 'DialogDiscardButton': 'trash.png', + 'MessageBoxInformation': 'dialog_information.png', + 'MessageBoxWarning': 'dialog_warning.png', + 'MessageBoxCritical': 'dialog_error.png', + 'MessageBoxQuestion': 'dialog_question.png', + 'BrowserReload': 'view-refresh.png', + 'LineEditClearButton': 'clear_left.png', }): if v not in pcache: p = I(v) @@ -1242,7 +1246,7 @@ def elided_text(text, font=None, width=300, pos='middle'): from PyQt5.Qt import QFontMetrics, QApplication fm = QApplication.fontMetrics() if font is None else (font if isinstance(font, QFontMetrics) else QFontMetrics(font)) delta = 4 - ellipsis = u'\u2026' + ellipsis = '\u2026' def remove_middle(x): mid = len(x) // 2 @@ -1361,7 +1365,7 @@ def set_app_uid(val): try: AppUserModelID(unicode_type(val)) except Exception as err: - prints(u'Failed to set app uid with error:', as_unicode(err)) + prints('Failed to set app uid with error:', as_unicode(err)) return False return True diff --git a/src/calibre/gui2/actions/__init__.py b/src/calibre/gui2/actions/__init__.py index 59049a1a07..8383fd469a 100644 --- a/src/calibre/gui2/actions/__init__.py +++ b/src/calibre/gui2/actions/__init__.py @@ -1,5 +1,6 @@ #!/usr/bin/env python2 # vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai +from __future__ import absolute_import, division, print_function, unicode_literals __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' @@ -19,7 +20,7 @@ from polyglot.builtins import unicode_type, string_or_bytes def menu_action_unique_name(plugin, unique_name): - return u'%s : menu action : %s'%(plugin.unique_name, unique_name) + return '%s : menu action : %s'%(plugin.unique_name, unique_name) class InterfaceAction(QObject): @@ -151,7 +152,7 @@ class InterfaceAction(QObject): bn = self.__class__.__name__ if getattr(self.interface_action_base_plugin, 'name'): bn = self.interface_action_base_plugin.name - return u'Interface Action: %s (%s)'%(bn, self.name) + return 'Interface Action: %s (%s)'%(bn, self.name) def create_action(self, spec=None, attr='qaction', shortcut_name=None): if spec is None: diff --git a/src/calibre/gui2/actions/add.py b/src/calibre/gui2/actions/add.py index 8e41690e2c..444e654ba9 100644 --- a/src/calibre/gui2/actions/add.py +++ b/src/calibre/gui2/actions/add.py @@ -1,5 +1,6 @@ #!/usr/bin/env python2 # vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai +from __future__ import absolute_import, division, print_function, unicode_literals __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' diff --git a/src/calibre/gui2/actions/add_to_library.py b/src/calibre/gui2/actions/add_to_library.py index 9fe4da3b83..21e984b89f 100644 --- a/src/calibre/gui2/actions/add_to_library.py +++ b/src/calibre/gui2/actions/add_to_library.py @@ -1,5 +1,6 @@ #!/usr/bin/env python2 # vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai +from __future__ import absolute_import, division, print_function, unicode_literals __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' diff --git a/src/calibre/gui2/actions/annotate.py b/src/calibre/gui2/actions/annotate.py index 711ede7ccd..224de0ced9 100644 --- a/src/calibre/gui2/actions/annotate.py +++ b/src/calibre/gui2/actions/annotate.py @@ -1,5 +1,6 @@ #!/usr/bin/env python2 # vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai +from __future__ import absolute_import, division, print_function, unicode_literals __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' diff --git a/src/calibre/gui2/actions/catalog.py b/src/calibre/gui2/actions/catalog.py index 8430b69dfb..0c6144e645 100644 --- a/src/calibre/gui2/actions/catalog.py +++ b/src/calibre/gui2/actions/catalog.py @@ -1,5 +1,6 @@ #!/usr/bin/env python2 # vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai +from __future__ import absolute_import, division, print_function, unicode_literals __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' diff --git a/src/calibre/gui2/actions/choose_library.py b/src/calibre/gui2/actions/choose_library.py index 3ea3a6ddd9..cbf2410e79 100644 --- a/src/calibre/gui2/actions/choose_library.py +++ b/src/calibre/gui2/actions/choose_library.py @@ -1,7 +1,7 @@ #!/usr/bin/env python2 # vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai +from __future__ import absolute_import, division, print_function, unicode_literals -from __future__ import print_function __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' __docformat__ = 'restructuredtext en' @@ -252,7 +252,7 @@ class ChooseLibraryAction(InterfaceAction): for i in range(5): ac = self.create_action(spec=('', None, None, None), attr='switch_action%d'%i) - ac.setObjectName(str(i)) + ac.setObjectName(unicode_type(i)) self.switch_actions.append(ac) ac.setVisible(False) connect_lambda(ac.triggered, self, lambda self: @@ -329,7 +329,7 @@ class ChooseLibraryAction(InterfaceAction): self.prev_lname = self.last_lname self.last_lname = lname if len(lname) > 16: - lname = lname[:16] + u'…' + lname = lname[:16] + '…' a = self.qaction a.setText(lname.replace('&', '&&&')) # I have no idea why this requires a triple ampersand self.update_tooltip(db.count()) diff --git a/src/calibre/gui2/actions/convert.py b/src/calibre/gui2/actions/convert.py index de31d199a6..d464bdb679 100644 --- a/src/calibre/gui2/actions/convert.py +++ b/src/calibre/gui2/actions/convert.py @@ -1,5 +1,6 @@ #!/usr/bin/env python2 # vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai +from __future__ import absolute_import, division, print_function, unicode_literals __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' diff --git a/src/calibre/gui2/actions/copy_to_library.py b/src/calibre/gui2/actions/copy_to_library.py index fa4a2635fa..82c7970453 100644 --- a/src/calibre/gui2/actions/copy_to_library.py +++ b/src/calibre/gui2/actions/copy_to_library.py @@ -1,5 +1,6 @@ #!/usr/bin/env python2 # vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai +from __future__ import absolute_import, division, print_function, unicode_literals __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' diff --git a/src/calibre/gui2/actions/delete.py b/src/calibre/gui2/actions/delete.py index f41810b3a8..12bd2695c4 100644 --- a/src/calibre/gui2/actions/delete.py +++ b/src/calibre/gui2/actions/delete.py @@ -1,5 +1,6 @@ #!/usr/bin/env python2 # vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai +from __future__ import absolute_import, division, print_function, unicode_literals __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' diff --git a/src/calibre/gui2/actions/device.py b/src/calibre/gui2/actions/device.py index a71d7ebeb3..0898dc3f56 100644 --- a/src/calibre/gui2/actions/device.py +++ b/src/calibre/gui2/actions/device.py @@ -1,5 +1,6 @@ #!/usr/bin/env python2 # vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai +from __future__ import absolute_import, division, print_function, unicode_literals __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' diff --git a/src/calibre/gui2/actions/edit_collections.py b/src/calibre/gui2/actions/edit_collections.py index 58b4c08f53..eda832f8fa 100644 --- a/src/calibre/gui2/actions/edit_collections.py +++ b/src/calibre/gui2/actions/edit_collections.py @@ -1,5 +1,6 @@ #!/usr/bin/env python2 # vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai +from __future__ import absolute_import, division, print_function, unicode_literals __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' diff --git a/src/calibre/gui2/actions/edit_metadata.py b/src/calibre/gui2/actions/edit_metadata.py index d0fcc7c624..d4df4d3242 100644 --- a/src/calibre/gui2/actions/edit_metadata.py +++ b/src/calibre/gui2/actions/edit_metadata.py @@ -1,5 +1,6 @@ #!/usr/bin/env python2 # vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai +from __future__ import absolute_import, division, print_function, unicode_literals __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' @@ -648,7 +649,7 @@ class EditMetadataAction(InterfaceAction): if not dest_mi.comments: dest_mi.comments = src_mi.comments else: - dest_mi.comments = unicode_type(dest_mi.comments) + u'\n\n' + unicode_type(src_mi.comments) + dest_mi.comments = unicode_type(dest_mi.comments) + '\n\n' + unicode_type(src_mi.comments) if src_mi.title and (not dest_mi.title or dest_mi.title == _('Unknown')): dest_mi.title = src_mi.title if (src_mi.authors and src_mi.authors[0] != _('Unknown')) and (not dest_mi.authors or dest_mi.authors[0] == _('Unknown')): @@ -701,7 +702,7 @@ class EditMetadataAction(InterfaceAction): if not dest_value: db.set_custom(dest_id, src_value, num=colnum) else: - dest_value = unicode_type(dest_value) + u'\n\n' + unicode_type(src_value) + dest_value = unicode_type(dest_value) + '\n\n' + unicode_type(src_value) db.set_custom(dest_id, dest_value, num=colnum) if (dt in {'bool', 'int', 'float', 'rating', 'datetime'} and dest_value is None): db.set_custom(dest_id, src_value, num=colnum) diff --git a/src/calibre/gui2/actions/fetch_news.py b/src/calibre/gui2/actions/fetch_news.py index 28b623f9b7..5aeeb5c3ba 100644 --- a/src/calibre/gui2/actions/fetch_news.py +++ b/src/calibre/gui2/actions/fetch_news.py @@ -1,5 +1,6 @@ #!/usr/bin/env python2 # vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai +from __future__ import absolute_import, division, print_function, unicode_literals __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' diff --git a/src/calibre/gui2/actions/help.py b/src/calibre/gui2/actions/help.py index b51d1ee606..da47c29d80 100644 --- a/src/calibre/gui2/actions/help.py +++ b/src/calibre/gui2/actions/help.py @@ -1,5 +1,6 @@ #!/usr/bin/env python2 # vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai +from __future__ import absolute_import, division, print_function, unicode_literals __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' @@ -22,6 +23,3 @@ class HelpAction(InterfaceAction): def show_help(self, *args): open_url(QUrl(localize_user_manual_link('https://manual.calibre-ebook.com'))) - - - diff --git a/src/calibre/gui2/actions/next_match.py b/src/calibre/gui2/actions/next_match.py index 8aa904cbbf..4e00dd2dbe 100644 --- a/src/calibre/gui2/actions/next_match.py +++ b/src/calibre/gui2/actions/next_match.py @@ -1,5 +1,6 @@ #!/usr/bin/env python2 # vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai +from __future__ import absolute_import, division, print_function, unicode_literals __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' diff --git a/src/calibre/gui2/actions/open.py b/src/calibre/gui2/actions/open.py index 02786349c7..122c0eedce 100644 --- a/src/calibre/gui2/actions/open.py +++ b/src/calibre/gui2/actions/open.py @@ -1,5 +1,6 @@ #!/usr/bin/env python2 # vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai +from __future__ import absolute_import, division, print_function, unicode_literals __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' @@ -24,5 +25,3 @@ class OpenFolderAction(InterfaceAction): enabled = loc == 'library' self.qaction.setEnabled(enabled) self.menuless_qaction.setEnabled(enabled) - - diff --git a/src/calibre/gui2/actions/preferences.py b/src/calibre/gui2/actions/preferences.py index f436450368..48ceb4db9b 100644 --- a/src/calibre/gui2/actions/preferences.py +++ b/src/calibre/gui2/actions/preferences.py @@ -1,5 +1,6 @@ #!/usr/bin/env python2 # vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai +from __future__ import absolute_import, division, print_function, unicode_literals __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' diff --git a/src/calibre/gui2/actions/restart.py b/src/calibre/gui2/actions/restart.py index 872c8d5e58..9ce20eb6ed 100644 --- a/src/calibre/gui2/actions/restart.py +++ b/src/calibre/gui2/actions/restart.py @@ -1,5 +1,6 @@ #!/usr/bin/env python2 # vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai +from __future__ import absolute_import, division, print_function, unicode_literals __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' @@ -19,5 +20,3 @@ class RestartAction(InterfaceAction): def restart(self, *args): self.gui.quit(restart=True) - - diff --git a/src/calibre/gui2/actions/save_to_disk.py b/src/calibre/gui2/actions/save_to_disk.py index 0802211a48..28b16200c6 100644 --- a/src/calibre/gui2/actions/save_to_disk.py +++ b/src/calibre/gui2/actions/save_to_disk.py @@ -1,5 +1,6 @@ #!/usr/bin/env python2 # vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai +from __future__ import absolute_import, division, print_function, unicode_literals __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' @@ -7,12 +8,11 @@ __docformat__ = 'restructuredtext en' import os, numbers from functools import partial -from polyglot.builtins import itervalues, map - from calibre.utils.config import prefs from calibre.gui2 import error_dialog, Dispatcher, choose_dir from calibre.gui2.actions import InterfaceAction +from polyglot.builtins import itervalues, map class SaveToDiskAction(InterfaceAction): diff --git a/src/calibre/gui2/actions/show_book_details.py b/src/calibre/gui2/actions/show_book_details.py index 4e4ceac324..4d3c2d164c 100644 --- a/src/calibre/gui2/actions/show_book_details.py +++ b/src/calibre/gui2/actions/show_book_details.py @@ -1,5 +1,6 @@ #!/usr/bin/env python2 # vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai +from __future__ import absolute_import, division, print_function, unicode_literals __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' diff --git a/src/calibre/gui2/actions/show_quickview.py b/src/calibre/gui2/actions/show_quickview.py index 279b91db60..28ce9aaf52 100644 --- a/src/calibre/gui2/actions/show_quickview.py +++ b/src/calibre/gui2/actions/show_quickview.py @@ -1,5 +1,6 @@ #!/usr/bin/env python2 # vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai +from __future__ import absolute_import, division, print_function, unicode_literals __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' diff --git a/src/calibre/gui2/actions/show_template_tester.py b/src/calibre/gui2/actions/show_template_tester.py index 7f62c291fe..08fc12c654 100644 --- a/src/calibre/gui2/actions/show_template_tester.py +++ b/src/calibre/gui2/actions/show_template_tester.py @@ -1,5 +1,6 @@ #!/usr/bin/env python2 # vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai +from __future__ import absolute_import, division, print_function, unicode_literals __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' diff --git a/src/calibre/gui2/actions/similar_books.py b/src/calibre/gui2/actions/similar_books.py index 5febe5f51f..c355425c14 100644 --- a/src/calibre/gui2/actions/similar_books.py +++ b/src/calibre/gui2/actions/similar_books.py @@ -1,5 +1,6 @@ #!/usr/bin/env python2 # vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai +from __future__ import absolute_import, division, print_function, unicode_literals __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' diff --git a/src/calibre/gui2/actions/tweak_epub.py b/src/calibre/gui2/actions/tweak_epub.py index a0d9f1c0a2..970e0551f9 100644 --- a/src/calibre/gui2/actions/tweak_epub.py +++ b/src/calibre/gui2/actions/tweak_epub.py @@ -1,5 +1,6 @@ #!/usr/bin/env python2 # vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai +from __future__ import absolute_import, division, print_function, unicode_literals __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' diff --git a/src/calibre/gui2/actions/unpack_book.py b/src/calibre/gui2/actions/unpack_book.py index e666c1a108..ff0f577487 100644 --- a/src/calibre/gui2/actions/unpack_book.py +++ b/src/calibre/gui2/actions/unpack_book.py @@ -1,5 +1,6 @@ #!/usr/bin/env python2 # vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai +from __future__ import absolute_import, division, print_function, unicode_literals __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' diff --git a/src/calibre/gui2/actions/view.py b/src/calibre/gui2/actions/view.py index c5fcfbeaae..9bfdf925b7 100644 --- a/src/calibre/gui2/actions/view.py +++ b/src/calibre/gui2/actions/view.py @@ -1,5 +1,6 @@ #!/usr/bin/env python2 # vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai +from __future__ import absolute_import, division, print_function, unicode_literals __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' diff --git a/src/calibre/gui2/catalog/catalog_bibtex.py b/src/calibre/gui2/catalog/catalog_bibtex.py index 0e38160819..1bb607ae74 100644 --- a/src/calibre/gui2/catalog/catalog_bibtex.py +++ b/src/calibre/gui2/catalog/catalog_bibtex.py @@ -1,16 +1,17 @@ #!/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 absolute_import, division, print_function, unicode_literals __license__ = 'GPL v3' __copyright__ = '2009, Kovid Goyal ' __docformat__ = 'restructuredtext en' +from PyQt5.Qt import QWidget, QListWidgetItem + from calibre.gui2 import gprefs from calibre.gui2.catalog.catalog_bibtex_ui import Ui_Form from polyglot.builtins import unicode_type, range -from PyQt5.Qt import QWidget, QListWidgetItem class PluginWidget(QWidget, Ui_Form): diff --git a/src/calibre/gui2/catalog/catalog_csv_xml.py b/src/calibre/gui2/catalog/catalog_csv_xml.py index 03f6c16cc4..5e1a356b2b 100644 --- a/src/calibre/gui2/catalog/catalog_csv_xml.py +++ b/src/calibre/gui2/catalog/catalog_csv_xml.py @@ -1,15 +1,16 @@ #!/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 absolute_import, division, print_function, unicode_literals __license__ = 'GPL v3' __copyright__ = '2009, Kovid Goyal ' __docformat__ = 'restructuredtext en' +from PyQt5.Qt import QWidget, QListWidgetItem, Qt, QVBoxLayout, QLabel, QListWidget + from calibre.gui2 import gprefs from calibre.gui2.ui import get_gui from polyglot.builtins import unicode_type, range -from PyQt5.Qt import QWidget, QListWidgetItem, Qt, QVBoxLayout, QLabel, QListWidget def get_saved_field_data(name, all_fields): diff --git a/src/calibre/gui2/catalog/catalog_epub_mobi.py b/src/calibre/gui2/catalog/catalog_epub_mobi.py index 1b9c66f9ae..c303efc328 100644 --- a/src/calibre/gui2/catalog/catalog_epub_mobi.py +++ b/src/calibre/gui2/catalog/catalog_epub_mobi.py @@ -1,6 +1,6 @@ #!/usr/bin/env python2 # vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai -from __future__ import print_function +from __future__ import absolute_import, division, print_function, unicode_literals __license__ = 'GPL v3' __copyright__ = '2009, Kovid Goyal ' @@ -15,7 +15,7 @@ from calibre.gui2 import gprefs, open_url, question_dialog, error_dialog from calibre.utils.config import JSONConfig from calibre.utils.icu import sort_key from calibre.utils.localization import localize_user_manual_link -from polyglot.builtins import unicode_type, zip, range +from polyglot.builtins import native_string_type, unicode_type, zip, range from .catalog_epub_mobi_ui import Ui_Form from PyQt5.Qt import (Qt, QAbstractItemView, QCheckBox, QComboBox, @@ -115,7 +115,7 @@ class PluginWidget(QWidget,Ui_Form): 'name':_('Wishlist item'), 'field':_('Tags'), 'pattern':'Wishlist', - 'prefix':u'\u00d7'},], + 'prefix':'\u00d7'},], ['table_widget','table_widget'])) self.OPTION_FIELDS = option_fields @@ -423,7 +423,7 @@ class PluginWidget(QWidget,Ui_Form): # Hook Preset signals self.preset_delete_pb.clicked.connect(self.preset_remove) self.preset_save_pb.clicked.connect(self.preset_save) - self.preset_field.currentIndexChanged[str].connect(self.preset_change) + self.preset_field.currentIndexChanged[native_string_type].connect(self.preset_change) self.blocking_all_signals = False @@ -1338,127 +1338,127 @@ class PrefixRules(GenericRulesTable): # Create a list of prefixes for user selection raw_prefix_list = [ - ('Ampersand',u'&'), - ('Angle left double',u'\u00ab'), - ('Angle left',u'\u2039'), - ('Angle right double',u'\u00bb'), - ('Angle right',u'\u203a'), - ('Arrow carriage return',u'\u21b5'), - ('Arrow double',u'\u2194'), - ('Arrow down',u'\u2193'), - ('Arrow left',u'\u2190'), - ('Arrow right',u'\u2192'), - ('Arrow up',u'\u2191'), - ('Asterisk',u'*'), - ('At sign',u'@'), - ('Bullet smallest',u'\u22c5'), - ('Bullet small',u'\u00b7'), - ('Bullet',u'\u2022'), - ('Cards clubs',u'\u2663'), - ('Cards diamonds',u'\u2666'), - ('Cards hearts',u'\u2665'), - ('Cards spades',u'\u2660'), - ('Caret',u'^'), - ('Checkmark',u'\u2713'), - ('Copyright circle c',u'\u00a9'), - ('Copyright circle r',u'\u00ae'), - ('Copyright trademark',u'\u2122'), - ('Currency cent',u'\u00a2'), - ('Currency dollar',u'$'), - ('Currency euro',u'\u20ac'), - ('Currency pound',u'\u00a3'), - ('Currency yen',u'\u00a5'), - ('Dagger double',u'\u2021'), - ('Dagger',u'\u2020'), - ('Degree',u'\u00b0'), - ('Dots3',u'\u2234'), - ('Hash',u'#'), - ('Infinity',u'\u221e'), - ('Lozenge',u'\u25ca'), - ('Math divide',u'\u00f7'), - ('Math empty',u'\u2205'), - ('Math equals',u'='), - ('Math minus',u'\u2212'), - ('Math plus circled',u'\u2295'), - ('Math times circled',u'\u2297'), - ('Math times',u'\u00d7'), - ('Paragraph',u'\u00b6'), - ('Percent',u'%'), - ('Plus-or-minus',u'\u00b1'), - ('Plus',u'+'), - ('Punctuation colon',u':'), - ('Punctuation colon-semi',u';'), - ('Punctuation exclamation',u'!'), - ('Punctuation question',u'?'), - ('Punctuation period',u'.'), - ('Punctuation slash back',u'\\'), - ('Punctuation slash forward',u'/'), - ('Section',u'\u00a7'), - ('Tilde',u'~'), - ('Vertical bar',u'|'), - ('Vertical bar broken',u'\u00a6'), - ('_0',u'0'), - ('_1',u'1'), - ('_2',u'2'), - ('_3',u'3'), - ('_4',u'4'), - ('_5',u'5'), - ('_6',u'6'), - ('_7',u'7'), - ('_8',u'8'), - ('_9',u'9'), - ('_A',u'A'), - ('_B',u'B'), - ('_C',u'C'), - ('_D',u'D'), - ('_E',u'E'), - ('_F',u'F'), - ('_G',u'G'), - ('_H',u'H'), - ('_I',u'I'), - ('_J',u'J'), - ('_K',u'K'), - ('_L',u'L'), - ('_M',u'M'), - ('_N',u'N'), - ('_O',u'O'), - ('_P',u'P'), - ('_Q',u'Q'), - ('_R',u'R'), - ('_S',u'S'), - ('_T',u'T'), - ('_U',u'U'), - ('_V',u'V'), - ('_W',u'W'), - ('_X',u'X'), - ('_Y',u'Y'), - ('_Z',u'Z'), - ('_a',u'a'), - ('_b',u'b'), - ('_c',u'c'), - ('_d',u'd'), - ('_e',u'e'), - ('_f',u'f'), - ('_g',u'g'), - ('_h',u'h'), - ('_i',u'i'), - ('_j',u'j'), - ('_k',u'k'), - ('_l',u'l'), - ('_m',u'm'), - ('_n',u'n'), - ('_o',u'o'), - ('_p',u'p'), - ('_q',u'q'), - ('_r',u'r'), - ('_s',u's'), - ('_t',u't'), - ('_u',u'u'), - ('_v',u'v'), - ('_w',u'w'), - ('_x',u'x'), - ('_y',u'y'), - ('_z',u'z'), + ('Ampersand', '&'), + ('Angle left double', '\u00ab'), + ('Angle left', '\u2039'), + ('Angle right double', '\u00bb'), + ('Angle right', '\u203a'), + ('Arrow carriage return', '\u21b5'), + ('Arrow double', '\u2194'), + ('Arrow down', '\u2193'), + ('Arrow left', '\u2190'), + ('Arrow right', '\u2192'), + ('Arrow up', '\u2191'), + ('Asterisk', '*'), + ('At sign', '@'), + ('Bullet smallest', '\u22c5'), + ('Bullet small', '\u00b7'), + ('Bullet', '\u2022'), + ('Cards clubs', '\u2663'), + ('Cards diamonds', '\u2666'), + ('Cards hearts', '\u2665'), + ('Cards spades', '\u2660'), + ('Caret', '^'), + ('Checkmark', '\u2713'), + ('Copyright circle c', '\u00a9'), + ('Copyright circle r', '\u00ae'), + ('Copyright trademark', '\u2122'), + ('Currency cent', '\u00a2'), + ('Currency dollar', '$'), + ('Currency euro', '\u20ac'), + ('Currency pound', '\u00a3'), + ('Currency yen', '\u00a5'), + ('Dagger double', '\u2021'), + ('Dagger', '\u2020'), + ('Degree', '\u00b0'), + ('Dots3', '\u2234'), + ('Hash', '#'), + ('Infinity', '\u221e'), + ('Lozenge', '\u25ca'), + ('Math divide', '\u00f7'), + ('Math empty', '\u2205'), + ('Math equals', '='), + ('Math minus', '\u2212'), + ('Math plus circled', '\u2295'), + ('Math times circled', '\u2297'), + ('Math times', '\u00d7'), + ('Paragraph', '\u00b6'), + ('Percent', '%'), + ('Plus-or-minus', '\u00b1'), + ('Plus', '+'), + ('Punctuation colon', ':'), + ('Punctuation colon-semi', ';'), + ('Punctuation exclamation', '!'), + ('Punctuation question', '?'), + ('Punctuation period', '.'), + ('Punctuation slash back', '\\'), + ('Punctuation slash forward', '/'), + ('Section', '\u00a7'), + ('Tilde', '~'), + ('Vertical bar', '|'), + ('Vertical bar broken', '\u00a6'), + ('_0', '0'), + ('_1', '1'), + ('_2', '2'), + ('_3', '3'), + ('_4', '4'), + ('_5', '5'), + ('_6', '6'), + ('_7', '7'), + ('_8', '8'), + ('_9', '9'), + ('_A', 'A'), + ('_B', 'B'), + ('_C', 'C'), + ('_D', 'D'), + ('_E', 'E'), + ('_F', 'F'), + ('_G', 'G'), + ('_H', 'H'), + ('_I', 'I'), + ('_J', 'J'), + ('_K', 'K'), + ('_L', 'L'), + ('_M', 'M'), + ('_N', 'N'), + ('_O', 'O'), + ('_P', 'P'), + ('_Q', 'Q'), + ('_R', 'R'), + ('_S', 'S'), + ('_T', 'T'), + ('_U', 'U'), + ('_V', 'V'), + ('_W', 'W'), + ('_X', 'X'), + ('_Y', 'Y'), + ('_Z', 'Z'), + ('_a', 'a'), + ('_b', 'b'), + ('_c', 'c'), + ('_d', 'd'), + ('_e', 'e'), + ('_f', 'f'), + ('_g', 'g'), + ('_h', 'h'), + ('_i', 'i'), + ('_j', 'j'), + ('_k', 'k'), + ('_l', 'l'), + ('_m', 'm'), + ('_n', 'n'), + ('_o', 'o'), + ('_p', 'p'), + ('_q', 'q'), + ('_r', 'r'), + ('_s', 's'), + ('_t', 't'), + ('_u', 'u'), + ('_v', 'v'), + ('_w', 'w'), + ('_x', 'x'), + ('_y', 'y'), + ('_z', 'z'), ] raw_prefix_list = sorted(raw_prefix_list, key=prefix_sorter) self.prefix_list = [x[1] for x in raw_prefix_list] diff --git a/src/calibre/gui2/comments_editor.py b/src/calibre/gui2/comments_editor.py index 0fffa212f0..f6e5229124 100644 --- a/src/calibre/gui2/comments_editor.py +++ b/src/calibre/gui2/comments_editor.py @@ -1,5 +1,6 @@ #!/usr/bin/env python2 # vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai +from __future__ import absolute_import, division, print_function, unicode_literals __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' @@ -338,7 +339,7 @@ class EditorWidget(QWebView, LineEditECM): # {{{ @property def html(self): - ans = u'' + ans = '' try: if not self.page().mainFrame().documentElement().findFirst('meta[name="calibre-dont-sanitize"]').isNull(): # Bypass cleanup if special meta tag exists @@ -364,9 +365,9 @@ class EditorWidget(QWebView, LineEditECM): # {{{ x.tag not in ('script', 'style')] if len(elems) > 1: - ans = u'

%s
'%(u''.join(elems)) + ans = '
%s
'%(''.join(elems)) else: - ans = u''.join(elems) + ans = ''.join(elems) if not ans.startswith('<'): ans = '

%s

'%ans ans = xml_replace_entities(ans) @@ -482,7 +483,7 @@ class Highlighter(QSyntaxHighlighter): if state == State_Comment: start = pos while pos < len_: - if text[pos:pos+3] == u"-->": + if text[pos:pos+3] == "-->": pos += 3 state = State_Text break @@ -495,7 +496,7 @@ class Highlighter(QSyntaxHighlighter): while pos < len_: ch = text[pos] pos += 1 - if ch == u'>': + if ch == '>': state = State_Text break self.setFormat(start, pos - start, self.colors['doctype']) @@ -506,7 +507,7 @@ class Highlighter(QSyntaxHighlighter): while pos < len_: ch = text[pos] pos += 1 - if ch == u'>': + if ch == '>': state = State_Text break if not ch.isspace(): @@ -524,7 +525,7 @@ class Highlighter(QSyntaxHighlighter): pos -= 1 state = State_InsideTag break - if ch == u'>': + if ch == '>': state = State_Text break self.setFormat(start, pos - start, self.colors['tag']) @@ -537,10 +538,10 @@ class Highlighter(QSyntaxHighlighter): ch = text[pos] pos += 1 - if ch == u'/': + if ch == '/': continue - if ch == u'>': + if ch == '>': state = State_Text break @@ -557,11 +558,11 @@ class Highlighter(QSyntaxHighlighter): ch = text[pos] pos += 1 - if ch == u'=': + if ch == '=': state = State_AttributeValue break - if ch in (u'>', u'/'): + if ch in ('>', '/'): state = State_InsideTag break @@ -577,12 +578,12 @@ class Highlighter(QSyntaxHighlighter): pos += 1 # handle opening single quote - if ch == u"'": + if ch == "'": state = State_SingleQuote break # handle opening double quote - if ch == u'"': + if ch == '"': state = State_DoubleQuote break @@ -597,7 +598,7 @@ class Highlighter(QSyntaxHighlighter): ch = text[pos] if ch.isspace(): break - if ch in (u'>', u'/'): + if ch in ('>', '/'): break pos += 1 state = State_InsideTag @@ -610,7 +611,7 @@ class Highlighter(QSyntaxHighlighter): while pos < len_: ch = text[pos] pos += 1 - if ch == u"'": + if ch == "'": break state = State_InsideTag @@ -624,7 +625,7 @@ class Highlighter(QSyntaxHighlighter): while pos < len_: ch = text[pos] pos += 1 - if ch == u'"': + if ch == '"': break state = State_InsideTag @@ -635,18 +636,18 @@ class Highlighter(QSyntaxHighlighter): # State_Text and default while pos < len_: ch = text[pos] - if ch == u'<': - if text[pos:pos+4] == u"