diff --git a/src/calibre/build_forms.py b/src/calibre/build_forms.py index 3db1d2ea58..2036afcb9d 100644 --- a/src/calibre/build_forms.py +++ b/src/calibre/build_forms.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2021, Kovid Goyal import os diff --git a/src/calibre/constants.py b/src/calibre/constants.py index cd7f9aa5c3..c66d846f78 100644 --- a/src/calibre/constants.py +++ b/src/calibre/constants.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2015, Kovid Goyal from polyglot.builtins import environ_item, hasenv import sys, locale, codecs, os, collections, collections.abc diff --git a/src/calibre/customize/__init__.py b/src/calibre/customize/__init__.py index cb1296eabd..b17bc55929 100644 --- a/src/calibre/customize/__init__.py +++ b/src/calibre/customize/__init__.py @@ -565,7 +565,7 @@ class CatalogPlugin(Plugin): # {{{ from calibre.ptempfile import PersistentTemporaryDirectory if not type(self) in builtin_plugins and self.name not in config['disabled_plugins']: - files_to_copy = ["%s.%s" % (self.name.lower(),ext) for ext in ["ui","py"]] + files_to_copy = [f"{self.name.lower()}.{ext}" for ext in ["ui","py"]] resources = zipfile.ZipFile(self.plugin_path,'r') if self.resources_path is None: @@ -575,7 +575,7 @@ class CatalogPlugin(Plugin): # {{{ try: resources.extract(file, self.resources_path) except: - print(" customize:__init__.initialize(): %s not found in %s" % (file, os.path.basename(self.plugin_path))) + print(f" customize:__init__.initialize(): {file} not found in {os.path.basename(self.plugin_path)}") continue resources.close() diff --git a/src/calibre/customize/builtins.py b/src/calibre/customize/builtins.py index 3d3d5ea909..df6756dca6 100644 --- a/src/calibre/customize/builtins.py +++ b/src/calibre/customize/builtins.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - __license__ = 'GPL v3' __copyright__ = '2008, Kovid Goyal ' diff --git a/src/calibre/customize/conversion.py b/src/calibre/customize/conversion.py index 5cda8c420e..ca7d9a4b8c 100644 --- a/src/calibre/customize/conversion.py +++ b/src/calibre/customize/conversion.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - ''' Defines the plugin system for conversions. ''' diff --git a/src/calibre/customize/profiles.py b/src/calibre/customize/profiles.py index 85a697fd37..a0db7f41e1 100644 --- a/src/calibre/customize/profiles.py +++ b/src/calibre/customize/profiles.py @@ -1,5 +1,3 @@ -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai - __license__ = 'GPL 3' __copyright__ = '2009, Kovid Goyal ' __docformat__ = 'restructuredtext en' diff --git a/src/calibre/customize/ui.py b/src/calibre/customize/ui.py index 7fe802dc0a..07eca3cea2 100644 --- a/src/calibre/customize/ui.py +++ b/src/calibre/customize/ui.py @@ -849,7 +849,7 @@ def main(args=sys.argv): type_len = name_len = 0 for plugin in initialized_plugins(): type_len, name_len = max(type_len, len(plugin.type)), max(name_len, len(plugin.name)) - fmt = '%-{}s%-{}s%-15s%-15s%s'.format(type_len+1, name_len+1) + fmt = f'%-{type_len+1}s%-{name_len+1}s%-15s%-15s%s' print(fmt%tuple('Type|Name|Version|Disabled|Site Customization'.split('|'))) print() for plugin in initialized_plugins(): diff --git a/src/calibre/customize/zipplugin.py b/src/calibre/customize/zipplugin.py index 3fb6c7de34..26bbe63001 100644 --- a/src/calibre/customize/zipplugin.py +++ b/src/calibre/customize/zipplugin.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/db/__init__.py b/src/calibre/db/__init__.py index 75d9fccc4b..4f920976ce 100644 --- a/src/calibre/db/__init__.py +++ b/src/calibre/db/__init__.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/db/adding.py b/src/calibre/db/adding.py index c2ffd5901a..3b14633078 100644 --- a/src/calibre/db/adding.py +++ b/src/calibre/db/adding.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' @@ -242,7 +241,7 @@ def add_catalog(cache, path, title, dbapi=None): new_book_added = False with lopen(path, 'rb') as stream: with cache.write_lock: - matches = cache._search('title:="%s" and tags:="%s"' % (title.replace('"', '\\"'), _('Catalog')), None) + matches = cache._search('title:="{}" and tags:="{}"'.format(title.replace('"', '\\"'), _('Catalog')), None) db_id = None if matches: db_id = list(matches)[0] diff --git a/src/calibre/db/annotations.py b/src/calibre/db/annotations.py index 83be2e3d65..7379c014ca 100644 --- a/src/calibre/db/annotations.py +++ b/src/calibre/db/annotations.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2020, Kovid Goyal from collections import defaultdict diff --git a/src/calibre/db/backend.py b/src/calibre/db/backend.py index 43817e8dcb..2d822e64b5 100644 --- a/src/calibre/db/backend.py +++ b/src/calibre/db/backend.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' @@ -59,7 +58,7 @@ from polyglot.builtins import ( class FTSQueryError(ValueError): def __init__(self, query, sql_statement, apsw_error): - ValueError.__init__(self, 'Failed to parse search query: {} with error: {}'.format(query, apsw_error)) + ValueError.__init__(self, f'Failed to parse search query: {query} with error: {apsw_error}') self.query = query self.sql_statement = sql_statement @@ -1263,7 +1262,7 @@ class DB: author = ascii_filename(_('Unknown')) if author.upper() in WINDOWS_RESERVED_NAMES: author += 'w' - return '%s/%s%s' % (author, title, book_id) + return f'{author}/{title}{book_id}' def construct_file_name(self, book_id, title, author, extlen): ''' @@ -1450,7 +1449,7 @@ class DB: f = lopen(path, 'rb') except OSError as e: # Ensure the path that caused this error is reported - raise Exception('Failed to open %r with error: %s' % (path, e)) + raise Exception(f'Failed to open {path!r} with error: {e}') with f: if hasattr(dest, 'write'): @@ -1825,11 +1824,11 @@ class DB: fts_table=fts_table, highlight_start=highlight_start, highlight_end=highlight_end, snippet_size=max(1, min(snippet_size, 64))) else: - text = 'highlight({}, 0, "{}", "{}")'.format(fts_table, highlight_start, highlight_end) + text = f'highlight({fts_table}, 0, "{highlight_start}", "{highlight_end}")' query = 'SELECT {0}.id, {0}.book, {0}.format, {0}.user_type, {0}.user, {0}.annot_data, {1} FROM {0} ' query = query.format('annotations', text) query += ' JOIN {fts_table} ON annotations.id = {fts_table}.rowid'.format(fts_table=fts_table) - query += ' WHERE {fts_table} MATCH ?'.format(fts_table=fts_table) + query += f' WHERE {fts_table} MATCH ?' data = [fts_engine_query] if restrict_to_user: query += ' AND annotations.user_type = ? AND annotations.user = ?' @@ -1837,7 +1836,7 @@ class DB: if annotation_type: query += ' AND annotations.annot_type = ? ' data.append(annotation_type) - query += ' ORDER BY {}.rank '.format(fts_table) + query += f' ORDER BY {fts_table}.rank ' ls = json.loads try: for (rowid, book_id, fmt, user_type, user, annot_data, text) in self.execute(query, tuple(data)): diff --git a/src/calibre/db/backup.py b/src/calibre/db/backup.py index 911cb5948c..1de37ec821 100644 --- a/src/calibre/db/backup.py +++ b/src/calibre/db/backup.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8 __license__ = 'GPL v3' diff --git a/src/calibre/db/cache.py b/src/calibre/db/cache.py index 63b11d30ca..a9df41f0e9 100644 --- a/src/calibre/db/cache.py +++ b/src/calibre/db/cache.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' @@ -2437,11 +2436,11 @@ class Cache: format_metadata[book_id] = {} for fmt in self._formats(book_id): mdata = self.format_metadata(book_id, fmt) - key = '%s:%s:%s' % (key_prefix, book_id, fmt) + key = f'{key_prefix}:{book_id}:{fmt}' format_metadata[book_id][fmt] = key with exporter.start_file(key, mtime=mdata.get('mtime')) as dest: self._copy_format_to(book_id, fmt, dest, report_file_size=dest.ensure_space) - cover_key = '%s:%s:%s' % (key_prefix, book_id, '.cover') + cover_key = '{}:{}:{}'.format(key_prefix, book_id, '.cover') with exporter.start_file(cover_key) as dest: if not self.copy_cover_to(book_id, dest, report_file_size=dest.ensure_space): dest.discard() diff --git a/src/calibre/db/categories.py b/src/calibre/db/categories.py index 0fd61aeb56..4ea53c0179 100644 --- a/src/calibre/db/categories.py +++ b/src/calibre/db/categories.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:fdm=marker:ai __license__ = 'GPL v3' diff --git a/src/calibre/db/cli/__init__.py b/src/calibre/db/cli/__init__.py index 3a8e513f2e..7ec5edd315 100644 --- a/src/calibre/db/cli/__init__.py +++ b/src/calibre/db/cli/__init__.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2017, Kovid Goyal diff --git a/src/calibre/db/cli/cmd_add.py b/src/calibre/db/cli/cmd_add.py index bd5d4a6f99..414fdae4b4 100644 --- a/src/calibre/db/cli/cmd_add.py +++ b/src/calibre/db/cli/cmd_add.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2017, Kovid Goyal diff --git a/src/calibre/db/cli/cmd_add_custom_column.py b/src/calibre/db/cli/cmd_add_custom_column.py index a1ce639b9c..300d49bf6f 100644 --- a/src/calibre/db/cli/cmd_add_custom_column.py +++ b/src/calibre/db/cli/cmd_add_custom_column.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2017, Kovid Goyal diff --git a/src/calibre/db/cli/cmd_add_format.py b/src/calibre/db/cli/cmd_add_format.py index d0b25254a3..f180846a0a 100644 --- a/src/calibre/db/cli/cmd_add_format.py +++ b/src/calibre/db/cli/cmd_add_format.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2017, Kovid Goyal diff --git a/src/calibre/db/cli/cmd_backup_metadata.py b/src/calibre/db/cli/cmd_backup_metadata.py index edcd8b268f..5dd79ffdd2 100644 --- a/src/calibre/db/cli/cmd_backup_metadata.py +++ b/src/calibre/db/cli/cmd_backup_metadata.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2017, Kovid Goyal @@ -54,7 +53,7 @@ class BackupProgress: else: self.count += 1 prints( - '%.1f%% %s - %s' % ((self.count * 100) / float(self.total), book_id, + '{:.1f}% {} - {}'.format((self.count * 100) / float(self.total), book_id, getattr(mi, 'title', 'Unknown')) ) diff --git a/src/calibre/db/cli/cmd_catalog.py b/src/calibre/db/cli/cmd_catalog.py index 9ab7595cef..a3901180ea 100644 --- a/src/calibre/db/cli/cmd_catalog.py +++ b/src/calibre/db/cli/cmd_catalog.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2017, Kovid Goyal diff --git a/src/calibre/db/cli/cmd_check_library.py b/src/calibre/db/cli/cmd_check_library.py index 8d719b955d..4c3153baa8 100644 --- a/src/calibre/db/cli/cmd_check_library.py +++ b/src/calibre/db/cli/cmd_check_library.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2017, Kovid Goyal diff --git a/src/calibre/db/cli/cmd_clone.py b/src/calibre/db/cli/cmd_clone.py index dbe70ec615..31987f49ef 100644 --- a/src/calibre/db/cli/cmd_clone.py +++ b/src/calibre/db/cli/cmd_clone.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2017, Kovid Goyal diff --git a/src/calibre/db/cli/cmd_custom_columns.py b/src/calibre/db/cli/cmd_custom_columns.py index 115b6733fc..c9487be434 100644 --- a/src/calibre/db/cli/cmd_custom_columns.py +++ b/src/calibre/db/cli/cmd_custom_columns.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2017, Kovid Goyal diff --git a/src/calibre/db/cli/cmd_embed_metadata.py b/src/calibre/db/cli/cmd_embed_metadata.py index c0aab6378c..647926026a 100644 --- a/src/calibre/db/cli/cmd_embed_metadata.py +++ b/src/calibre/db/cli/cmd_embed_metadata.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2017, Kovid Goyal diff --git a/src/calibre/db/cli/cmd_export.py b/src/calibre/db/cli/cmd_export.py index b472ee4ea5..022892ffdb 100644 --- a/src/calibre/db/cli/cmd_export.py +++ b/src/calibre/db/cli/cmd_export.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2017, Kovid Goyal @@ -148,7 +147,7 @@ def main(opts, args, dbctx): export(opts, dbctx, book_id, dest, dbproxy, length, i == 0) if opts.progress: num = i + 1 - print('\r {:.0%} [{}/{}]'.format(num / total, num, total), end=' '*20) + print(f'\r {num / total:.0%} [{num}/{total}]', end=' '*20) if opts.progress: print() return 0 diff --git a/src/calibre/db/cli/cmd_list.py b/src/calibre/db/cli/cmd_list.py index 94913a8005..3591be0aba 100644 --- a/src/calibre/db/cli/cmd_list.py +++ b/src/calibre/db/cli/cmd_list.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2017, Kovid Goyal @@ -46,7 +45,7 @@ def implementation( fields = sorted(afields) sort_by = sort_by or 'id' if sort_by not in afields: - return 'Unknown sort field: {}'.format(sort_by) + return f'Unknown sort field: {sort_by}' if not set(fields).issubset(afields): return 'Unknown fields: {}'.format(', '.join(set(fields) - afields)) if search_text: diff --git a/src/calibre/db/cli/cmd_list_categories.py b/src/calibre/db/cli/cmd_list_categories.py index cb73569ae3..351d452fb4 100644 --- a/src/calibre/db/cli/cmd_list_categories.py +++ b/src/calibre/db/cli/cmd_list_categories.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2017, Kovid Goyal diff --git a/src/calibre/db/cli/cmd_remove.py b/src/calibre/db/cli/cmd_remove.py index 768e7962d0..7c5aae9df3 100644 --- a/src/calibre/db/cli/cmd_remove.py +++ b/src/calibre/db/cli/cmd_remove.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2017, Kovid Goyal diff --git a/src/calibre/db/cli/cmd_remove_custom_column.py b/src/calibre/db/cli/cmd_remove_custom_column.py index 5ac8a3d998..6d2f605894 100644 --- a/src/calibre/db/cli/cmd_remove_custom_column.py +++ b/src/calibre/db/cli/cmd_remove_custom_column.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2017, Kovid Goyal diff --git a/src/calibre/db/cli/cmd_remove_format.py b/src/calibre/db/cli/cmd_remove_format.py index afe75c6b79..d9cf715beb 100644 --- a/src/calibre/db/cli/cmd_remove_format.py +++ b/src/calibre/db/cli/cmd_remove_format.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2017, Kovid Goyal diff --git a/src/calibre/db/cli/cmd_restore_database.py b/src/calibre/db/cli/cmd_restore_database.py index f053a79970..2ac1e2296a 100644 --- a/src/calibre/db/cli/cmd_restore_database.py +++ b/src/calibre/db/cli/cmd_restore_database.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2017, Kovid Goyal diff --git a/src/calibre/db/cli/cmd_saved_searches.py b/src/calibre/db/cli/cmd_saved_searches.py index 6008fac18e..96f3f594f1 100644 --- a/src/calibre/db/cli/cmd_saved_searches.py +++ b/src/calibre/db/cli/cmd_saved_searches.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2017, Kovid Goyal diff --git a/src/calibre/db/cli/cmd_search.py b/src/calibre/db/cli/cmd_search.py index 246e230735..891604a9e5 100644 --- a/src/calibre/db/cli/cmd_search.py +++ b/src/calibre/db/cli/cmd_search.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2017, Kovid Goyal diff --git a/src/calibre/db/cli/cmd_set_custom.py b/src/calibre/db/cli/cmd_set_custom.py index b40fb887bf..301494fc3f 100644 --- a/src/calibre/db/cli/cmd_set_custom.py +++ b/src/calibre/db/cli/cmd_set_custom.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2017, Kovid Goyal diff --git a/src/calibre/db/cli/cmd_set_metadata.py b/src/calibre/db/cli/cmd_set_metadata.py index 1c36ecc529..ff31c37236 100644 --- a/src/calibre/db/cli/cmd_set_metadata.py +++ b/src/calibre/db/cli/cmd_set_metadata.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2017, Kovid Goyal diff --git a/src/calibre/db/cli/cmd_show_metadata.py b/src/calibre/db/cli/cmd_show_metadata.py index 7a846f9e32..dd764fd8d4 100644 --- a/src/calibre/db/cli/cmd_show_metadata.py +++ b/src/calibre/db/cli/cmd_show_metadata.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2017, Kovid Goyal diff --git a/src/calibre/db/cli/main.py b/src/calibre/db/cli/main.py index 4dbe8b331d..7ea7d04b82 100644 --- a/src/calibre/db/cli/main.py +++ b/src/calibre/db/cli/main.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2017, Kovid Goyal import json @@ -140,7 +139,7 @@ class DBCtx: parts = urlparse(self.library_path) self.library_id = parts.fragment or None self.url = urlunparse(parts._replace(fragment='')).rstrip('/') - self.br = browser(handle_refresh=False, user_agent='{} {}'.format(__appname__, __version__)) + self.br = browser(handle_refresh=False, user_agent=f'{__appname__} {__version__}') self.is_remote = True username, password = read_credentials(opts) self.has_credentials = False diff --git a/src/calibre/db/cli/tests.py b/src/calibre/db/cli/tests.py index e0687a6d10..a258da3525 100644 --- a/src/calibre/db/cli/tests.py +++ b/src/calibre/db/cli/tests.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/db/cli/utils.py b/src/calibre/db/cli/utils.py index e15609dcea..d0b5c2d2e3 100644 --- a/src/calibre/db/cli/utils.py +++ b/src/calibre/db/cli/utils.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2017, Kovid Goyal diff --git a/src/calibre/db/copy_to_library.py b/src/calibre/db/copy_to_library.py index 9a9adeaed9..a8df8372a2 100644 --- a/src/calibre/db/copy_to_library.py +++ b/src/calibre/db/copy_to_library.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2019, Kovid Goyal diff --git a/src/calibre/db/covers.py b/src/calibre/db/covers.py index 568eac0820..9034eb9934 100644 --- a/src/calibre/db/covers.py +++ b/src/calibre/db/covers.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2021, Kovid Goyal import os diff --git a/src/calibre/db/delete_service.py b/src/calibre/db/delete_service.py index c79808d195..8fff63d69c 100644 --- a/src/calibre/db/delete_service.py +++ b/src/calibre/db/delete_service.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' diff --git a/src/calibre/db/errors.py b/src/calibre/db/errors.py index 564e58c822..add9055e69 100644 --- a/src/calibre/db/errors.py +++ b/src/calibre/db/errors.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' @@ -14,5 +13,5 @@ class NoSuchFormat(ValueError): class NoSuchBook(KeyError): def __init__(self, book_id): - KeyError.__init__(self, 'No book with id: {} in database'.format(book_id)) + KeyError.__init__(self, f'No book with id: {book_id} in database') self.book_id = book_id diff --git a/src/calibre/db/fields.py b/src/calibre/db/fields.py index 450550c5fa..557f9e740f 100644 --- a/src/calibre/db/fields.py +++ b/src/calibre/db/fields.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/db/lazy.py b/src/calibre/db/lazy.py index 5fba1ab907..36040a6ec2 100644 --- a/src/calibre/db/lazy.py +++ b/src/calibre/db/lazy.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/db/legacy.py b/src/calibre/db/legacy.py index 3b90bad0e6..3f53f4b416 100644 --- a/src/calibre/db/legacy.py +++ b/src/calibre/db/legacy.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' diff --git a/src/calibre/db/listeners.py b/src/calibre/db/listeners.py index 33523b2183..11cf14912e 100644 --- a/src/calibre/db/listeners.py +++ b/src/calibre/db/listeners.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2021, Kovid Goyal import weakref diff --git a/src/calibre/db/locking.py b/src/calibre/db/locking.py index c689ae410f..fde75aa2b5 100644 --- a/src/calibre/db/locking.py +++ b/src/calibre/db/locking.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/db/restore.py b/src/calibre/db/restore.py index c31c110270..726804f2a1 100644 --- a/src/calibre/db/restore.py +++ b/src/calibre/db/restore.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/db/schema_upgrades.py b/src/calibre/db/schema_upgrades.py index c957d0bde3..c502622720 100644 --- a/src/calibre/db/schema_upgrades.py +++ b/src/calibre/db/schema_upgrades.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/db/search.py b/src/calibre/db/search.py index 897b96d0dc..bf15e060f2 100644 --- a/src/calibre/db/search.py +++ b/src/calibre/db/search.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:fdm=marker:ai __license__ = 'GPL v3' diff --git a/src/calibre/db/tables.py b/src/calibre/db/tables.py index 91fba0a106..cff608b312 100644 --- a/src/calibre/db/tables.py +++ b/src/calibre/db/tables.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' @@ -296,7 +295,7 @@ class ManyToOneTable(Table): # this is a many-to-one mapping we know that we can delete # links without checking the item ID db.executemany( - 'DELETE FROM {} WHERE book=?'.format(self.link_table), tuple((x,) for x in books_to_delete)) + f'DELETE FROM {self.link_table} WHERE book=?', tuple((x,) for x in books_to_delete)) affected_books |= books_to_delete else: # Process normally any items where the VL was not significant @@ -327,7 +326,7 @@ class ManyToOneTable(Table): if existing_item is None or existing_item == item_id: # A simple rename will do the trick self.id_map[item_id] = new_name - db.execute('UPDATE {} SET {}=? WHERE id=?'.format(table, col), (new_name, item_id)) + db.execute(f'UPDATE {table} SET {col}=? WHERE id=?', (new_name, item_id)) else: # We have to replace new_id = existing_item @@ -466,7 +465,7 @@ class ManyToManyTable(ManyToOneTable): if existing_item is None or existing_item == item_id: # A simple rename will do the trick self.id_map[item_id] = new_name - db.execute('UPDATE {} SET {}=? WHERE id=?'.format(table, col), (new_name, item_id)) + db.execute(f'UPDATE {table} SET {col}=? WHERE id=?', (new_name, item_id)) else: # We have to replace new_id = existing_item @@ -478,7 +477,7 @@ class ManyToManyTable(ManyToOneTable): for book_id in books: self.book_col_map[book_id] = tuple((existing_item if x == item_id else x) for x in self.book_col_map.get(book_id, ()) if x != existing_item) self.col_book_map[existing_item].update(books) - db.executemany('DELETE FROM {} WHERE book=? AND {}=?'.format(self.link_table, lcol), [ + db.executemany(f'DELETE FROM {self.link_table} WHERE book=? AND {lcol}=?', [ (book_id, existing_item) for book_id in books]) db.execute('UPDATE {0} SET {1}=? WHERE {1}=?; DELETE FROM {2} WHERE id=?'.format( self.link_table, lcol, table), (existing_item, item_id, item_id)) @@ -515,7 +514,7 @@ class ManyToManyTable(ManyToOneTable): tuple((main_id, x, book_id) for x in v)) else: # duplicates - db.execute('DELETE FROM {} WHERE book=?'.format(self.link_table), (book_id,)) + db.execute(f'DELETE FROM {self.link_table} WHERE book=?', (book_id,)) db.executemany( 'INSERT INTO {} (book,{}) VALUES (?,?)'.format(self.link_table, self.metadata['link_column']), tuple((book_id, x) for x in vals)) diff --git a/src/calibre/db/tests/__init__.py b/src/calibre/db/tests/__init__.py index 219dc1f99c..ad82601065 100644 --- a/src/calibre/db/tests/__init__.py +++ b/src/calibre/db/tests/__init__.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/db/tests/add_remove.py b/src/calibre/db/tests/add_remove.py index f2f94f6d0e..00fd416795 100644 --- a/src/calibre/db/tests/add_remove.py +++ b/src/calibre/db/tests/add_remove.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:fdm=marker:ai __license__ = 'GPL v3' diff --git a/src/calibre/db/tests/base.py b/src/calibre/db/tests/base.py index edd190baf7..6a9d6eca3f 100644 --- a/src/calibre/db/tests/base.py +++ b/src/calibre/db/tests/base.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/db/tests/filesystem.py b/src/calibre/db/tests/filesystem.py index 0254c80cfd..2ced22ebc2 100644 --- a/src/calibre/db/tests/filesystem.py +++ b/src/calibre/db/tests/filesystem.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:fdm=marker:ai __license__ = 'GPL v3' diff --git a/src/calibre/db/tests/fts.py b/src/calibre/db/tests/fts.py index 7f777b7737..dd278a6bfc 100644 --- a/src/calibre/db/tests/fts.py +++ b/src/calibre/db/tests/fts.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai # License: GPLv3 Copyright: 2021, Kovid Goyal diff --git a/src/calibre/db/tests/legacy.py b/src/calibre/db/tests/legacy.py index efbe7944be..4542eb6c8e 100644 --- a/src/calibre/db/tests/legacy.py +++ b/src/calibre/db/tests/legacy.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' @@ -30,7 +29,7 @@ class ET: legacy = self.legacy or test.init_legacy(test.cloned_library) oldres = getattr(old, self.func_name)(*self.args, **self.kwargs) newres = getattr(legacy, self.func_name)(*self.args, **self.kwargs) - test.assertEqual(oldres, newres, 'Equivalence test for %s with args: %s and kwargs: %s failed' % ( + test.assertEqual(oldres, newres, 'Equivalence test for {} with args: {} and kwargs: {} failed'.format( self.func_name, reprlib.repr(self.args), reprlib.repr(self.kwargs))) self.retval = newres return newres @@ -49,7 +48,7 @@ def compare_argspecs(old, new, attr): ok = len(old.args) == len(new.args) and get_defaults(old) == get_defaults(new) if not ok: - raise AssertionError('The argspec for %s does not match. %r != %r' % (attr, old, new)) + raise AssertionError(f'The argspec for {attr} does not match. {old!r} != {new!r}') def run_funcs(self, db, ndb, funcs): @@ -69,7 +68,7 @@ def run_funcs(self, db, ndb, funcs): args = args[:-1] meth = meth[1:] res1, res2 = fmt(getattr(db, meth)(*args)), fmt(getattr(ndb, meth)(*args)) - self.assertEqual(res1, res2, 'The method: %s() returned different results for argument %s' % (meth, args)) + self.assertEqual(res1, res2, f'The method: {meth}() returned different results for argument {args}') # }}} @@ -265,7 +264,7 @@ class LegacyTest(BaseTest): fmt = lambda val:{x[0]:tuple(x[1:]) for x in val} for a in args: self.assertEqual(fmt(getattr(db, meth)(*a)), fmt(getattr(ndb, meth)(*a)), - 'The method: %s() returned different results for argument %s' % (meth, a)) + f'The method: {meth}() returned different results for argument {a}') def f(x, y): # get_top_level_move_items is broken in the old db on case-insensitive file systems x.discard('metadata_db_prefs_backup.json') @@ -318,7 +317,7 @@ class LegacyTest(BaseTest): meth, args = x[0], x[1:] self.assertEqual( decode(getattr(db, meth)(*args)), decode(getattr(ndb, meth)(*args)), - 'The method: %s() returned different results for argument %s' % (meth, args) + f'The method: {meth}() returned different results for argument {args}' ) db.close() # }}} diff --git a/src/calibre/db/tests/locking.py b/src/calibre/db/tests/locking.py index 633ebddff0..c568a7ac3e 100644 --- a/src/calibre/db/tests/locking.py +++ b/src/calibre/db/tests/locking.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' @@ -186,7 +185,7 @@ class TestLock(BaseTest): break t.join(left) live = [t for t in threads if t.is_alive()] - self.assertEqual(len(live), 0, 'ShLock hung or very slow, {} threads alive'.format(len(live))) + self.assertEqual(len(live), 0, f'ShLock hung or very slow, {len(live)} threads alive') self.assertEqual(len(done), len(threads), 'SHLock locking failed') self.assertFalse(lock.is_shared) self.assertFalse(lock.is_exclusive) diff --git a/src/calibre/db/tests/main.py b/src/calibre/db/tests/main.py index e3afe467b1..94d972ad6d 100644 --- a/src/calibre/db/tests/main.py +++ b/src/calibre/db/tests/main.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:fdm=marker:ai __license__ = 'GPL v3' diff --git a/src/calibre/db/tests/profiling.py b/src/calibre/db/tests/profiling.py index 4c52282972..122b89a516 100644 --- a/src/calibre/db/tests/profiling.py +++ b/src/calibre/db/tests/profiling.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' diff --git a/src/calibre/db/tests/reading.py b/src/calibre/db/tests/reading.py index 2af44ae003..2fc89a0144 100644 --- a/src/calibre/db/tests/reading.py +++ b/src/calibre/db/tests/reading.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' @@ -609,9 +608,9 @@ class ReadingTest(BaseTest): if field == 'formats': f = lambda x: x if x is None else tuple(x) self.assertEqual(f(getattr(mi, field)), f(getattr(pmi, field)), - 'Standard field: %s not the same for book %s' % (field, book_id)) + f'Standard field: {field} not the same for book {book_id}') self.assertEqual(mi.format_field(field), pmi.format_field(field), - 'Standard field format: %s not the same for book %s' % (field, book_id)) + f'Standard field format: {field} not the same for book {book_id}') def f(x): try: @@ -627,9 +626,9 @@ class ReadingTest(BaseTest): for field, meta in cache.field_metadata.custom_iteritems(): if meta['datatype'] != 'composite': self.assertEqual(f(getattr(mi, field)), f(getattr(pmi, field)), - 'Custom field: %s not the same for book %s' % (field, book_id)) + f'Custom field: {field} not the same for book {book_id}') self.assertEqual(mi.format_field(field), pmi.format_field(field), - 'Custom field format: %s not the same for book %s' % (field, book_id)) + f'Custom field format: {field} not the same for book {book_id}') # Test handling of recursive templates cache.create_custom_column('comp2', 'comp2', 'composite', False, display={'composite_template':'{title}'}) diff --git a/src/calibre/db/tests/utils.py b/src/calibre/db/tests/utils.py index dcf8eba5b3..afa37adcbb 100644 --- a/src/calibre/db/tests/utils.py +++ b/src/calibre/db/tests/utils.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' diff --git a/src/calibre/db/tests/writing.py b/src/calibre/db/tests/writing.py index 5844617ce3..a5cc86647a 100644 --- a/src/calibre/db/tests/writing.py +++ b/src/calibre/db/tests/writing.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:fdm=marker:ai __license__ = 'GPL v3' @@ -402,10 +401,10 @@ class WritingTest(BaseTest): mi = cache.get_metadata(1) old_path = cache.field_for('path', 1) old_title, old_author = mi.title, mi.authors[0] - ae(old_path, '%s/%s (1)' % (old_author, old_title)) + ae(old_path, f'{old_author}/{old_title} (1)') mi.title, mi.authors = 'New Title', ['New Author'] cache.set_metadata(1, mi) - ae(cache.field_for('path', 1), '%s/%s (1)' % (mi.authors[0], mi.title)) + ae(cache.field_for('path', 1), f'{mi.authors[0]}/{mi.title} (1)') p = cache.format_abspath(1, 'FMT1') self.assertTrue(mi.authors[0] in p and mi.title in p) diff --git a/src/calibre/db/utils.py b/src/calibre/db/utils.py index 81737f350f..60badf4ca5 100644 --- a/src/calibre/db/utils.py +++ b/src/calibre/db/utils.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' diff --git a/src/calibre/db/view.py b/src/calibre/db/view.py index 751046b891..7b38abb13b 100644 --- a/src/calibre/db/view.py +++ b/src/calibre/db/view.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' @@ -279,7 +278,7 @@ class View: def _build_restriction_string(self, restriction): if self.base_restriction: if restriction: - return '(%s) and (%s)' % (self.base_restriction, restriction) + return f'({self.base_restriction}) and ({restriction})' else: return self.base_restriction else: @@ -295,7 +294,7 @@ class View: else: q = query if search_restriction: - q = '(%s) and (%s)' % (search_restriction, query) + q = f'({search_restriction}) and ({query})' if not q: if set_restriction_count: self.search_restriction_book_count = len(self._map) diff --git a/src/calibre/db/write.py b/src/calibre/db/write.py index 6be1d29374..21965fab39 100644 --- a/src/calibre/db/write.py +++ b/src/calibre/db/write.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:fdm=marker:ai __license__ = 'GPL v3' diff --git a/src/calibre/debug.py b/src/calibre/debug.py index c0168e56e3..7cd8711f42 100644 --- a/src/calibre/debug.py +++ b/src/calibre/debug.py @@ -208,7 +208,7 @@ def print_basic_debug_info(out=None): from calibre.customize.ui import has_external_plugins, initialized_plugins if has_external_plugins(): from calibre.customize import PluginInstallationType - names = ('{} {}'.format(p.name, p.version) for p in initialized_plugins() + names = (f'{p.name} {p.version}' for p in initialized_plugins() if getattr(p, 'installation_type', None) is not PluginInstallationType.BUILTIN) out('Successfully initialized third party plugins:', ' && '.join(names)) diff --git a/src/calibre/devices/android/__init__.py b/src/calibre/devices/android/__init__.py index d8edc6064a..872a71567f 100644 --- a/src/calibre/devices/android/__init__.py +++ b/src/calibre/devices/android/__init__.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/devices/android/driver.py b/src/calibre/devices/android/driver.py index ea8e419b01..268b2c3663 100644 --- a/src/calibre/devices/android/driver.py +++ b/src/calibre/devices/android/driver.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - __license__ = 'GPL v3' __copyright__ = '2009, Kovid Goyal ' __docformat__ = 'restructuredtext en' diff --git a/src/calibre/devices/binatone/driver.py b/src/calibre/devices/binatone/driver.py index 53a91bcc8c..bcd5a4ceeb 100644 --- a/src/calibre/devices/binatone/driver.py +++ b/src/calibre/devices/binatone/driver.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - __license__ = 'GPL v3' __copyright__ = '2009, John Schember ' __docformat__ = 'restructuredtext en' diff --git a/src/calibre/devices/blackberry/driver.py b/src/calibre/devices/blackberry/driver.py index 7f6eeaae90..840c23a1e0 100644 --- a/src/calibre/devices/blackberry/driver.py +++ b/src/calibre/devices/blackberry/driver.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - __license__ = 'GPL 3' __copyright__ = '2009, Kovid Goyal ' __docformat__ = 'restructuredtext en' diff --git a/src/calibre/devices/cybook/driver.py b/src/calibre/devices/cybook/driver.py index 07f9f4d4a6..adf991af72 100644 --- a/src/calibre/devices/cybook/driver.py +++ b/src/calibre/devices/cybook/driver.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - __license__ = 'GPL v3' __copyright__ = '2009, John Schember ' __docformat__ = 'restructuredtext en' diff --git a/src/calibre/devices/cybook/t4b.py b/src/calibre/devices/cybook/t4b.py index 33a327ea2d..22487d363d 100644 --- a/src/calibre/devices/cybook/t4b.py +++ b/src/calibre/devices/cybook/t4b.py @@ -1,5 +1,3 @@ -# vim:fileencoding=utf-8 - __license__ = 'GPL v3' __copyright__ = '2013, Jellby ' ''' diff --git a/src/calibre/devices/eb600/driver.py b/src/calibre/devices/eb600/driver.py index 797f70812e..62a4e95df5 100644 --- a/src/calibre/devices/eb600/driver.py +++ b/src/calibre/devices/eb600/driver.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - __license__ = 'GPL v3' __copyright__ = '2009, Kovid Goyal ' __docformat__ = 'restructuredtext en' @@ -86,7 +83,7 @@ class TOLINO(EB600): def get_device_information(self, end_session=True): self.set_device_name() - return super(TOLINO, self).get_device_information(end_session) + return super().get_device_information(end_session) # There are apparently two versions of this device, one with swapped # drives and one without, see https://bugs.launchpad.net/bugs/1240504 diff --git a/src/calibre/devices/edge/driver.py b/src/calibre/devices/edge/driver.py index d4bd1a7364..5335c03d24 100644 --- a/src/calibre/devices/edge/driver.py +++ b/src/calibre/devices/edge/driver.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - __license__ = 'GPL v3' __copyright__ = '2009, Kovid Goyal' __docformat__ = 'restructuredtext en' diff --git a/src/calibre/devices/eslick/__init__.py b/src/calibre/devices/eslick/__init__.py index d8edc6064a..872a71567f 100644 --- a/src/calibre/devices/eslick/__init__.py +++ b/src/calibre/devices/eslick/__init__.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/devices/eslick/driver.py b/src/calibre/devices/eslick/driver.py index 328bddac5a..2c3bbb2980 100644 --- a/src/calibre/devices/eslick/driver.py +++ b/src/calibre/devices/eslick/driver.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/devices/folder_device/__init__.py b/src/calibre/devices/folder_device/__init__.py index d8edc6064a..872a71567f 100644 --- a/src/calibre/devices/folder_device/__init__.py +++ b/src/calibre/devices/folder_device/__init__.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/devices/hanlin/driver.py b/src/calibre/devices/hanlin/driver.py index e25f577f05..98f84091cc 100644 --- a/src/calibre/devices/hanlin/driver.py +++ b/src/calibre/devices/hanlin/driver.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - __license__ = 'GPL v3' __copyright__ = '2009, Tijmen Ruizendaal ' __docformat__ = 'restructuredtext en' diff --git a/src/calibre/devices/hanvon/driver.py b/src/calibre/devices/hanvon/driver.py index 420fc4d7fa..3c9e2b3ba7 100644 --- a/src/calibre/devices/hanvon/driver.py +++ b/src/calibre/devices/hanvon/driver.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - __license__ = 'GPL v3' __copyright__ = '2009, John Schember ' __docformat__ = 'restructuredtext en' diff --git a/src/calibre/devices/iliad/driver.py b/src/calibre/devices/iliad/driver.py index e63c38d965..06c6992e31 100644 --- a/src/calibre/devices/iliad/driver.py +++ b/src/calibre/devices/iliad/driver.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - __license__ = 'GPL 3' __copyright__ = '2009, John Schember ' __docformat__ = 'restructuredtext en' diff --git a/src/calibre/devices/irexdr/driver.py b/src/calibre/devices/irexdr/driver.py index d18ae315a7..e38b0dede0 100644 --- a/src/calibre/devices/irexdr/driver.py +++ b/src/calibre/devices/irexdr/driver.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - __license__ = 'GPL 3' __copyright__ = '2009, John Schember ' __docformat__ = 'restructuredtext en' diff --git a/src/calibre/devices/iriver/__init__.py b/src/calibre/devices/iriver/__init__.py index d8edc6064a..872a71567f 100644 --- a/src/calibre/devices/iriver/__init__.py +++ b/src/calibre/devices/iriver/__init__.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/devices/iriver/driver.py b/src/calibre/devices/iriver/driver.py index 83467f1bb8..7beb9cf794 100644 --- a/src/calibre/devices/iriver/driver.py +++ b/src/calibre/devices/iriver/driver.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/devices/jetbook/driver.py b/src/calibre/devices/jetbook/driver.py index a047bdedad..98c20167ea 100644 --- a/src/calibre/devices/jetbook/driver.py +++ b/src/calibre/devices/jetbook/driver.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - __license__ = 'GPL v3' __copyright__ = '2009, James Ralston ' __docformat__ = 'restructuredtext en' @@ -58,7 +55,7 @@ class JETBOOK(USBMS): au = mi.format_authors() if not au: au = 'Unknown' - return '%s#%s%s' % (au, title, fileext) + return f'{au}#{title}{fileext}' @classmethod def metadata_from_path(cls, path): diff --git a/src/calibre/devices/kindle/apnx.py b/src/calibre/devices/kindle/apnx.py index 36acd431f0..21176374a9 100644 --- a/src/calibre/devices/kindle/apnx.py +++ b/src/calibre/devices/kindle/apnx.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - __license__ = 'GPL v3' __copyright__ = '2011, John Schember ' __docformat__ = 'restructuredtext en' diff --git a/src/calibre/devices/kindle/bookmark.py b/src/calibre/devices/kindle/bookmark.py index df4f5b2d6d..1d9b240d1c 100644 --- a/src/calibre/devices/kindle/bookmark.py +++ b/src/calibre/devices/kindle/bookmark.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - __license__ = 'GPL v3' __docformat__ = 'restructuredtext en' diff --git a/src/calibre/devices/kindle/driver.py b/src/calibre/devices/kindle/driver.py index 8172c956ed..16c0bbd935 100644 --- a/src/calibre/devices/kindle/driver.py +++ b/src/calibre/devices/kindle/driver.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - __license__ = 'GPL v3' __copyright__ = '2009, John Schember ' __docformat__ = 'restructuredtext en' @@ -557,7 +554,7 @@ class KINDLE2(KINDLE): shutil.copyfileobj(src, dest) fsync(dest) if DEBUG: - prints('Restored {} cover thumbnails that were destroyed by Amazon'.format(count)) + prints(f'Restored {count} cover thumbnails that were destroyed by Amazon') def delete_single_book(self, path): try: @@ -569,7 +566,7 @@ class KINDLE2(KINDLE): os.remove(tp) except OSError as err: if err.errno != errno.ENOENT: - prints('Failed to delete thumbnail for {!r} at {!r} with error: {}'.format(path, tp, err)) + prints(f'Failed to delete thumbnail for {path!r} at {tp!r} with error: {err}') except Exception: import traceback traceback.print_exc() diff --git a/src/calibre/devices/kobo/__init__.py b/src/calibre/devices/kobo/__init__.py index c227aeaca5..b5e7183f9f 100644 --- a/src/calibre/devices/kobo/__init__.py +++ b/src/calibre/devices/kobo/__init__.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/devices/kobo/bookmark.py b/src/calibre/devices/kobo/bookmark.py index a370bcd08b..22b77bdba0 100644 --- a/src/calibre/devices/kobo/bookmark.py +++ b/src/calibre/devices/kobo/bookmark.py @@ -1,6 +1,3 @@ -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai - - __license__ = 'GPL v3' __copyright__ = '2011, Timothy Legge and Kovid Goyal ' __docformat__ = 'restructuredtext en' @@ -57,7 +54,7 @@ class Bookmark(): # {{{ 'ORDER BY bm.ContentID, bm.chapterprogress' ) - debug_print("Kobo::Bookmark::get_bookmark_data - getting kepub chapters: contentId={}".format(self.contentId)) + debug_print(f"Kobo::Bookmark::get_bookmark_data - getting kepub chapters: contentId={self.contentId}") cursor.execute(kepub_chapter_query, book_query_values) kepub_chapters = {} if self.kepub: @@ -69,7 +66,7 @@ class Bookmark(): # {{{ 'chapter_title': chapter_row['Title'], 'chapter_index': chapter_row['VolumeIndex'] } - debug_print("Kobo::Bookmark::get_bookmark_data - getting kepub chapter: kepub chapters={}".format(kepub_chapters)) + debug_print(f"Kobo::Bookmark::get_bookmark_data - getting kepub chapter: kepub chapters={kepub_chapters}") except: debug_print("Kobo::Bookmark::get_bookmark_data - No chapters found") @@ -83,20 +80,20 @@ class Bookmark(): # {{{ # For kepubs on newer firmware, the title needs to come from an 899 row. if self.kepub: chapter_contentID = row['ContentID'] - debug_print("Kobo::Bookmark::get_bookmark_data - getting kepub: chapter chapter_contentID='{}'".format(chapter_contentID)) + debug_print(f"Kobo::Bookmark::get_bookmark_data - getting kepub: chapter chapter_contentID='{chapter_contentID}'") filename_index = chapter_contentID.find('!') book_contentID_part = chapter_contentID[:filename_index] - debug_print("Kobo::Bookmark::get_bookmark_data - getting kepub: chapter book_contentID_part='{}'".format(book_contentID_part)) + debug_print(f"Kobo::Bookmark::get_bookmark_data - getting kepub: chapter book_contentID_part='{book_contentID_part}'") file_contentID_part = chapter_contentID[filename_index + 1:] filename_index = file_contentID_part.find('!') opf_reference = file_contentID_part[:filename_index] - debug_print("Kobo::Bookmark::get_bookmark_data - getting kepub: chapter opf_reference='{}'".format(opf_reference)) + debug_print(f"Kobo::Bookmark::get_bookmark_data - getting kepub: chapter opf_reference='{opf_reference}'") file_contentID_part = file_contentID_part[filename_index + 1:] - debug_print("Kobo::Bookmark::get_bookmark_data - getting kepub: chapter file_contentID_part='{}'".format(file_contentID_part)) + debug_print(f"Kobo::Bookmark::get_bookmark_data - getting kepub: chapter file_contentID_part='{file_contentID_part}'") # from urllib import quote # file_contentID_part = quote(file_contentID_part) chapter_contentID = book_contentID_part + "!" + opf_reference + "!" + file_contentID_part - debug_print("Kobo::Bookmark::get_bookmark_data - getting kepub chapter chapter_contentID='{}'".format(chapter_contentID)) + debug_print(f"Kobo::Bookmark::get_bookmark_data - getting kepub chapter chapter_contentID='{chapter_contentID}'") kepub_chapter = kepub_chapters.get(chapter_contentID, None) if kepub_chapter is not None: chapter_title = kepub_chapter['chapter_title'] diff --git a/src/calibre/devices/kobo/driver.py b/src/calibre/devices/kobo/driver.py index a92e7bf697..559295cbeb 100644 --- a/src/calibre/devices/kobo/driver.py +++ b/src/calibre/devices/kobo/driver.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' @@ -1573,11 +1572,11 @@ class KOBOTOUCH(KOBO): if main and carda and not self.is_main_drive(main): drives['main'] = carda drives['carda'] = main - debug_print('KoboTouch::sort_drives - swapped drives - main=%s, carda=%s' % (drives['main'], drives['carda'])) + debug_print('KoboTouch::sort_drives - swapped drives - main={}, carda={}'.format(drives['main'], drives['carda'])) return drives def is_main_drive(self, drive): - debug_print('KoboTouch::is_main_drive - drive=%s, path=%s' % (drive, os.path.join(drive, '.kobo'))) + debug_print('KoboTouch::is_main_drive - drive={}, path={}'.format(drive, os.path.join(drive, '.kobo'))) return os.path.exists(self.normalize_path(os.path.join(drive, '.kobo'))) def books(self, oncard=None, end_session=True): @@ -2128,13 +2127,13 @@ class KOBOTOUCH(KOBO): from css_parser import parseFile as cssparseFile try: extra_sheet = cssparseFile(extra_css_path) - debug_print("KoboTouch:get_extra_css: Using extra CSS in {} ({} rules)".format(extra_css_path, len(extra_sheet.cssRules))) + debug_print(f"KoboTouch:get_extra_css: Using extra CSS in {extra_css_path} ({len(extra_sheet.cssRules)} rules)") if len(extra_sheet.cssRules) ==0: debug_print("KoboTouch:get_extra_css: Extra CSS file has no valid rules. CSS will not be modified.") extra_sheet = None except Exception as e: - debug_print("KoboTouch:get_extra_css: Problem parsing extra CSS file {}".format(extra_css_path)) - debug_print("KoboTouch:get_extra_css: Exception {}".format(e)) + debug_print(f"KoboTouch:get_extra_css: Problem parsing extra CSS file {extra_css_path}") + debug_print(f"KoboTouch:get_extra_css: Exception {e}") # create dictionary of features enabled in kobo extra css self.extra_css_options = {} @@ -2166,7 +2165,7 @@ class KOBOTOUCH(KOBO): i = 0 for file, n, mi in zip(files, names, metadata): debug_print("KoboTouch:upload_books: Processing book: {} by {}".format(mi.title, " and ".join(mi.authors))) - debug_print("KoboTouch:upload_books: file=%s, name=%s" % (file, n)) + debug_print(f"KoboTouch:upload_books: file={file}, name={n}") self.report_progress(i / float(len(files)), "Processing book: {} by {}".format(mi.title, " and ".join(mi.authors))) mi.kte_calibre_name = n self._modify_epub(file, mi) @@ -2208,7 +2207,7 @@ class KOBOTOUCH(KOBO): return result def _modify_epub(self, book_file, metadata, container=None): - debug_print("KoboTouch:_modify_epub:Processing {} - {}".format(metadata.author_sort, metadata.title)) + debug_print(f"KoboTouch:_modify_epub:Processing {metadata.author_sort} - {metadata.title}") # Currently only modifying CSS, so if no stylesheet, don't do anything if not self.extra_sheet: @@ -2229,9 +2228,9 @@ class KOBOTOUCH(KOBO): # future css mods may be epub/kepub specific, so pass file extension arg fileext = os.path.splitext(book_file)[-1].lower() - debug_print("KoboTouch:_modify_epub: Modifying {}".format(cssname)) + debug_print(f"KoboTouch:_modify_epub: Modifying {cssname}") if self._modify_stylesheet(newsheet, fileext): - debug_print("KoboTouch:_modify_epub:CSS rules {} -> {} ({})".format(oldrules, len(newsheet.cssRules), cssname)) + debug_print(f"KoboTouch:_modify_epub:CSS rules {oldrules} -> {len(newsheet.cssRules)} ({cssname})") container.dirty(cssname) is_dirty = True @@ -2285,8 +2284,8 @@ class KOBOTOUCH(KOBO): container = get_container(book_file) container.css_preprocessor = DummyCSSPreProcessor() except Exception as e: - debug_print("KoboTouch:create_container: exception from get_container {} - {}".format(metadata.author_sort, metadata.title)) - debug_print("KoboTouch:create_container: exception is: {}".format(e)) + debug_print(f"KoboTouch:create_container: exception from get_container {metadata.author_sort} - {metadata.title}") + debug_print(f"KoboTouch:create_container: exception is: {e}") else: commit_container = False debug_print("KoboTouch:create_container: received container") @@ -3090,7 +3089,7 @@ class KOBOTOUCH(KOBO): debug_print(' Did not find a record - adding shelf "%s"' % bookshelf_name) cursor.execute(addquery, add_values) elif result['_IsDeleted'] == 'true': - debug_print("KoboTouch:check_for_bookshelf - Shelf '%s' is deleted - undeleting. result['_IsDeleted']='%s'" % ( + debug_print("KoboTouch:check_for_bookshelf - Shelf '{}' is deleted - undeleting. result['_IsDeleted']='{}'".format( bookshelf_name, str(result['_IsDeleted']))) cursor.execute(updatequery, test_values) @@ -3177,7 +3176,7 @@ class KOBOTOUCH(KOBO): # debug_print('KoboTouch:set_core_metadata book="%s"' % book.title) show_debug = self.is_debugging_title(book.title) if show_debug: - debug_print('KoboTouch:set_core_metadata book="%s", \nseries_only="%s"' % (book, series_only)) + debug_print(f'KoboTouch:set_core_metadata book="{book}", \nseries_only="{series_only}"') plugboard = None if self.plugboard_func and not series_only: @@ -3204,11 +3203,11 @@ class KOBOTOUCH(KOBO): kobo_metadata = book.kobo_metadata if show_debug: - debug_print('KoboTouch:set_core_metadata newmi.series="%s"' % (newmi.series, )) - debug_print('KoboTouch:set_core_metadata kobo_metadata.series="%s"' % (kobo_metadata.series, )) - debug_print('KoboTouch:set_core_metadata newmi.series_index="%s"' % (newmi.series_index, )) - debug_print('KoboTouch:set_core_metadata kobo_metadata.series_index="%s"' % (kobo_metadata.series_index, )) - debug_print('KoboTouch:set_core_metadata book.kobo_series_number="%s"' % (book.kobo_series_number, )) + debug_print(f'KoboTouch:set_core_metadata newmi.series="{newmi.series}"') + debug_print(f'KoboTouch:set_core_metadata kobo_metadata.series="{kobo_metadata.series}"') + debug_print(f'KoboTouch:set_core_metadata newmi.series_index="{newmi.series_index}"') + debug_print(f'KoboTouch:set_core_metadata kobo_metadata.series_index="{kobo_metadata.series_index}"') + debug_print(f'KoboTouch:set_core_metadata book.kobo_series_number="{book.kobo_series_number}"') if newmi.series is not None: new_series = newmi.series @@ -3223,10 +3222,10 @@ class KOBOTOUCH(KOBO): series_changed = not (new_series == kobo_metadata.series) series_number_changed = not (new_series_number == book.kobo_series_number) if show_debug: - debug_print('KoboTouch:set_core_metadata new_series="%s"' % (new_series, )) - debug_print('KoboTouch:set_core_metadata new_series_number="%s"' % (new_series_number, )) - debug_print('KoboTouch:set_core_metadata series_number_changed="%s"' % (series_number_changed, )) - debug_print('KoboTouch:set_core_metadata series_changed="%s"' % (series_changed, )) + debug_print(f'KoboTouch:set_core_metadata new_series="{new_series}"') + debug_print(f'KoboTouch:set_core_metadata new_series_number="{new_series_number}"') + debug_print(f'KoboTouch:set_core_metadata series_number_changed="{series_number_changed}"') + debug_print(f'KoboTouch:set_core_metadata series_changed="{series_changed}"') if series_changed or series_number_changed: update_values.append(new_series) @@ -3250,7 +3249,7 @@ class KOBOTOUCH(KOBO): update_values.append(newmi.series_index) set_clause += ', SeriesNumberFloat = ? ' if show_debug: - debug_print("KoboTouch:set_core_metadata Setting SeriesID - new_series='%s', series_id='%s'" % (new_series, series_id)) + debug_print(f"KoboTouch:set_core_metadata Setting SeriesID - new_series='{new_series}', series_id='{series_id}'") if not series_only: if not (newmi.title == kobo_metadata.title): @@ -3900,8 +3899,8 @@ class KOBOTOUCH(KOBO): debug_print('KoboTouch:dump_bookshelves - end') def __str__(self, *args, **kwargs): - options = ', '.join(['%s: %s' % (x.name, self.get_pref(x.name)) for x in self._config().preferences]) - return "Driver:%s, Options - %s" % (self.name, options) + options = ', '.join([f'{x.name}: {self.get_pref(x.name)}' for x in self._config().preferences]) + return f"Driver:{self.name}, Options - {options}" if __name__ == '__main__': diff --git a/src/calibre/devices/kobo/kobotouch_config.py b/src/calibre/devices/kobo/kobotouch_config.py index dfc35d7015..c571faa448 100644 --- a/src/calibre/devices/kobo/kobotouch_config.py +++ b/src/calibre/devices/kobo/kobotouch_config.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:fdm=marker:ai __license__ = 'GPL v3' diff --git a/src/calibre/devices/misc.py b/src/calibre/devices/misc.py index 1d32426f00..1c35bf4dc7 100644 --- a/src/calibre/devices/misc.py +++ b/src/calibre/devices/misc.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/devices/mtp/__init__.py b/src/calibre/devices/mtp/__init__.py index 6b2910c3df..c2a96b7708 100644 --- a/src/calibre/devices/mtp/__init__.py +++ b/src/calibre/devices/mtp/__init__.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/devices/mtp/base.py b/src/calibre/devices/mtp/base.py index 0c6d5c5540..c028d83fde 100644 --- a/src/calibre/devices/mtp/base.py +++ b/src/calibre/devices/mtp/base.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:fdm=marker:ai __license__ = 'GPL v3' diff --git a/src/calibre/devices/mtp/books.py b/src/calibre/devices/mtp/books.py index 06478a6aa8..3384a830d5 100644 --- a/src/calibre/devices/mtp/books.py +++ b/src/calibre/devices/mtp/books.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:fdm=marker:ai __license__ = 'GPL v3' diff --git a/src/calibre/devices/mtp/defaults.py b/src/calibre/devices/mtp/defaults.py index 49dfec73dd..b8d091a347 100644 --- a/src/calibre/devices/mtp/defaults.py +++ b/src/calibre/devices/mtp/defaults.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:fdm=marker:ai __license__ = 'GPL v3' diff --git a/src/calibre/devices/mtp/driver.py b/src/calibre/devices/mtp/driver.py index 54276b55a2..7452c5cf86 100644 --- a/src/calibre/devices/mtp/driver.py +++ b/src/calibre/devices/mtp/driver.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:fdm=marker:ai __license__ = 'GPL v3' diff --git a/src/calibre/devices/mtp/filesystem_cache.py b/src/calibre/devices/mtp/filesystem_cache.py index 632f5a3fb4..92e2d9e1e0 100644 --- a/src/calibre/devices/mtp/filesystem_cache.py +++ b/src/calibre/devices/mtp/filesystem_cache.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:fdm=marker:ai __license__ = 'GPL v3' diff --git a/src/calibre/devices/mtp/test.py b/src/calibre/devices/mtp/test.py index 45a81d4d53..5e62e3ceb5 100644 --- a/src/calibre/devices/mtp/test.py +++ b/src/calibre/devices/mtp/test.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:fdm=marker:ai __license__ = 'GPL v3' diff --git a/src/calibre/devices/mtp/unix/__init__.py b/src/calibre/devices/mtp/unix/__init__.py index 004e23d52d..a2ec8c43b0 100644 --- a/src/calibre/devices/mtp/unix/__init__.py +++ b/src/calibre/devices/mtp/unix/__init__.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/devices/mtp/unix/driver.py b/src/calibre/devices/mtp/unix/driver.py index 8130f088b3..611879e1b7 100644 --- a/src/calibre/devices/mtp/unix/driver.py +++ b/src/calibre/devices/mtp/unix/driver.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:fdm=marker:ai __license__ = 'GPL v3' __copyright__ = '2012, Kovid Goyal ' @@ -75,7 +74,7 @@ class MTP_DEVICE(MTPDeviceBase): traceback.print_stack() return False if debug is not None and ans: - debug('Device {} claims to be an MTP device in the IOKit registry'.format(d)) + debug(f'Device {d} claims to be an MTP device in the IOKit registry') return bool(ans) def set_debug_level(self, lvl): diff --git a/src/calibre/devices/mtp/unix/sysfs.py b/src/calibre/devices/mtp/unix/sysfs.py index a79745e80b..0200209d6e 100644 --- a/src/calibre/devices/mtp/unix/sysfs.py +++ b/src/calibre/devices/mtp/unix/sysfs.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:fdm=marker:ai __license__ = 'GPL v3' diff --git a/src/calibre/devices/mtp/unix/upstream/update.py b/src/calibre/devices/mtp/unix/upstream/update.py index 54e17e5c23..c43d90cbc8 100755 --- a/src/calibre/devices/mtp/unix/upstream/update.py +++ b/src/calibre/devices/mtp/unix/upstream/update.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:fdm=marker:ai __license__ = 'GPL v3' diff --git a/src/calibre/devices/mtp/windows/__init__.py b/src/calibre/devices/mtp/windows/__init__.py index 3610d3374c..fba7748a38 100644 --- a/src/calibre/devices/mtp/windows/__init__.py +++ b/src/calibre/devices/mtp/windows/__init__.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:fdm=marker:ai __license__ = 'GPL v3' diff --git a/src/calibre/devices/mtp/windows/driver.py b/src/calibre/devices/mtp/windows/driver.py index 3bfbe1f451..0c2432f985 100644 --- a/src/calibre/devices/mtp/windows/driver.py +++ b/src/calibre/devices/mtp/windows/driver.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:fdm=marker:ai __license__ = 'GPL v3' diff --git a/src/calibre/devices/nokia/driver.py b/src/calibre/devices/nokia/driver.py index b3b9b8a94d..020afd6573 100644 --- a/src/calibre/devices/nokia/driver.py +++ b/src/calibre/devices/nokia/driver.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - __license__ = 'GPL v3' __copyright__ = '2009-2014, John Schember and Andres Gomez ' __docformat__ = 'restructuredtext en' diff --git a/src/calibre/devices/nook/driver.py b/src/calibre/devices/nook/driver.py index ae295b461c..46d57f692c 100644 --- a/src/calibre/devices/nook/driver.py +++ b/src/calibre/devices/nook/driver.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - __license__ = 'GPL v3' __copyright__ = '2009, John Schember ' __docformat__ = 'restructuredtext en' diff --git a/src/calibre/devices/nuut2/driver.py b/src/calibre/devices/nuut2/driver.py index 7a4c76b5a0..5c14394909 100644 --- a/src/calibre/devices/nuut2/driver.py +++ b/src/calibre/devices/nuut2/driver.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - __license__ = 'GPL v3' __copyright__ = '2009, Kovid Goyal ' __docformat__ = 'restructuredtext en' diff --git a/src/calibre/devices/paladin/__init__.py b/src/calibre/devices/paladin/__init__.py index 463ad37bb2..1f6b29ebfa 100644 --- a/src/calibre/devices/paladin/__init__.py +++ b/src/calibre/devices/paladin/__init__.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/devices/paladin/driver.py b/src/calibre/devices/paladin/driver.py index bd6aea84ef..1ddec6b72c 100644 --- a/src/calibre/devices/paladin/driver.py +++ b/src/calibre/devices/paladin/driver.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2016, Kovid Goyal diff --git a/src/calibre/devices/prs505/sony_cache.py b/src/calibre/devices/prs505/sony_cache.py index d77273ae9c..7fa4f3788f 100644 --- a/src/calibre/devices/prs505/sony_cache.py +++ b/src/calibre/devices/prs505/sony_cache.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/devices/prst1/__init__.py b/src/calibre/devices/prst1/__init__.py index 463ad37bb2..1f6b29ebfa 100644 --- a/src/calibre/devices/prst1/__init__.py +++ b/src/calibre/devices/prst1/__init__.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/devices/prst1/driver.py b/src/calibre/devices/prst1/driver.py index 8ef883af64..647023d6fe 100644 --- a/src/calibre/devices/prst1/driver.py +++ b/src/calibre/devices/prst1/driver.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/devices/smart_device_app/__init__.py b/src/calibre/devices/smart_device_app/__init__.py index c227aeaca5..b5e7183f9f 100644 --- a/src/calibre/devices/smart_device_app/__init__.py +++ b/src/calibre/devices/smart_device_app/__init__.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/devices/smart_device_app/driver.py b/src/calibre/devices/smart_device_app/driver.py index 7e9292bb66..c36a7ae2c7 100644 --- a/src/calibre/devices/smart_device_app/driver.py +++ b/src/calibre/devices/smart_device_app/driver.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai ''' Created on 29 Jun 2012 @@ -2112,7 +2111,7 @@ def monkeypatched_service_type_name(type_: str, *, strict: bool = True) -> str: trailer = type_[-len(_LOCAL_TRAILER) + 1 :] has_protocol = False else: - raise BadTypeInNameException("Type '%s' must end with '%s'" % (type_, _LOCAL_TRAILER)) + raise BadTypeInNameException(f"Type '{type_}' must end with '{_LOCAL_TRAILER}'") if strict or has_protocol: service_name = remaining.pop() diff --git a/src/calibre/devices/sne/driver.py b/src/calibre/devices/sne/driver.py index 357b7ea511..e8cfa72c00 100644 --- a/src/calibre/devices/sne/driver.py +++ b/src/calibre/devices/sne/driver.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - __license__ = 'GPL v3' __copyright__ = '2009, John Schember ' __docformat__ = 'restructuredtext en' diff --git a/src/calibre/devices/teclast/__init__.py b/src/calibre/devices/teclast/__init__.py index c227aeaca5..b5e7183f9f 100644 --- a/src/calibre/devices/teclast/__init__.py +++ b/src/calibre/devices/teclast/__init__.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/devices/udisks.py b/src/calibre/devices/udisks.py index 6beda24277..a53f172164 100644 --- a/src/calibre/devices/udisks.py +++ b/src/calibre/devices/udisks.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/devices/usbms/books.py b/src/calibre/devices/usbms/books.py index 507ee5ff91..173475f8ee 100644 --- a/src/calibre/devices/usbms/books.py +++ b/src/calibre/devices/usbms/books.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - __license__ = 'GPL 3' __copyright__ = '2009, John Schember ' __docformat__ = 'restructuredtext en' diff --git a/src/calibre/devices/usbms/cli.py b/src/calibre/devices/usbms/cli.py index 148607da03..364ad80c9b 100644 --- a/src/calibre/devices/usbms/cli.py +++ b/src/calibre/devices/usbms/cli.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - __license__ = 'GPL v3' __copyright__ = '2009, John Schember ' __docformat__ = 'restructuredtext en' diff --git a/src/calibre/devices/usbms/device.py b/src/calibre/devices/usbms/device.py index b844d76627..0958b6eefc 100644 --- a/src/calibre/devices/usbms/device.py +++ b/src/calibre/devices/usbms/device.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - __license__ = 'GPL v3' __copyright__ = '2009, John Schember ' \ '2009, Kovid Goyal ' @@ -232,7 +229,7 @@ class Device(DeviceConfig, DevicePlugin): usbdevice.vendor_id, usbdevice.product_id, usbdevice.bcd, data.get('manufacturer') or '', data.get('product') or '', data.get('serial_number') or '') if debug: - prints('USB Info for device: {}'.format(dev)) + prints(f'USB Info for device: {dev}') return self.can_handle(dev, debug=debug) def open_windows(self): @@ -251,7 +248,7 @@ class Device(DeviceConfig, DevicePlugin): if debug: from pprint import pformat - prints('Drive letters for {}'.format(usbdev)) + prints(f'Drive letters for {usbdev}') prints(pformat(dlmap)) filtered = set() @@ -264,7 +261,7 @@ class Device(DeviceConfig, DevicePlugin): elif self.windows_filter_pnp_id(pnp_id): filtered.add(dl) if debug: - prints('Ignoring the drive %s because of a PNP filter on %s' % (dl, pnp_id)) + prints(f'Ignoring the drive {dl} because of a PNP filter on {pnp_id}') elif not drive_is_ok(dl, debug=debug): filtered.add(dl) if debug: @@ -342,7 +339,7 @@ class Device(DeviceConfig, DevicePlugin): if not matches: from pprint import pformat raise DeviceError( - 'Could not detect BSD names for %s. Try rebooting.\nOutput from osx_get_usb_drives():\n%s' % (self.name, pformat(drives))) + f'Could not detect BSD names for {self.name}. Try rebooting.\nOutput from osx_get_usb_drives():\n{pformat(drives)}') pat = re.compile(r'(?P\d+)([a-z]+(?P

\d+)){0,1}') @@ -505,7 +502,7 @@ class Device(DeviceConfig, DevicePlugin): except: ok[node] = False if DEBUG and not ok[node]: - print('\nIgnoring the node: %s as could not read size from: %s' % (node, sz)) + print(f'\nIgnoring the node: {node} as could not read size from: {sz}') devnodes.append(node) diff --git a/src/calibre/devices/usbms/deviceconfig.py b/src/calibre/devices/usbms/deviceconfig.py index 0f61f7dc47..3f61d7cd75 100644 --- a/src/calibre/devices/usbms/deviceconfig.py +++ b/src/calibre/devices/usbms/deviceconfig.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - __license__ = 'GPL 3' __copyright__ = '2009, John Schember ' __docformat__ = 'restructuredtext en' diff --git a/src/calibre/devices/usbms/driver.py b/src/calibre/devices/usbms/driver.py index 182ded099f..ba4c10ce15 100644 --- a/src/calibre/devices/usbms/driver.py +++ b/src/calibre/devices/usbms/driver.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - __license__ = 'GPL v3' __copyright__ = '2009, John Schember ' __docformat__ = 'restructuredtext en' diff --git a/src/calibre/devices/usbms/hal.py b/src/calibre/devices/usbms/hal.py index 68cd4204b3..1478f3b904 100644 --- a/src/calibre/devices/usbms/hal.py +++ b/src/calibre/devices/usbms/hal.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2021, Kovid Goyal import time diff --git a/src/calibre/devices/user_defined/driver.py b/src/calibre/devices/user_defined/driver.py index fcaf24364d..8b4a75dd4f 100644 --- a/src/calibre/devices/user_defined/driver.py +++ b/src/calibre/devices/user_defined/driver.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - __license__ = 'GPL v3' __copyright__ = '2009, Kovid Goyal ' __docformat__ = 'restructuredtext en' diff --git a/src/calibre/devices/utils.py b/src/calibre/devices/utils.py index d0543174cd..77f31cfa8b 100644 --- a/src/calibre/devices/utils.py +++ b/src/calibre/devices/utils.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:fdm=marker:ai __license__ = 'GPL v3' diff --git a/src/calibre/devices/winusb.py b/src/calibre/devices/winusb.py index e00531f1d2..bfec24fb2b 100644 --- a/src/calibre/devices/winusb.py +++ b/src/calibre/devices/winusb.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2016, Kovid Goyal @@ -49,7 +48,7 @@ class GUID(Structure): self.data4[7] = b8 def __str__(self): - return "{%08x-%04x-%04x-%s-%s}" % ( + return "{{{:08x}-{:04x}-{:04x}-{}-{}}}".format( self.data1, self.data2, self.data3, @@ -113,7 +112,7 @@ class SP_DEVINFO_DATA(Structure): ] def __str__(self): - return "ClassGuid:%s DevInst:%s" % (self.ClassGuid, self.DevInst) + return f"ClassGuid:{self.ClassGuid} DevInst:{self.DevInst}" PSP_DEVINFO_DATA = POINTER(SP_DEVINFO_DATA) @@ -128,7 +127,7 @@ class SP_DEVICE_INTERFACE_DATA(Structure): ] def __str__(self): - return "InterfaceClassGuid:%s Flags:%s" % (self.InterfaceClassGuid, self.Flags) + return f"InterfaceClassGuid:{self.InterfaceClassGuid} Flags:{self.Flags}" ANYSIZE_ARRAY = 1 @@ -697,7 +696,7 @@ class USBDevice(_USBDevice): if x is None: return 'None' return '0x%x' % x - return 'USBDevice(vendor_id=%s product_id=%s bcd=%s devid=%s devinst=%s)' % ( + return 'USBDevice(vendor_id={} product_id={} bcd={} devid={} devinst={})'.format( r(self.vendor_id), r(self.product_id), r(self.bcd), self.devid, self.devinst) @@ -782,10 +781,10 @@ def get_drive_letters_for_device_single(usbdev, storage_number_map, debug=False) storage_number = get_storage_number(devpath) except OSError as err: if debug: - prints('Failed to get storage number for: %s with error: %s' % (devid, as_unicode(err))) + prints(f'Failed to get storage number for: {devid} with error: {as_unicode(err)}') continue if debug: - prints('Storage number for %s: %s' % (devid, storage_number)) + prints(f'Storage number for {devid}: {storage_number}') if storage_number: partitions = storage_number_map.get(storage_number[:2]) drive_letters = [] @@ -803,7 +802,7 @@ def get_drive_letters_for_device_single(usbdev, storage_number_map, debug=False) ans['readonly_drives'].add(dl) except OSError as err: if debug: - prints('Failed to get readonly status for drive: %s with error: %s' % (dl, as_unicode(err))) + prints(f'Failed to get readonly status for drive: {dl} with error: {as_unicode(err)}') return ans @@ -820,7 +819,7 @@ def get_storage_number_map(drive_types=(DRIVE_REMOVABLE, DRIVE_FIXED), debug=Fal ans[sn[:2]].append((sn[2], letter)) except OSError as err: if debug: - prints('Failed to get storage number for drive: %s with error: %s' % (letter, as_unicode(err))) + prints(f'Failed to get storage number for drive: {letter} with error: {as_unicode(err)}') continue for val in itervalues(ans): val.sort(key=itemgetter(0)) @@ -838,14 +837,14 @@ def get_storage_number_map_alt(debug=False): GetVolumeNameForVolumeMountPoint(devpath, wbuf, len(wbuf)) except OSError as err: if debug: - prints('Failed to get volume id for drive: %s with error: %s' % (devpath, as_unicode(err))) + prints(f'Failed to get volume id for drive: {devpath} with error: {as_unicode(err)}') continue vname = wbuf.value try: wbuf, names = get_volume_pathnames(vname, buf=wbuf) except OSError as err: if debug: - prints('Failed to get mountpoints for volume %s with error: %s' % (devpath, as_unicode(err))) + prints(f'Failed to get mountpoints for volume {devpath} with error: {as_unicode(err)}') continue for name in names: name = name.upper() @@ -853,14 +852,14 @@ def get_storage_number_map_alt(debug=False): break else: if debug: - prints('Ignoring volume %s as it has no assigned drive letter. Mountpoints: %s' % (devpath, names)) + prints(f'Ignoring volume {devpath} as it has no assigned drive letter. Mountpoints: {names}') continue try: sn = get_storage_number('\\\\.\\' + name[0] + ':') ans[sn[:2]].append((sn[2], name[0])) except OSError as err: if debug: - prints('Failed to get storage number for drive: %s with error: %s' % (name[0], as_unicode(err))) + prints(f'Failed to get storage number for drive: {name[0]} with error: {as_unicode(err)}') continue for val in itervalues(ans): val.sort(key=itemgetter(0)) @@ -1007,7 +1006,7 @@ def develop(): # {{{ connected, usbdev = dev.is_usb_connected(usb_devices, debug=True) if connected: print('\n') - print('Potentially connected device: %s at %s' % (dev.get_gui_name(), usbdev)) + print(f'Potentially connected device: {dev.get_gui_name()} at {usbdev}') print() print('Drives for this device:') data = get_drive_letters_for_device(usbdev, debug=True) @@ -1024,7 +1023,7 @@ def drives_for(vendor_id, product_id=None): pprint(usb_devices) for usbdev in usb_devices: if usbdev.vendor_id == vendor_id and (product_id is None or usbdev.product_id == product_id): - print('Drives for: {}'.format(usbdev)) + print(f'Drives for: {usbdev}') pprint(get_drive_letters_for_device(usbdev, debug=True)) print('USB info:', get_usb_info(usbdev, debug=True)) diff --git a/src/calibre/ebooks/BeautifulSoup.py b/src/calibre/ebooks/BeautifulSoup.py index dad2ec5c3b..c4f7e1a24d 100644 --- a/src/calibre/ebooks/BeautifulSoup.py +++ b/src/calibre/ebooks/BeautifulSoup.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2019, Kovid Goyal diff --git a/src/calibre/ebooks/azw4/reader.py b/src/calibre/ebooks/azw4/reader.py index c4a0463566..f16e98baab 100644 --- a/src/calibre/ebooks/azw4/reader.py +++ b/src/calibre/ebooks/azw4/reader.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - ''' Read content from azw4 file. diff --git a/src/calibre/ebooks/chardet.py b/src/calibre/ebooks/chardet.py index ced93f410b..53fe6c5108 100644 --- a/src/calibre/ebooks/chardet.py +++ b/src/calibre/ebooks/chardet.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/chm/metadata.py b/src/calibre/ebooks/chm/metadata.py index 712edb9228..502a5a0f96 100644 --- a/src/calibre/ebooks/chm/metadata.py +++ b/src/calibre/ebooks/chm/metadata.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' @@ -80,7 +79,7 @@ def _get_comments(soup): date = date.replace('\u00a9', '').strip() # and pages often comes as '(\d+ pages)' pages = re.search(r'\d+', pages).group(0) - return 'Published %s, %s pages.' % (date, pages) + return f'Published {date}, {pages} pages.' except: pass return None diff --git a/src/calibre/ebooks/compression/__init__.py b/src/calibre/ebooks/compression/__init__.py index c8ab3b77a5..e21b6518f9 100644 --- a/src/calibre/ebooks/compression/__init__.py +++ b/src/calibre/ebooks/compression/__init__.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - __license__ = 'GPL 3' __copyright__ = '2009, John Schember ' __docformat__ = 'restructuredtext en' diff --git a/src/calibre/ebooks/compression/palmdoc.py b/src/calibre/ebooks/compression/palmdoc.py index 9b607cb8e7..9d4bfac303 100644 --- a/src/calibre/ebooks/compression/palmdoc.py +++ b/src/calibre/ebooks/compression/palmdoc.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/compression/tcr.py b/src/calibre/ebooks/compression/tcr.py index d4ec4cc8be..aa72bec8a9 100644 --- a/src/calibre/ebooks/compression/tcr.py +++ b/src/calibre/ebooks/compression/tcr.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - __license__ = 'GPL 3' __copyright__ = '2009, John Schember ' __docformat__ = 'restructuredtext en' diff --git a/src/calibre/ebooks/constants.py b/src/calibre/ebooks/constants.py index 8cc5d43e27..292e1f24e5 100644 --- a/src/calibre/ebooks/constants.py +++ b/src/calibre/ebooks/constants.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/conversion/__init__.py b/src/calibre/ebooks/conversion/__init__.py index d48f093caf..4d619cc5dd 100644 --- a/src/calibre/ebooks/conversion/__init__.py +++ b/src/calibre/ebooks/conversion/__init__.py @@ -1,6 +1,3 @@ -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai - - __license__ = 'GPL v3' __copyright__ = '2011, Kovid Goyal ' __docformat__ = 'restructuredtext en' diff --git a/src/calibre/ebooks/conversion/config.py b/src/calibre/ebooks/conversion/config.py index e09a369dcc..8d0aba9aea 100644 --- a/src/calibre/ebooks/conversion/config.py +++ b/src/calibre/ebooks/conversion/config.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/conversion/plugins/__init__.py b/src/calibre/ebooks/conversion/plugins/__init__.py index 6b2910c3df..c2a96b7708 100644 --- a/src/calibre/ebooks/conversion/plugins/__init__.py +++ b/src/calibre/ebooks/conversion/plugins/__init__.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/conversion/plugins/azw4_input.py b/src/calibre/ebooks/conversion/plugins/azw4_input.py index 505e41b3fe..0658b01d10 100644 --- a/src/calibre/ebooks/conversion/plugins/azw4_input.py +++ b/src/calibre/ebooks/conversion/plugins/azw4_input.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - __license__ = 'GPL v3' __copyright__ = '2011, John Schember ' __docformat__ = 'restructuredtext en' diff --git a/src/calibre/ebooks/conversion/plugins/comic_input.py b/src/calibre/ebooks/conversion/plugins/comic_input.py index 20a96316b6..c4c3ceed82 100644 --- a/src/calibre/ebooks/conversion/plugins/comic_input.py +++ b/src/calibre/ebooks/conversion/plugins/comic_input.py @@ -228,7 +228,7 @@ class ComicInput(InputFormatPlugin): if self.for_viewer: wrapper_page_href = href(wrappers[0]) for i in range(num_pages_per_comic[0]): - toc.add_item('{}#page_{}'.format(wrapper_page_href, i+1), None, + toc.add_item(f'{wrapper_page_href}#page_{i+1}', None, _('Page')+' %d'%(i+1), play_order=i) else: @@ -246,7 +246,7 @@ class ComicInput(InputFormatPlugin): if self.for_viewer: wrapper_page_href = href(wrappers[0]) for i in range(num_pages): - stoc.add_item('{}#page_{}'.format(wrapper_page_href, i+1), None, + stoc.add_item(f'{wrapper_page_href}#page_{i+1}', None, _('Page')+' %d'%(i+1), play_order=po) po += 1 else: @@ -293,32 +293,32 @@ class ComicInput(InputFormatPlugin): from calibre.ebooks.oeb.base import XHTML_NS def page(pnum, src): - return ''.format(pnum + 1, os.path.basename(src)) + return f'' pages = '\n'.join(page(i, src) for i, src in enumerate(pages)) base = os.path.dirname(pages[0]) wrapper = ''' - + - %s + {} - ''' % (XHTML_NS, pages) + '''.format(XHTML_NS, pages) path = os.path.join(base, cdir, 'wrapper.xhtml') with open(path, 'wb') as f: f.write(wrapper.encode('utf-8')) diff --git a/src/calibre/ebooks/conversion/plugins/djvu_input.py b/src/calibre/ebooks/conversion/plugins/djvu_input.py index 9d2d5c6b97..dd38176da4 100644 --- a/src/calibre/ebooks/conversion/plugins/djvu_input.py +++ b/src/calibre/ebooks/conversion/plugins/djvu_input.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - __license__ = 'GPL 3' __copyright__ = '2011, Anthon van der Neut ' __docformat__ = 'restructuredtext en' diff --git a/src/calibre/ebooks/conversion/plugins/docx_input.py b/src/calibre/ebooks/conversion/plugins/docx_input.py index e69cef7407..ad5bebd4fb 100644 --- a/src/calibre/ebooks/conversion/plugins/docx_input.py +++ b/src/calibre/ebooks/conversion/plugins/docx_input.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/conversion/plugins/docx_output.py b/src/calibre/ebooks/conversion/plugins/docx_output.py index 4c76b86ff2..7ed0ccff6d 100644 --- a/src/calibre/ebooks/conversion/plugins/docx_output.py +++ b/src/calibre/ebooks/conversion/plugins/docx_output.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/conversion/plugins/epub_output.py b/src/calibre/ebooks/conversion/plugins/epub_output.py index aef9448b72..a7f20f7e3b 100644 --- a/src/calibre/ebooks/conversion/plugins/epub_output.py +++ b/src/calibre/ebooks/conversion/plugins/epub_output.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/conversion/plugins/fb2_output.py b/src/calibre/ebooks/conversion/plugins/fb2_output.py index 2c99437846..eb9bf110dd 100644 --- a/src/calibre/ebooks/conversion/plugins/fb2_output.py +++ b/src/calibre/ebooks/conversion/plugins/fb2_output.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - __license__ = 'GPL 3' __copyright__ = '2009, John Schember ' __docformat__ = 'restructuredtext en' diff --git a/src/calibre/ebooks/conversion/plugins/html_input.py b/src/calibre/ebooks/conversion/plugins/html_input.py index a75809e120..6f9c2084ea 100644 --- a/src/calibre/ebooks/conversion/plugins/html_input.py +++ b/src/calibre/ebooks/conversion/plugins/html_input.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/conversion/plugins/htmlz_input.py b/src/calibre/ebooks/conversion/plugins/htmlz_input.py index c67fcbb153..faa581d7bc 100644 --- a/src/calibre/ebooks/conversion/plugins/htmlz_input.py +++ b/src/calibre/ebooks/conversion/plugins/htmlz_input.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - __license__ = 'GPL 3' __copyright__ = '2011, John Schember ' __docformat__ = 'restructuredtext en' diff --git a/src/calibre/ebooks/conversion/plugins/htmlz_output.py b/src/calibre/ebooks/conversion/plugins/htmlz_output.py index c206062ec4..024d1cc135 100644 --- a/src/calibre/ebooks/conversion/plugins/htmlz_output.py +++ b/src/calibre/ebooks/conversion/plugins/htmlz_output.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - __license__ = 'GPL 3' __copyright__ = '2011, John Schember ' __docformat__ = 'restructuredtext en' diff --git a/src/calibre/ebooks/conversion/plugins/lit_input.py b/src/calibre/ebooks/conversion/plugins/lit_input.py index fea2ce265d..8c5fe7d58f 100644 --- a/src/calibre/ebooks/conversion/plugins/lit_input.py +++ b/src/calibre/ebooks/conversion/plugins/lit_input.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/conversion/plugins/lit_output.py b/src/calibre/ebooks/conversion/plugins/lit_output.py index 46e3c22e13..cfb72a6037 100644 --- a/src/calibre/ebooks/conversion/plugins/lit_output.py +++ b/src/calibre/ebooks/conversion/plugins/lit_output.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/conversion/plugins/lrf_input.py b/src/calibre/ebooks/conversion/plugins/lrf_input.py index ed2f80ff25..bd2ab4ecd7 100644 --- a/src/calibre/ebooks/conversion/plugins/lrf_input.py +++ b/src/calibre/ebooks/conversion/plugins/lrf_input.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/conversion/plugins/lrf_output.py b/src/calibre/ebooks/conversion/plugins/lrf_output.py index 718db0a55a..bfbd07aee4 100644 --- a/src/calibre/ebooks/conversion/plugins/lrf_output.py +++ b/src/calibre/ebooks/conversion/plugins/lrf_output.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/conversion/plugins/mobi_output.py b/src/calibre/ebooks/conversion/plugins/mobi_output.py index 425b992fcd..c31350b052 100644 --- a/src/calibre/ebooks/conversion/plugins/mobi_output.py +++ b/src/calibre/ebooks/conversion/plugins/mobi_output.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/conversion/plugins/pdb_input.py b/src/calibre/ebooks/conversion/plugins/pdb_input.py index 3eafb90a66..b661826058 100644 --- a/src/calibre/ebooks/conversion/plugins/pdb_input.py +++ b/src/calibre/ebooks/conversion/plugins/pdb_input.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - __license__ = 'GPL v3' __copyright__ = '2009, John Schember ' __docformat__ = 'restructuredtext en' @@ -30,7 +27,7 @@ class PDBInput(InputFormatPlugin): raise PDBError('No reader available for format within container.\n Identity is %s. Book type is %s' % (header.ident, IDENTITY_TO_NAME.get(header.ident, _('Unknown')))) - log.debug('Detected ebook format as: %s with identity: %s' % (IDENTITY_TO_NAME[header.ident], header.ident)) + log.debug(f'Detected ebook format as: {IDENTITY_TO_NAME[header.ident]} with identity: {header.ident}') reader = Reader(header, stream, log, options) opf = reader.extract_content(os.getcwd()) diff --git a/src/calibre/ebooks/conversion/plugins/pdb_output.py b/src/calibre/ebooks/conversion/plugins/pdb_output.py index 9e41476798..ceb6c8fc60 100644 --- a/src/calibre/ebooks/conversion/plugins/pdb_output.py +++ b/src/calibre/ebooks/conversion/plugins/pdb_output.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - __license__ = 'GPL 3' __copyright__ = '2009, John Schember ' __docformat__ = 'restructuredtext en' diff --git a/src/calibre/ebooks/conversion/plugins/pdf_input.py b/src/calibre/ebooks/conversion/plugins/pdf_input.py index 72f76e18dc..cce1dd21ac 100644 --- a/src/calibre/ebooks/conversion/plugins/pdf_input.py +++ b/src/calibre/ebooks/conversion/plugins/pdf_input.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - __license__ = 'GPL 3' __copyright__ = '2009, John Schember ' __docformat__ = 'restructuredtext en' diff --git a/src/calibre/ebooks/conversion/plugins/pdf_output.py b/src/calibre/ebooks/conversion/plugins/pdf_output.py index d27a9da214..66db84a0b3 100644 --- a/src/calibre/ebooks/conversion/plugins/pdf_output.py +++ b/src/calibre/ebooks/conversion/plugins/pdf_output.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - __license__ = 'GPL 3' __copyright__ = '2012, Kovid Goyal ' __docformat__ = 'restructuredtext en' diff --git a/src/calibre/ebooks/conversion/plugins/pml_input.py b/src/calibre/ebooks/conversion/plugins/pml_input.py index 2d7ab50f66..8aa08d4e77 100644 --- a/src/calibre/ebooks/conversion/plugins/pml_input.py +++ b/src/calibre/ebooks/conversion/plugins/pml_input.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - __license__ = 'GPL v3' __copyright__ = '2009, John Schember ' __docformat__ = 'restructuredtext en' diff --git a/src/calibre/ebooks/conversion/plugins/pml_output.py b/src/calibre/ebooks/conversion/plugins/pml_output.py index 5d8619af8a..47eb4cc2d6 100644 --- a/src/calibre/ebooks/conversion/plugins/pml_output.py +++ b/src/calibre/ebooks/conversion/plugins/pml_output.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - __license__ = 'GPL 3' __copyright__ = '2009, John Schember ' __docformat__ = 'restructuredtext en' diff --git a/src/calibre/ebooks/conversion/plugins/rb_input.py b/src/calibre/ebooks/conversion/plugins/rb_input.py index 82c0804811..077a23f08f 100644 --- a/src/calibre/ebooks/conversion/plugins/rb_input.py +++ b/src/calibre/ebooks/conversion/plugins/rb_input.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - __license__ = 'GPL 3' __copyright__ = '2009, John Schember ' __docformat__ = 'restructuredtext en' diff --git a/src/calibre/ebooks/conversion/plugins/rb_output.py b/src/calibre/ebooks/conversion/plugins/rb_output.py index 6a83f0c91d..54dd5655c7 100644 --- a/src/calibre/ebooks/conversion/plugins/rb_output.py +++ b/src/calibre/ebooks/conversion/plugins/rb_output.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - __license__ = 'GPL 3' __copyright__ = '2009, John Schember ' __docformat__ = 'restructuredtext en' diff --git a/src/calibre/ebooks/conversion/plugins/recipe_input.py b/src/calibre/ebooks/conversion/plugins/recipe_input.py index 104a842c08..930b113d89 100644 --- a/src/calibre/ebooks/conversion/plugins/recipe_input.py +++ b/src/calibre/ebooks/conversion/plugins/recipe_input.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/conversion/plugins/rtf_output.py b/src/calibre/ebooks/conversion/plugins/rtf_output.py index e8b40b53e8..c8f211f037 100644 --- a/src/calibre/ebooks/conversion/plugins/rtf_output.py +++ b/src/calibre/ebooks/conversion/plugins/rtf_output.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - __license__ = 'GPL 3' __copyright__ = '2009, John Schember ' __docformat__ = 'restructuredtext en' diff --git a/src/calibre/ebooks/conversion/plugins/snb_input.py b/src/calibre/ebooks/conversion/plugins/snb_input.py index 66ede4cea5..4c1762d8cf 100644 --- a/src/calibre/ebooks/conversion/plugins/snb_input.py +++ b/src/calibre/ebooks/conversion/plugins/snb_input.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - __license__ = 'GPL 3' __copyright__ = '2010, Li Fanxi ' __docformat__ = 'restructuredtext en' diff --git a/src/calibre/ebooks/conversion/plugins/snb_output.py b/src/calibre/ebooks/conversion/plugins/snb_output.py index 0c89fd10f3..2a65e03f50 100644 --- a/src/calibre/ebooks/conversion/plugins/snb_output.py +++ b/src/calibre/ebooks/conversion/plugins/snb_output.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - __license__ = 'GPL 3' __copyright__ = '2010, Li Fanxi ' __docformat__ = 'restructuredtext en' diff --git a/src/calibre/ebooks/conversion/plugins/tcr_input.py b/src/calibre/ebooks/conversion/plugins/tcr_input.py index ed38dbb838..c9674bb443 100644 --- a/src/calibre/ebooks/conversion/plugins/tcr_input.py +++ b/src/calibre/ebooks/conversion/plugins/tcr_input.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - __license__ = 'GPL 3' __copyright__ = '2009, John Schember ' __docformat__ = 'restructuredtext en' diff --git a/src/calibre/ebooks/conversion/plugins/tcr_output.py b/src/calibre/ebooks/conversion/plugins/tcr_output.py index a697966fc9..5edc87ebcc 100644 --- a/src/calibre/ebooks/conversion/plugins/tcr_output.py +++ b/src/calibre/ebooks/conversion/plugins/tcr_output.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - __license__ = 'GPL 3' __copyright__ = '2009, John Schember ' __docformat__ = 'restructuredtext en' diff --git a/src/calibre/ebooks/conversion/plugins/txt_input.py b/src/calibre/ebooks/conversion/plugins/txt_input.py index 2d35235431..a28f58e405 100644 --- a/src/calibre/ebooks/conversion/plugins/txt_input.py +++ b/src/calibre/ebooks/conversion/plugins/txt_input.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - __license__ = 'GPL 3' __copyright__ = '2009, John Schember ' __docformat__ = 'restructuredtext en' @@ -91,7 +88,7 @@ class TXTInput(InputFormatPlugin): 'of the standard Markdown format. The extensions enabled by default: %default.\n' 'To learn more about Markdown extensions, see {}\n' 'This should be a comma separated list of extensions to enable:\n' - ).format('https://python-markdown.github.io/extensions/') + '\n'.join('* %s: %s' % (k, MD_EXTENSIONS[k]) for k in sorted(MD_EXTENSIONS))), + ).format('https://python-markdown.github.io/extensions/') + '\n'.join(f'* {k}: {MD_EXTENSIONS[k]}' for k in sorted(MD_EXTENSIONS))), } def shift_file(self, fname, data): @@ -100,7 +97,7 @@ class TXTInput(InputFormatPlugin): c = 0 while os.path.exists(candidate): c += 1 - candidate = os.path.join(self.output_dir, '{}-{}{}'.format(name, c, ext)) + candidate = os.path.join(self.output_dir, f'{name}-{c}{ext}') ans = candidate with open(ans, 'wb') as f: f.write(data) @@ -204,7 +201,7 @@ class TXTInput(InputFormatPlugin): # gb2312 instead of gbk. gbk is a superset of gb2312, anyway. det_encoding = 'gbk' ienc = det_encoding - log.debug('Detected input encoding as %s with a confidence of %s%%' % (ienc, confidence * 100)) + log.debug(f'Detected input encoding as {ienc} with a confidence of {confidence * 100}%') if not ienc: ienc = 'utf-8' log.debug('No input encoding specified and could not auto detect using %s' % ienc) diff --git a/src/calibre/ebooks/conversion/plugins/txt_output.py b/src/calibre/ebooks/conversion/plugins/txt_output.py index cd62a0d80a..65997b7f56 100644 --- a/src/calibre/ebooks/conversion/plugins/txt_output.py +++ b/src/calibre/ebooks/conversion/plugins/txt_output.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - __license__ = 'GPL 3' __copyright__ = '2009, John Schember ' __docformat__ = 'restructuredtext en' diff --git a/src/calibre/ebooks/conversion/plumber.py b/src/calibre/ebooks/conversion/plumber.py index 53e428425f..e4fcc037e6 100644 --- a/src/calibre/ebooks/conversion/plumber.py +++ b/src/calibre/ebooks/conversion/plumber.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - __license__ = 'GPL 3' __copyright__ = '2009, Kovid Goyal ' __docformat__ = 'restructuredtext en' diff --git a/src/calibre/ebooks/conversion/preprocess.py b/src/calibre/ebooks/conversion/preprocess.py index ba5ee0da7f..a7782eae65 100644 --- a/src/calibre/ebooks/conversion/preprocess.py +++ b/src/calibre/ebooks/conversion/preprocess.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' @@ -351,7 +350,7 @@ def accent_regex(accent_maps, letter_before=False): accent_cat.add(accent) k, v = accent_maps[accent].split(':', 1) if len(k) != len(v): - raise ValueError('Invalid mapping for: {} -> {}'.format(k, v)) + raise ValueError(f'Invalid mapping for: {k} -> {v}') accent_maps[accent] = lmap = dict(zip(k, v)) letters |= set(lmap) diff --git a/src/calibre/ebooks/conversion/search_replace.py b/src/calibre/ebooks/conversion/search_replace.py index 62d180cc26..ea747c3bff 100644 --- a/src/calibre/ebooks/conversion/search_replace.py +++ b/src/calibre/ebooks/conversion/search_replace.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2017, Kovid Goyal diff --git a/src/calibre/ebooks/conversion/utils.py b/src/calibre/ebooks/conversion/utils.py index 2ec154a951..02c90a735b 100644 --- a/src/calibre/ebooks/conversion/utils.py +++ b/src/calibre/ebooks/conversion/utils.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' @@ -445,7 +444,7 @@ class HeuristicProcessor: html = re.sub('/]*/>', '

', html) # Get rid of empty span, bold, font, em, & italics tags fmt_tags = 'font|[ibu]|em|strong' - open_fmt_pat, close_fmt_pat = r'<(?:{})(?:\s[^>]*)?>'.format(fmt_tags), ''.format(fmt_tags) + open_fmt_pat, close_fmt_pat = fr'<(?:{fmt_tags})(?:\s[^>]*)?>', f'' for i in range(2): html = re.sub(r"\s*]*>\s*(]*>\s*){0,2}\s*\s*", " ", html) html = re.sub( diff --git a/src/calibre/ebooks/covers.py b/src/calibre/ebooks/covers.py index f81120c9d5..b673a54ac1 100644 --- a/src/calibre/ebooks/covers.py +++ b/src/calibre/ebooks/covers.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' @@ -603,7 +602,7 @@ def generate_cover(mi, prefs=None, as_qimage=False): p.setPen(color) block.draw(p) p.end() - img.setText('Generated cover', '%s %s' % (__appname__, __version__)) + img.setText('Generated cover', f'{__appname__} {__version__}') if as_qimage: return img return pixmap_to_data(img) @@ -679,7 +678,7 @@ def calibre_cover2(title, author_string='', series_string='', prefs=None, as_qim p.setPen(color) block.draw(p) p.end() - img.setText('Generated cover', '%s %s' % (__appname__, __version__)) + img.setText('Generated cover', f'{__appname__} {__version__}') if as_qimage: return img return pixmap_to_data(img) diff --git a/src/calibre/ebooks/css_transform_rules.py b/src/calibre/ebooks/css_transform_rules.py index 8efb390bd7..8b129a5cb2 100644 --- a/src/calibre/ebooks/css_transform_rules.py +++ b/src/calibre/ebooks/css_transform_rules.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2016, Kovid Goyal @@ -342,7 +341,7 @@ def export_rules(serialized_rules): lines = [] for rule in serialized_rules: lines.extend('# ' + l for l in rule_to_text(rule).splitlines()) - lines.extend('%s: %s' % (k, v.replace('\n', ' ')) for k, v in iteritems(rule) if k in allowed_keys) + lines.extend('{}: {}'.format(k, v.replace('\n', ' ')) for k, v in iteritems(rule) if k in allowed_keys) lines.append('') return '\n'.join(lines).encode('utf-8') diff --git a/src/calibre/ebooks/djvu/djvu.py b/src/calibre/ebooks/djvu/djvu.py index 2b9f247232..967338ac1b 100644 --- a/src/calibre/ebooks/djvu/djvu.py +++ b/src/calibre/ebooks/djvu/djvu.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# coding: utf-8 __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/djvu/djvubzzdec.py b/src/calibre/ebooks/djvu/djvubzzdec.py index fa19326a6b..f5a0e9c06a 100644 --- a/src/calibre/ebooks/djvu/djvubzzdec.py +++ b/src/calibre/ebooks/djvu/djvubzzdec.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# coding: utf-8 __license__ = 'GPL v3' __copyright__ = '2011, Anthon van der Neut ' diff --git a/src/calibre/ebooks/docx/__init__.py b/src/calibre/ebooks/docx/__init__.py index 5572220196..fd10297f12 100644 --- a/src/calibre/ebooks/docx/__init__.py +++ b/src/calibre/ebooks/docx/__init__.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/docx/block_styles.py b/src/calibre/ebooks/docx/block_styles.py index 5280133bfc..1bd6e856c5 100644 --- a/src/calibre/ebooks/docx/block_styles.py +++ b/src/calibre/ebooks/docx/block_styles.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' @@ -167,12 +166,12 @@ def read_indent(parent, dest, XPath, get): l, lc = get(indent, 'w:left'), get(indent, 'w:leftChars') pl = simple_float(lc, 0.01) if lc is not None else simple_float(l, 0.05) if l is not None else None if pl is not None: - padding_left = '%.3g%s' % (pl, 'em' if lc is not None else 'pt') + padding_left = '{:.3g}{}'.format(pl, 'em' if lc is not None else 'pt') r, rc = get(indent, 'w:right'), get(indent, 'w:rightChars') pr = simple_float(rc, 0.01) if rc is not None else simple_float(r, 0.05) if r is not None else None if pr is not None: - padding_right = '%.3g%s' % (pr, 'em' if rc is not None else 'pt') + padding_right = '{:.3g}{}'.format(pr, 'em' if rc is not None else 'pt') h, hc = get(indent, 'w:hanging'), get(indent, 'w:hangingChars') fl, flc = get(indent, 'w:firstLine'), get(indent, 'w:firstLineChars') @@ -181,7 +180,7 @@ def read_indent(parent, dest, XPath, get): ti = (simple_float(hc, 0.01) if hc is not None else simple_float(h, 0.05) if h is not None else simple_float(flc, 0.01) if flc is not None else simple_float(fl, 0.05) if fl is not None else None) if ti is not None: - text_indent = '%.3g%s' % (ti, 'em' if hc is not None or (h is None and flc is not None) else 'pt') + text_indent = '{:.3g}{}'.format(ti, 'em' if hc is not None or (h is None and flc is not None) else 'pt') setattr(dest, 'margin_left', padding_left) setattr(dest, 'margin_right', padding_right) @@ -209,18 +208,18 @@ def read_spacing(parent, dest, XPath, get): a, al, aa = get(s, 'w:after'), get(s, 'w:afterLines'), get(s, 'w:afterAutospacing') pb = None if aa in {'on', '1', 'true'} else simple_float(al, 0.02) if al is not None else simple_float(a, 0.05) if a is not None else None if pb is not None: - padding_bottom = '%.3g%s' % (pb, 'ex' if al is not None else 'pt') + padding_bottom = '{:.3g}{}'.format(pb, 'ex' if al is not None else 'pt') b, bl, bb = get(s, 'w:before'), get(s, 'w:beforeLines'), get(s, 'w:beforeAutospacing') pt = None if bb in {'on', '1', 'true'} else simple_float(bl, 0.02) if bl is not None else simple_float(b, 0.05) if b is not None else None if pt is not None: - padding_top = '%.3g%s' % (pt, 'ex' if bl is not None else 'pt') + padding_top = '{:.3g}{}'.format(pt, 'ex' if bl is not None else 'pt') l, lr = get(s, 'w:line'), get(s, 'w:lineRule', 'auto') if l is not None: lh = simple_float(l, 0.05) if lr in {'exact', 'atLeast'} else simple_float(l, 1/240.0) if lh is not None: - line_height = '%.3g%s' % (lh, 'pt' if lr in {'exact', 'atLeast'} else '') + line_height = '{:.3g}{}'.format(lh, 'pt' if lr in {'exact', 'atLeast'} else '') setattr(dest, 'margin_top', padding_top) setattr(dest, 'margin_bottom', padding_bottom) @@ -453,13 +452,13 @@ class ParagraphStyle: def clear_borders(self): for edge in border_edges[:-1]: for prop in ('width', 'color', 'style'): - setattr(self, 'border_%s_%s' % (edge, prop), inherit) + setattr(self, f'border_{edge}_{prop}', inherit) def clone_border_styles(self): style = ParagraphStyle(self.namespace) for edge in border_edges[:-1]: for prop in ('width', 'color', 'style'): - attr = 'border_%s_%s' % (edge, prop) + attr = f'border_{edge}_{prop}' setattr(style, attr, getattr(self, attr)) return style diff --git a/src/calibre/ebooks/docx/char_styles.py b/src/calibre/ebooks/docx/char_styles.py index 4b9ade9af2..025a080f11 100644 --- a/src/calibre/ebooks/docx/char_styles.py +++ b/src/calibre/ebooks/docx/char_styles.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/docx/cleanup.py b/src/calibre/ebooks/docx/cleanup.py index 1231e693ec..48e26ba87f 100644 --- a/src/calibre/ebooks/docx/cleanup.py +++ b/src/calibre/ebooks/docx/cleanup.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/docx/container.py b/src/calibre/ebooks/docx/container.py index d2d40453f0..c73ad84a21 100644 --- a/src/calibre/ebooks/docx/container.py +++ b/src/calibre/ebooks/docx/container.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/docx/dump.py b/src/calibre/ebooks/docx/dump.py index c4191057bb..e64c4d2136 100644 --- a/src/calibre/ebooks/docx/dump.py +++ b/src/calibre/ebooks/docx/dump.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/docx/fields.py b/src/calibre/ebooks/docx/fields.py index d33ff8e951..a1da9b3fa5 100644 --- a/src/calibre/ebooks/docx/fields.py +++ b/src/calibre/ebooks/docx/fields.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' @@ -195,7 +194,7 @@ class Fields: for runs in self.get_runs(field): self.hyperlink_fields.append(({'anchor':dest}, runs)) else: - log.warn('Unsupported reference field (%s), ignoring: %r' % (field.name, ref)) + log.warn(f'Unsupported reference field ({field.name}), ignoring: {ref!r}') parse_noteref = parse_ref diff --git a/src/calibre/ebooks/docx/fonts.py b/src/calibre/ebooks/docx/fonts.py index 332ded5bb2..951349e521 100644 --- a/src/calibre/ebooks/docx/fonts.py +++ b/src/calibre/ebooks/docx/fonts.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' @@ -154,7 +153,7 @@ class Fonts: name = f.name if variant in f.embedded else f.family_name if is_symbol_font(name): return name - return '"%s", %s' % (name.replace('"', ''), f.css_generic_family) + return '"{}", {}'.format(name.replace('"', ''), f.css_generic_family) def embed_fonts(self, dest_dir, docx): defs = [] @@ -171,7 +170,7 @@ class Fonts: d['font-weight'] = 'bold' if 'Italic' in variant: d['font-style'] = 'italic' - d = ['%s: %s' % (k, v) for k, v in iteritems(d)] + d = [f'{k}: {v}' for k, v in iteritems(d)] d = ';\n\t'.join(d) defs.append('@font-face {\n\t%s\n}\n' % d) return '\n'.join(defs) @@ -189,7 +188,7 @@ class Fonts: if not is_truetype_font(prefix): return None ext = 'otf' if prefix.startswith(b'OTTO') else 'ttf' - fname = ascii_filename('%s - %s.%s' % (name, variant, ext)).replace(' ', '_').replace('&', '_') + fname = ascii_filename(f'{name} - {variant}.{ext}').replace(' ', '_').replace('&', '_') with open(os.path.join(dest_dir, fname), 'wb') as dest: dest.write(prefix) dest.write(raw[32:]) diff --git a/src/calibre/ebooks/docx/footnotes.py b/src/calibre/ebooks/docx/footnotes.py index f0652e471f..2c6b052e8e 100644 --- a/src/calibre/ebooks/docx/footnotes.py +++ b/src/calibre/ebooks/docx/footnotes.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/docx/images.py b/src/calibre/ebooks/docx/images.py index b8605184f8..ac00d1d371 100644 --- a/src/calibre/ebooks/docx/images.py +++ b/src/calibre/ebooks/docx/images.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' @@ -263,7 +262,7 @@ class Images: ans = self.pic_to_img(pic, alt, inline, title) if ans is not None: if style: - ans.set('style', '; '.join('%s: %s' % (k, v) for k, v in iteritems(style))) + ans.set('style', '; '.join(f'{k}: {v}' for k, v in iteritems(style))) yield ans # Now process the floats @@ -274,7 +273,7 @@ class Images: ans = self.pic_to_img(pic, alt, anchor, title) if ans is not None: if style: - ans.set('style', '; '.join('%s: %s' % (k, v) for k, v in iteritems(style))) + ans.set('style', '; '.join(f'{k}: {v}' for k, v in iteritems(style))) yield ans def pict_to_html(self, pict, page): @@ -296,7 +295,7 @@ class Images: style['margin-left'] = '0' if align == 'left' else 'auto' style['margin-right'] = 'auto' if align == 'left' else '0' if style: - hr.set('style', '; '.join(('%s:%s' % (k, v) for k, v in iteritems(style)))) + hr.set('style', '; '.join((f'{k}:{v}' for k, v in iteritems(style)))) yield hr for imagedata in XPath('descendant::v:imagedata[@r:id]')(pict): diff --git a/src/calibre/ebooks/docx/index.py b/src/calibre/ebooks/docx/index.py index 9be71fc7ac..a00b158392 100644 --- a/src/calibre/ebooks/docx/index.py +++ b/src/calibre/ebooks/docx/index.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/docx/lcid.py b/src/calibre/ebooks/docx/lcid.py index 1e365f0321..d8a19868eb 100644 --- a/src/calibre/ebooks/docx/lcid.py +++ b/src/calibre/ebooks/docx/lcid.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/docx/names.py b/src/calibre/ebooks/docx/names.py index f73d7fd1ec..f045efcef6 100644 --- a/src/calibre/ebooks/docx/names.py +++ b/src/calibre/ebooks/docx/names.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' @@ -82,7 +81,7 @@ def barename(x): def XML(x): - return '{%s}%s' % (TRANSITIONAL_NAMESPACES['xml'], x) + return '{{{}}}{}'.format(TRANSITIONAL_NAMESPACES['xml'], x) def generate_anchor(name, existing): @@ -114,12 +113,12 @@ class DOCXNamespace: def is_tag(self, x, q): tag = getattr(x, 'tag', x) ns, name = q.partition(':')[0::2] - return '{%s}%s' % (self.namespaces.get(ns, None), name) == tag + return f'{{{self.namespaces.get(ns, None)}}}{name}' == tag def expand(self, name, sep=':'): ns, tag = name.partition(sep)[::2] if ns and tag: - tag = '{%s}%s' % (self.namespaces[ns], tag) + tag = f'{{{self.namespaces[ns]}}}{tag}' return tag or ns def get(self, x, attr, default=None): diff --git a/src/calibre/ebooks/docx/numbering.py b/src/calibre/ebooks/docx/numbering.py index f5f193544f..42a41d9717 100644 --- a/src/calibre/ebooks/docx/numbering.py +++ b/src/calibre/ebooks/docx/numbering.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/docx/settings.py b/src/calibre/ebooks/docx/settings.py index a98f7cd549..d0a6823947 100644 --- a/src/calibre/ebooks/docx/settings.py +++ b/src/calibre/ebooks/docx/settings.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/docx/styles.py b/src/calibre/ebooks/docx/styles.py index d20b13eeb0..9df8bebd7d 100644 --- a/src/calibre/ebooks/docx/styles.py +++ b/src/calibre/ebooks/docx/styles.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' @@ -256,7 +255,7 @@ class Styles: if is_numbering and not is_section_break: num_id, lvl = direct_formatting.numbering_id, direct_formatting.numbering_level - p.set('calibre_num_id', '%s:%s' % (lvl, num_id)) + p.set('calibre_num_id', f'{lvl}:{num_id}') ps = self.numbering.get_para_style(num_id, lvl) if ps is not None: parent_styles.append(ps) @@ -264,7 +263,7 @@ class Styles: not is_numbering and not is_section_break and linked_style is not None and has_numbering(linked_style.paragraph_style) ): num_id, lvl = linked_style.paragraph_style.numbering_id, linked_style.paragraph_style.numbering_level - p.set('calibre_num_id', '%s:%s' % (lvl, num_id)) + p.set('calibre_num_id', f'{lvl}:{num_id}') is_numbering = True ps = self.numbering.get_para_style(num_id, lvl) if ps is not None: @@ -497,14 +496,14 @@ class Styles: body_color = '' if self.body_color.lower() not in ('currentcolor', 'inherit'): - body_color = 'color: {};'.format(self.body_color) + body_color = f'color: {self.body_color};' prefix = textwrap.dedent(s) % (self.body_font_family, self.body_font_size, body_color) if ef: prefix = ef + '\n' + prefix ans = [] for (cls, css) in sorted(itervalues(self.classes), key=lambda x:x[0]): - b = ('\t%s: %s;' % (k, v) for k, v in iteritems(css)) + b = (f'\t{k}: {v};' for k, v in iteritems(css)) b = '\n'.join(b) - ans.append('.%s {\n%s\n}\n' % (cls, b.rstrip(';'))) + ans.append('.{} {{\n{}\n}}\n'.format(cls, b.rstrip(';'))) return prefix + '\n' + '\n'.join(ans) diff --git a/src/calibre/ebooks/docx/tables.py b/src/calibre/ebooks/docx/tables.py index 45c43151b9..d3574cd217 100644 --- a/src/calibre/ebooks/docx/tables.py +++ b/src/calibre/ebooks/docx/tables.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/docx/theme.py b/src/calibre/ebooks/docx/theme.py index b1c2c15935..dcdb4939ee 100644 --- a/src/calibre/ebooks/docx/theme.py +++ b/src/calibre/ebooks/docx/theme.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/docx/to_html.py b/src/calibre/ebooks/docx/to_html.py index d284bae8c9..50e82a9a0d 100644 --- a/src/calibre/ebooks/docx/to_html.py +++ b/src/calibre/ebooks/docx/to_html.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/docx/toc.py b/src/calibre/ebooks/docx/toc.py index 5d73af07c6..e6fb45d951 100644 --- a/src/calibre/ebooks/docx/toc.py +++ b/src/calibre/ebooks/docx/toc.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/docx/writer/__init__.py b/src/calibre/ebooks/docx/writer/__init__.py index e4102b4b10..0cbf055ec8 100644 --- a/src/calibre/ebooks/docx/writer/__init__.py +++ b/src/calibre/ebooks/docx/writer/__init__.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/docx/writer/container.py b/src/calibre/ebooks/docx/writer/container.py index fcdb9a8a34..2fde66d5bd 100644 --- a/src/calibre/ebooks/docx/writer/container.py +++ b/src/calibre/ebooks/docx/writer/container.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' @@ -54,7 +53,7 @@ def create_skeleton(opts, namespaces=None): namespaces = namespaces or DOCXNamespace().namespaces def w(x): - return '{%s}%s' % (namespaces['w'], x) + return '{{{}}}{}'.format(namespaces['w'], x) dn = {k:v for k, v in iteritems(namespaces) if k in {'w', 'r', 'm', 've', 'o', 'wp', 'w10', 'wne', 'a', 'pic'}} E = ElementMaker(namespace=dn['w'], nsmap=dn) doc = E.document() @@ -97,7 +96,7 @@ def create_skeleton(opts, namespaces=None): def update_doc_props(root, mi, namespace): def setm(name, text=None, ns='dc'): - ans = root.makeelement('{%s}%s' % (namespace.namespaces[ns], name)) + ans = root.makeelement(f'{{{namespace.namespaces[ns]}}}{name}') for child in tuple(root): if child.tag == ans.tag: root.remove(child) @@ -245,7 +244,7 @@ class DOCX: cp = E.coreProperties(E.revision("1"), E.lastModifiedBy('calibre')) ts = utcnow().isoformat(native_string_type('T')).rpartition('.')[0] + 'Z' for x in 'created modified'.split(): - x = cp.makeelement('{%s}%s' % (namespaces['dcterms'], x), **{'{%s}type' % namespaces['xsi']:'dcterms:W3CDTF'}) + x = cp.makeelement('{{{}}}{}'.format(namespaces['dcterms'], x), **{'{%s}type' % namespaces['xsi']:'dcterms:W3CDTF'}) x.text = ts cp.append(x) self.mi = mi diff --git a/src/calibre/ebooks/docx/writer/fonts.py b/src/calibre/ebooks/docx/writer/fonts.py index 838e060af3..de02ad4eec 100644 --- a/src/calibre/ebooks/docx/writer/fonts.py +++ b/src/calibre/ebooks/docx/writer/fonts.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/docx/writer/from_html.py b/src/calibre/ebooks/docx/writer/from_html.py index eb11eb444a..16283c085f 100644 --- a/src/calibre/ebooks/docx/writer/from_html.py +++ b/src/calibre/ebooks/docx/writer/from_html.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/docx/writer/images.py b/src/calibre/ebooks/docx/writer/images.py index 4ae6cbb334..e05dc1e6ea 100644 --- a/src/calibre/ebooks/docx/writer/images.py +++ b/src/calibre/ebooks/docx/writer/images.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/docx/writer/links.py b/src/calibre/ebooks/docx/writer/links.py index 71e5eadf83..46e9368e02 100644 --- a/src/calibre/ebooks/docx/writer/links.py +++ b/src/calibre/ebooks/docx/writer/links.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/docx/writer/lists.py b/src/calibre/ebooks/docx/writer/lists.py index f28ba17781..0859530d55 100644 --- a/src/calibre/ebooks/docx/writer/lists.py +++ b/src/calibre/ebooks/docx/writer/lists.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' @@ -107,7 +106,7 @@ class Level: self.num_fmt = 'bullet' self.lvl_text = '\uf0b7' if list_type == 'disc' else STYLE_MAP[list_type] else: - self.lvl_text = '%{}.'.format(self.ilvl + 1) + self.lvl_text = f'%{self.ilvl + 1}.' self.num_fmt = STYLE_MAP.get(list_type, 'decimal') def __hash__(self): diff --git a/src/calibre/ebooks/docx/writer/styles.py b/src/calibre/ebooks/docx/writer/styles.py index 74018d6087..c91feb180a 100644 --- a/src/calibre/ebooks/docx/writer/styles.py +++ b/src/calibre/ebooks/docx/writer/styles.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' @@ -65,7 +64,7 @@ class CombinedStyle: def serialize(self, styles, normal_style): makeelement = self.namespace.makeelement - w = lambda x: '{%s}%s' % (self.namespace.namespaces['w'], x) + w = lambda x: '{{{}}}{}'.format(self.namespace.namespaces['w'], x) block = makeelement(styles, 'w:style', w_styleId=self.id, w_type='paragraph') makeelement(block, 'w:name', w_val=self.name) makeelement(block, 'w:qFormat') @@ -148,7 +147,7 @@ class DOCXStyle: def __init__(self, namespace): self.namespace = namespace - self.w = lambda x: '{%s}%s' % (namespace.namespaces['w'], x) + self.w = lambda x: '{{{}}}{}'.format(namespace.namespaces['w'], x) self.id = self.name = None self.next_style = None self.calculate_hash() @@ -689,7 +688,7 @@ class StylesManager: self.pure_block_styles = sorted(pure_block_styles, key=block_counts.__getitem__) bnum = len(str(max(1, len(pure_block_styles) - 1))) for i, bs in enumerate(self.pure_block_styles): - bs.id = bs.name = '%0{}d Block'.format(bnum) % i + bs.id = bs.name = f'%0{bnum}d Block' % i bs.seq = i if i == 0: self.normal_pure_block_style = bs @@ -715,7 +714,7 @@ class StylesManager: style.id = style.name = 'Normal' else: if style.outline_level is None: - val = 'Para %0{}d'.format(snum) % i + val = f'Para %0{snum}d' % i else: val = 'Heading %d' % (style.outline_level + 1) heading_styles.append(style) @@ -738,7 +737,7 @@ class StylesManager: rnum = len(str(max(1, len(ds_counts) - 1))) for i, (text_style, count) in enumerate(ds_counts.most_common()): text_style.id = 'Text%d' % i - text_style.name = '%0{}d Text'.format(rnum) % i + text_style.name = f'%0{rnum}d Text' % i text_style.seq = i self.descendant_text_styles = sorted(descendant_style_map, key=attrgetter('seq')) diff --git a/src/calibre/ebooks/docx/writer/tables.py b/src/calibre/ebooks/docx/writer/tables.py index 8141448333..4e95eb6adf 100644 --- a/src/calibre/ebooks/docx/writer/tables.py +++ b/src/calibre/ebooks/docx/writer/tables.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/docx/writer/utils.py b/src/calibre/ebooks/docx/writer/utils.py index a05ea69062..e0ff6d9f66 100644 --- a/src/calibre/ebooks/docx/writer/utils.py +++ b/src/calibre/ebooks/docx/writer/utils.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' @@ -27,7 +26,7 @@ def convert_color(value): return if val.alpha < 0.01: return - return '%02X%02X%02X' % (int(val.red * 255), int(val.green * 255), int(val.blue * 255)) + return f'{int(val.red * 255):02X}{int(val.green * 255):02X}{int(val.blue * 255):02X}' def test_convert_color(return_tests=False): diff --git a/src/calibre/ebooks/epub/cfi/parse.py b/src/calibre/ebooks/epub/cfi/parse.py index 1b6efb6ff0..e348098c11 100644 --- a/src/calibre/ebooks/epub/cfi/parse.py +++ b/src/calibre/ebooks/epub/cfi/parse.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' @@ -22,7 +21,7 @@ class Parser: # calibre used to escape hyphens as well, so recognize them even though # not strictly spec compliant escaped_char = r'\^' + special_char[:-1] + '-]' - chars = r'(?:%s|(?:%s))+' % (unescaped_char, escaped_char) + chars = fr'(?:{unescaped_char}|(?:{escaped_char}))+' chars_no_space = chars.replace('0020', '0021') # No leading zeros allowed for integers integer = r'(?:[1-9][0-9]*)|0' @@ -48,11 +47,11 @@ class Parser: # Text assertion patterns self.ta1_pat = c(r'({0})(?:,({0})){{0,1}}'.format(chars)) self.ta2_pat = c(r',(%s)' % chars) - self.parameters_pat = c(r'(?:;(%s)=((?:%s,?)+))+' % (chars_no_space, chars)) + self.parameters_pat = c(fr'(?:;({chars_no_space})=((?:{chars},?)+))+') self.csv_pat = c(r'(?:(%s),?)+' % chars) # Unescape characters - unescape_pat = c(r'%s(%s)' % (escaped_char[:2], escaped_char[2:])) + unescape_pat = c(fr'{escaped_char[:2]}({escaped_char[2:]})') self.unescape = lambda x: unescape_pat.sub(r'\1', x) def parse_epubcfi(self, raw): diff --git a/src/calibre/ebooks/epub/cfi/tests.py b/src/calibre/ebooks/epub/cfi/tests.py index a2d0b32c24..cc04fb8a4a 100644 --- a/src/calibre/ebooks/epub/cfi/tests.py +++ b/src/calibre/ebooks/epub/cfi/tests.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' @@ -126,7 +125,7 @@ class Tests(unittest.TestCase): test(cfi, body) for i in range(len(body)): - test('/4/{}'.format((i + 1)*2), body[i]) + test(f'/4/{(i + 1)*2}', body[i]) p = body[4] test('/4/999[para05]', p) diff --git a/src/calibre/ebooks/epub/periodical.py b/src/calibre/ebooks/epub/periodical.py index 6efdbe3c3d..8b2a661040 100644 --- a/src/calibre/ebooks/epub/periodical.py +++ b/src/calibre/ebooks/epub/periodical.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/fb2/__init__.py b/src/calibre/ebooks/fb2/__init__.py index c623df2d9c..4e93dd8225 100644 --- a/src/calibre/ebooks/fb2/__init__.py +++ b/src/calibre/ebooks/fb2/__init__.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/fb2/fb2ml.py b/src/calibre/ebooks/fb2/fb2ml.py index f310f68991..78e369eb86 100644 --- a/src/calibre/ebooks/fb2/fb2ml.py +++ b/src/calibre/ebooks/fb2/fb2ml.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - __license__ = 'GPL 3' __copyright__ = '2009, John Schember ' __docformat__ = 'restructuredtext en' @@ -164,7 +161,7 @@ class FB2MLizer: index = '1' if self.oeb_book.metadata.series_index: index = self.oeb_book.metadata.series_index[0] - metadata['sequence'] = '' % (prepare_string_for_xml('%s' % self.oeb_book.metadata.series[0]), index) + metadata['sequence'] = ''.format(prepare_string_for_xml('%s' % self.oeb_book.metadata.series[0]), index) year = publisher = isbn = '' identifiers = self.oeb_book.metadata['identifier'] @@ -205,7 +202,7 @@ class FB2MLizer: metadata['comments'] = '' else: from calibre.utils.html2text import html2text - metadata['comments'] = '

{}

'.format(prepare_string_for_xml(html2text(comments.value).strip())) + metadata['comments'] = f'

{prepare_string_for_xml(html2text(comments.value).strip())}

' # Keep the indentation level of the description the same as the body. header = textwrap.dedent('''\ @@ -333,7 +330,7 @@ class FB2MLizer: # Don't put the encoded image on a single line. step = 72 data = '\n'.join(raw_data[i:i+step] for i in range(0, len(raw_data), step)) - images.append('%s' % (self.image_hrefs[item.href], content_type, data)) + images.append(f'{data}') except Exception as e: self.log.error('Error: Could not include file %s because ' '%s.' % (item.href, e)) diff --git a/src/calibre/ebooks/html/__init__.py b/src/calibre/ebooks/html/__init__.py index d8edc6064a..872a71567f 100644 --- a/src/calibre/ebooks/html/__init__.py +++ b/src/calibre/ebooks/html/__init__.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/html/input.py b/src/calibre/ebooks/html/input.py index 1527883dfc..7b2a78a7f6 100644 --- a/src/calibre/ebooks/html/input.py +++ b/src/calibre/ebooks/html/input.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/html/to_zip.py b/src/calibre/ebooks/html/to_zip.py index b066fd694b..30e3023e77 100644 --- a/src/calibre/ebooks/html/to_zip.py +++ b/src/calibre/ebooks/html/to_zip.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/html_entities.py b/src/calibre/ebooks/html_entities.py index 265ebe10c0..ca2dc2fdf7 100644 --- a/src/calibre/ebooks/html_entities.py +++ b/src/calibre/ebooks/html_entities.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2017, Kovid Goyal @@ -2141,7 +2140,7 @@ if __name__ == '__main__': lines = [] for k in sorted(entities): - lines.append(" '%s': %r," % (k, entities[k])) + lines.append(f" '{k}': {entities[k]!r},") with open(__file__, 'r+b') as f: raw = f.read().decode('utf-8') diff --git a/src/calibre/ebooks/html_transform_rules.py b/src/calibre/ebooks/html_transform_rules.py index 81819b5362..82133fa1ff 100644 --- a/src/calibre/ebooks/html_transform_rules.py +++ b/src/calibre/ebooks/html_transform_rules.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2016, Kovid Goyal @@ -461,7 +460,7 @@ def export_rules(serialized_rules): lines = [] for rule in serialized_rules: lines.extend('# ' + l for l in rule_to_text(rule).splitlines()) - lines.extend('%s: %s' % (k, v.replace('\n', ' ')) for k, v in rule.items() if k in allowed_keys and k != 'actions') + lines.extend('{}: {}'.format(k, v.replace('\n', ' ')) for k, v in rule.items() if k in allowed_keys and k != 'actions') for action in rule.get('actions', ()): lines.append(f"action: {action['type']}: {action.get('data', '')}") lines.append('') diff --git a/src/calibre/ebooks/htmlz/oeb2html.py b/src/calibre/ebooks/htmlz/oeb2html.py index 5d4166d8cf..219a67ce8f 100644 --- a/src/calibre/ebooks/htmlz/oeb2html.py +++ b/src/calibre/ebooks/htmlz/oeb2html.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - __license__ = 'GPL 3' __copyright__ = '2011, John Schember ' __docformat__ = 'restructuredtext en' @@ -86,7 +83,7 @@ class OEB2HTML: if item.media_type in OEB_IMAGES: if item.href not in self.images: ext = os.path.splitext(item.href)[1] - fname = '%s%s' % (len(self.images), ext) + fname = f'{len(self.images)}{ext}' fname = fname.zfill(10) self.images[item.href] = fname if item in oeb_book.spine: @@ -192,10 +189,10 @@ class OEB2HTMLNoCSSizer(OEB2HTML): at = '' for k, v in attribs.items(): k = k.split('}')[-1] - at += ' %s="%s"' % (k, prepare_string_for_xml(v, attribute=True)) + at += f' {k}="{prepare_string_for_xml(v, attribute=True)}"' # Write the tag. - text.append('<%s%s' % (tag, at)) + text.append(f'<{tag}{at}') if tag in SELF_CLOSING_TAGS: text.append(' />') else: @@ -285,7 +282,7 @@ class OEB2HTMLInlineCSSizer(OEB2HTML): at = '' for k, v in attribs.items(): k = k.split('}')[-1] - at += ' %s="%s"' % (k, prepare_string_for_xml(v, attribute=True)) + at += f' {k}="{prepare_string_for_xml(v, attribute=True)}"' # Turn style into strings for putting in the tag. style_t = '' @@ -293,7 +290,7 @@ class OEB2HTMLInlineCSSizer(OEB2HTML): style_t = ' style="%s"' % style_a.replace('"', "'") # Write the tag. - text.append('<%s%s%s' % (tag, at, style_t)) + text.append(f'<{tag}{at}{style_t}') if tag in SELF_CLOSING_TAGS: text.append(' />') else: @@ -378,10 +375,10 @@ class OEB2HTMLClassCSSizer(OEB2HTML): at = '' for k, v in attribs.items(): k = k.split('}')[-1] - at += ' %s="%s"' % (k, prepare_string_for_xml(v, attribute=True)) + at += f' {k}="{prepare_string_for_xml(v, attribute=True)}"' # Write the tag. - text.append('<%s%s' % (tag, at)) + text.append(f'<{tag}{at}') if tag in SELF_CLOSING_TAGS: text.append(' />') else: diff --git a/src/calibre/ebooks/iterator/__init__.py b/src/calibre/ebooks/iterator/__init__.py index c227aeaca5..b5e7183f9f 100644 --- a/src/calibre/ebooks/iterator/__init__.py +++ b/src/calibre/ebooks/iterator/__init__.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/lrf/html/convert_from.py b/src/calibre/ebooks/lrf/html/convert_from.py index 6c087252f0..5748feed44 100644 --- a/src/calibre/ebooks/lrf/html/convert_from.py +++ b/src/calibre/ebooks/lrf/html/convert_from.py @@ -1,4 +1,3 @@ -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2008, Kovid Goyal diff --git a/src/calibre/ebooks/lrf/input.py b/src/calibre/ebooks/lrf/input.py index 3cc0fac2a1..08224595f0 100644 --- a/src/calibre/ebooks/lrf/input.py +++ b/src/calibre/ebooks/lrf/input.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/lrf/objects.py b/src/calibre/ebooks/lrf/objects.py index ae14c33db6..b04689feec 100644 --- a/src/calibre/ebooks/lrf/objects.py +++ b/src/calibre/ebooks/lrf/objects.py @@ -80,7 +80,7 @@ class LRFObject: if h[1] != '' and h[0] != '': setattr(self, h[0], val) else: - raise LRFParseError("Unknown tag in %s: %s" % (self.__class__.__name__, str(tag))) + raise LRFParseError(f"Unknown tag in {self.__class__.__name__}: {str(tag)}") def __iter__(self): yield from range(0) @@ -123,7 +123,7 @@ class LRFContentObject(LRFObject): func, args = action[0], (action[1],) getattr(self, func)(tag, *args) else: - raise LRFParseError("Unknown tag in %s: %s" % (self.__class__.__name__, str(tag))) + raise LRFParseError(f"Unknown tag in {self.__class__.__name__}: {str(tag)}") def __iter__(self): yield from self._contents diff --git a/src/calibre/ebooks/lrf/pylrs/pylrs.py b/src/calibre/ebooks/lrf/pylrs/pylrs.py index 5fa247dd4a..2f011ec3ae 100644 --- a/src/calibre/ebooks/lrf/pylrs/pylrs.py +++ b/src/calibre/ebooks/lrf/pylrs/pylrs.py @@ -1097,7 +1097,7 @@ class LrsStyle(LrsObject, LrsAttributes, LrsContainer): def update(self, settings): for name, value in settings.items(): if name not in self.__class__.validSettings: - raise LrsError("%s not a valid setting for %s" % (name, self.__class__.__name__)) + raise LrsError(f"{name} not a valid setting for {self.__class__.__name__}") self.attrs[name] = value def getLabel(self): diff --git a/src/calibre/ebooks/lrf/tags.py b/src/calibre/ebooks/lrf/tags.py index 0893468c66..13c56fbf51 100644 --- a/src/calibre/ebooks/lrf/tags.py +++ b/src/calibre/ebooks/lrf/tags.py @@ -205,7 +205,7 @@ class Tag: s = "Tag %04X " % self.id if self.name: s += self.name - s += " at %08X, contents: %s" % (self.offset, repr(self.contents)) + s += f" at {self.offset:08X}, contents: {repr(self.contents)}" return s @property diff --git a/src/calibre/ebooks/metadata/__init__.py b/src/calibre/ebooks/metadata/__init__.py index 60af28eaea..5bbc43b0f3 100644 --- a/src/calibre/ebooks/metadata/__init__.py +++ b/src/calibre/ebooks/metadata/__init__.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/metadata/archive.py b/src/calibre/ebooks/metadata/archive.py index 25831ad9b2..37bc601393 100644 --- a/src/calibre/ebooks/metadata/archive.py +++ b/src/calibre/ebooks/metadata/archive.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/metadata/author_mapper.py b/src/calibre/ebooks/metadata/author_mapper.py index efffaa6fc4..e7705b539a 100644 --- a/src/calibre/ebooks/metadata/author_mapper.py +++ b/src/calibre/ebooks/metadata/author_mapper.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2015, Kovid Goyal diff --git a/src/calibre/ebooks/metadata/book/__init__.py b/src/calibre/ebooks/metadata/book/__init__.py index 38ba115c55..6835319590 100644 --- a/src/calibre/ebooks/metadata/book/__init__.py +++ b/src/calibre/ebooks/metadata/book/__init__.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/metadata/book/base.py b/src/calibre/ebooks/metadata/book/base.py index b547d68dc5..1efa47521b 100644 --- a/src/calibre/ebooks/metadata/book/base.py +++ b/src/calibre/ebooks/metadata/book/base.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/metadata/book/formatter.py b/src/calibre/ebooks/metadata/book/formatter.py index 7edba76fb2..5d651f7eef 100644 --- a/src/calibre/ebooks/metadata/book/formatter.py +++ b/src/calibre/ebooks/metadata/book/formatter.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/metadata/book/render.py b/src/calibre/ebooks/metadata/book/render.py index eac13ab426..4dbaf5173f 100644 --- a/src/calibre/ebooks/metadata/book/render.py +++ b/src/calibre/ebooks/metadata/book/render.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' @@ -65,7 +64,7 @@ def search_action_with_data(search_term, value, book_id, field=None, **k): return search_action(search_term, value, field=field, book_id=book_id, **k) -DEFAULT_AUTHOR_LINK = 'search-{}'.format(DEFAULT_AUTHOR_SOURCE) +DEFAULT_AUTHOR_LINK = f'search-{DEFAULT_AUTHOR_SOURCE}' def author_search_href(which, title=None, author=None): @@ -140,8 +139,8 @@ def mi_to_html( ans.append((field, row % (name, val))) else: if heading_position == 'above': - val = '

%s

%s' % (p(name), val) - comment_fields.append('
%s
' % (field.replace('#', '_'), val)) + val = f'

{p(name)}

{val}' + comment_fields.append('
{}
'.format(field.replace('#', '_'), val)) elif metadata['datatype'] == 'rating': val = getattr(mi, field) if val: @@ -158,13 +157,13 @@ def mi_to_html( ans.append((field, row % (name, comments_to_html(val)))) else: if not metadata['is_multiple']: - val = '%s' % ( + val = '{}'.format( search_action(field, val), _('Click to see books with {0}: {1}').format(metadata['name'], a(val)), p(val)) else: all_vals = [v.strip() for v in val.split(metadata['is_multiple']['list_to_ui']) if v.strip()] - links = ['%s' % ( + links = ['{}'.format( search_action(field, x), _('Click to see books with {0}: {1}').format( metadata['name'], a(x)), p(x)) for x in all_vals] val = metadata['is_multiple']['list_to_ui'].join(links) @@ -182,7 +181,7 @@ def mi_to_html( durl = ':::'.join((durl.split(':::'))[2:]) extra = '
%s'%( prepare_string_for_xml(durl)) - link = '%s%s' % (action(scheme, loc=loc), + link = '{}{}'.format(action(scheme, loc=loc), prepare_string_for_xml(path, True), pathstr, extra) ans.append((field, row % (name, link))) elif field == 'formats': @@ -204,7 +203,7 @@ def mi_to_html( elif field == 'identifiers': urls = urls_from_identifiers(mi.identifiers, sort_results=True) links = [ - '%s' % ( + '{}'.format( action('identifier', url=url, name=namel, id_type=id_typ, value=id_val, field='identifiers', book_id=book_id), a(id_typ), a(id_val), p(namel)) for namel, id_typ, id_val, url in urls] @@ -239,13 +238,13 @@ def mi_to_html( if not mi.languages: continue names = filter(None, map(calibre_langcode_to_name, mi.languages)) - names = ['%s' % (search_action_with_data('languages', n, book_id), _( + names = ['{}'.format(search_action_with_data('languages', n, book_id), _( 'Search calibre for books with the language: {}').format(n), n) for n in names] ans.append((field, row % (name, ', '.join(names)))) elif field == 'publisher': if not mi.publisher: continue - val = '%s' % ( + val = '{}'.format( search_action_with_data('publisher', mi.publisher, book_id), _('Click to see books with {0}: {1}').format(metadata['name'], a(mi.publisher)), p(mi.publisher)) @@ -283,11 +282,11 @@ def mi_to_html( continue aval = format_date(aval, 'yyyy-MM-dd') if val == aval: - val = '%s' % ( + val = '{}'.format( search_action_with_data(field, str(aval), book_id, None, original_value=val), a( _('Click to see books with {0}: {1}').format(metadata['name'] or field, val)), val) else: - val = '%s' % ( + val = '{}'.format( search_action_with_data(field, str(aval), book_id, None, original_value=val), a( _('Click to see books with {0}: {1} (derived from {2})').format( metadata['name'] or field, aval, val)), val) @@ -299,7 +298,7 @@ def mi_to_html( all_vals = mi.get(field) if not metadata.get('display', {}).get('is_names', False): all_vals = sorted(all_vals, key=sort_key) - links = ['%s' % ( + links = ['{}'.format( search_action_with_data(st, x, book_id, field), _('Click to see books with {0}: {1}').format( metadata['name'] or field, a(x)), p(x)) for x in all_vals] @@ -310,11 +309,11 @@ def mi_to_html( st = metadata['search_terms'][0] except Exception: st = field - val = '%s' % ( + val = '{}'.format( search_action_with_data(st, val, book_id, field), a( _('Click to see books with {0}: {1}').format(metadata['name'] or field, val)), p(val)) elif metadata['datatype'] == 'bool': - val = '%s' % ( + val = '{}'.format( search_action_with_data(field, val, book_id, None), a( _('Click to see books with {0}: {1}').format(metadata['name'] or field, val)), val) else: @@ -323,11 +322,11 @@ def mi_to_html( if not aval: continue if val == aval: - val = '%s' % ( + val = '{}'.format( search_action_with_data(field, str(aval), book_id, None, original_value=val), a( _('Click to see books with {0}: {1}').format(metadata['name'] or field, val)), val) else: - val = '%s' % ( + val = '{}'.format( search_action_with_data(field, str(aval), book_id, None, original_value=val), a( _('Click to see books with {0}: {1} (derived from {2})').format( metadata['name'] or field, aval, val)), val) @@ -359,5 +358,5 @@ def mi_to_html( # This causes wasted space at the edge of the table in Qt's rich text # engine, see https://bugs.launchpad.net/calibre/+bug/1881488 margin = 'left' if rtl else 'right' - rans += 'margin-{}: auto; '.format(margin) + rans += f'margin-{margin}: auto; ' return '{}">{}'.format(rans, '\n'.join(ans)), comment_fields diff --git a/src/calibre/ebooks/metadata/book/serialize.py b/src/calibre/ebooks/metadata/book/serialize.py index cc044a7018..f13cf38f20 100644 --- a/src/calibre/ebooks/metadata/book/serialize.py +++ b/src/calibre/ebooks/metadata/book/serialize.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2017, Kovid Goyal diff --git a/src/calibre/ebooks/metadata/docx.py b/src/calibre/ebooks/metadata/docx.py index aceb41addc..97d4c37f76 100644 --- a/src/calibre/ebooks/metadata/docx.py +++ b/src/calibre/ebooks/metadata/docx.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:fdm=marker:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/metadata/ereader.py b/src/calibre/ebooks/metadata/ereader.py index 0c911eec50..339ff4d919 100644 --- a/src/calibre/ebooks/metadata/ereader.py +++ b/src/calibre/ebooks/metadata/ereader.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - ''' Read meta information from eReader pdb files. ''' @@ -96,7 +93,7 @@ def set_metadata(stream, mi): # Merge the metadata into the file file_mi = get_metadata(stream, False) file_mi.smart_update(mi) - sections[hr.metadata_offset] = ('%s\x00%s\x00%s\x00%s\x00%s\x00' % ( + sections[hr.metadata_offset] = ('{}\x00{}\x00{}\x00{}\x00{}\x00'.format( file_mi.title, authors_to_string(file_mi.authors), '', file_mi.publisher, file_mi.isbn)).encode('cp1252', 'replace') # Rebuild the PDB wrapper because the offsets have changed due to the diff --git a/src/calibre/ebooks/metadata/extz.py b/src/calibre/ebooks/metadata/extz.py index 9ada262840..8020556a5d 100644 --- a/src/calibre/ebooks/metadata/extz.py +++ b/src/calibre/ebooks/metadata/extz.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - __license__ = 'GPL v3' __copyright__ = '2011, John Schember ' diff --git a/src/calibre/ebooks/metadata/fb2.py b/src/calibre/ebooks/metadata/fb2.py index ef3fb65fc7..a2c56d7167 100644 --- a/src/calibre/ebooks/metadata/fb2.py +++ b/src/calibre/ebooks/metadata/fb2.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' @@ -56,7 +55,7 @@ class Context: def get_or_create(self, parent, tag, attribs={}, at_start=True): xpathstr='./fb:'+tag for n, v in attribs.items(): - xpathstr += '[@%s="%s"]' % (n, v) + xpathstr += f'[@{n}="{v}"]' ans = self.XPath(xpathstr)(parent) if ans: ans = ans[0] @@ -65,7 +64,7 @@ class Context: return ans def create_tag(self, parent, tag, attribs={}, at_start=True): - ans = parent.makeelement('{%s}%s' % (self.fb_ns, tag)) + ans = parent.makeelement(f'{{{self.fb_ns}}}{tag}') ans.attrib.update(attribs) if at_start: parent.insert(0, ans) @@ -209,7 +208,7 @@ def _parse_book_title(root, ctx): xp_ti = '//fb:title-info/fb:book-title/text()' xp_pi = '//fb:publish-info/fb:book-title/text()' xp_si = '//fb:src-title-info/fb:book-title/text()' - book_title = ctx.XPath('normalize-space(%s|%s|%s)' % (xp_ti, xp_pi, xp_si))(root) + book_title = ctx.XPath(f'normalize-space({xp_ti}|{xp_pi}|{xp_si})')(root) return book_title @@ -243,7 +242,7 @@ def _parse_cover_data(root, imgid, mi, ctx): fmt = identify(cdata)[0] mi.cover_data = (fmt, cdata) else: - prints("WARNING: Unsupported coverpage mime-type '%s' (id=#%s)" % (mimetype, imgid)) + prints(f"WARNING: Unsupported coverpage mime-type '{mimetype}' (id=#{imgid})") def _parse_tags(root, mi, ctx): @@ -264,7 +263,7 @@ def _parse_series(root, mi, ctx): xp_ti = '//fb:title-info/fb:sequence[1]' xp_pi = '//fb:publish-info/fb:sequence[1]' - elms_sequence = ctx.XPath('%s|%s' % (xp_ti, xp_pi))(root) + elms_sequence = ctx.XPath(f'{xp_ti}|{xp_pi}')(root) if elms_sequence: mi.series = elms_sequence[0].get('name', None) if mi.series: diff --git a/src/calibre/ebooks/metadata/haodoo.py b/src/calibre/ebooks/metadata/haodoo.py index 25c357682e..f446bd66ac 100644 --- a/src/calibre/ebooks/metadata/haodoo.py +++ b/src/calibre/ebooks/metadata/haodoo.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - ''' Read meta information from Haodoo.net pdb files. ''' diff --git a/src/calibre/ebooks/metadata/html.py b/src/calibre/ebooks/metadata/html.py index abaa230eb7..14cb98bbce 100644 --- a/src/calibre/ebooks/metadata/html.py +++ b/src/calibre/ebooks/metadata/html.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/metadata/kdl.py b/src/calibre/ebooks/metadata/kdl.py index 526455ab15..727cb94a81 100644 --- a/src/calibre/ebooks/metadata/kdl.py +++ b/src/calibre/ebooks/metadata/kdl.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/metadata/kfx.py b/src/calibre/ebooks/metadata/kfx.py index c156e25dd7..1afae122d2 100644 --- a/src/calibre/ebooks/metadata/kfx.py +++ b/src/calibre/ebooks/metadata/kfx.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2015, Kovid Goyal , John Howell ' diff --git a/src/calibre/ebooks/metadata/mobi.py b/src/calibre/ebooks/metadata/mobi.py index 3a5c750045..2ca77b77cd 100644 --- a/src/calibre/ebooks/metadata/mobi.py +++ b/src/calibre/ebooks/metadata/mobi.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2009, Kovid Goyal @@ -313,7 +312,7 @@ class MetadataUpdater: print("%10s %10s %10s" % ("offset","flags","val")) for i in range(len(self.pdbrecords)): pdbrecord = self.pdbrecords[i] - print("%10X %10X %10X" % (pdbrecord[0], pdbrecord[1], pdbrecord[2])) + print(f"{pdbrecord[0]:10X} {pdbrecord[1]:10X} {pdbrecord[2]:10X}") def record(self, n): if n >= self.nrecs: diff --git a/src/calibre/ebooks/metadata/odt.py b/src/calibre/ebooks/metadata/odt.py index 5673f6c47c..7c8a856628 100644 --- a/src/calibre/ebooks/metadata/odt.py +++ b/src/calibre/ebooks/metadata/odt.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:fdm=marker:ai # # Copyright (C) 2006 Søren Roug, European Environment Agency # @@ -72,7 +71,7 @@ def get_metadata(stream, extract_cover=True): def find(field): ns, tag = fields[field] - ans = root.xpath('//ns0:{}'.format(tag), namespaces={'ns0': ns}) + ans = root.xpath(f'//ns0:{tag}', namespaces={'ns0': ns}) if ans: return normalize(tostring(ans[0], method='text', encoding='unicode', with_tail=False)).strip() @@ -172,7 +171,7 @@ def _set_metadata(raw, mi): def remove(*tag_names): for tag_name in tag_names: ns = fields[tag_name][0] - tag_name = '{}:{}'.format(nsrmap[ns], tag_name) + tag_name = f'{nsrmap[ns]}:{tag_name}' for x in xpath('descendant::' + tag_name, meta): x.getparent().remove(x) @@ -241,7 +240,7 @@ def _set_metadata(raw, mi): if not mi.is_null('series'): remove_user_metadata('opf.series', 'opf.seriesindex') add_user_metadata('opf.series', mi.series) - add_user_metadata('opf.seriesindex', '{}'.format(mi.series_index)) + add_user_metadata('opf.seriesindex', f'{mi.series_index}') if not mi.is_null('identifiers'): remove_user_metadata('opf.identifiers') add_user_metadata('opf.identifiers', as_unicode(json.dumps(mi.identifiers))) diff --git a/src/calibre/ebooks/metadata/opf.py b/src/calibre/ebooks/metadata/opf.py index 364517586a..7e24154ad9 100644 --- a/src/calibre/ebooks/metadata/opf.py +++ b/src/calibre/ebooks/metadata/opf.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2016, Kovid Goyal diff --git a/src/calibre/ebooks/metadata/opf2.py b/src/calibre/ebooks/metadata/opf2.py index 5febf2688b..0333795317 100644 --- a/src/calibre/ebooks/metadata/opf2.py +++ b/src/calibre/ebooks/metadata/opf2.py @@ -1273,11 +1273,11 @@ class OPF: # {{{ def create_metadata_element(self, name, attrib=None, is_dc=True): if is_dc: - name = '{%s}%s' % (self.NAMESPACES['dc'], name) + name = '{{{}}}{}'.format(self.NAMESPACES['dc'], name) else: attrib = attrib or {} attrib['name'] = 'calibre:' + name - name = '{%s}%s' % (self.NAMESPACES['opf'], 'meta') + name = '{{{}}}{}'.format(self.NAMESPACES['opf'], 'meta') nsmap = dict(self.NAMESPACES) del nsmap['opf'] elem = etree.SubElement(self.metadata, name, attrib=attrib, diff --git a/src/calibre/ebooks/metadata/opf3.py b/src/calibre/ebooks/metadata/opf3.py index 94b29a9404..d1e45c00f8 100644 --- a/src/calibre/ebooks/metadata/opf3.py +++ b/src/calibre/ebooks/metadata/opf3.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2016, Kovid Goyal @@ -192,7 +191,7 @@ def ensure_prefix(root, prefixes, prefix, value=None): prefixes[prefix] = value or reserved_prefixes[prefix] prefixes = {k:v for k, v in iteritems(prefixes) if reserved_prefixes.get(k) != v} if prefixes: - root.set('prefix', ' '.join('%s: %s' % (k, v) for k, v in iteritems(prefixes))) + root.set('prefix', ' '.join(f'{k}: {v}' for k, v in iteritems(prefixes))) else: root.attrib.pop('prefix', None) @@ -301,7 +300,7 @@ def set_identifiers(root, prefixes, refines, new_identifiers, force_identifiers= metadata = XPath('./opf:metadata')(root)[0] for scheme, val in iteritems(new_identifiers): ident = metadata.makeelement(DC('identifier')) - ident.text = '%s:%s' % (scheme, val) + ident.text = f'{scheme}:{val}' if package_identifier is None: metadata.append(ident) else: @@ -323,7 +322,7 @@ def identifier_writer(name): metadata = XPath('./opf:metadata')(root)[0] if ival: ident = metadata.makeelement(DC('identifier')) - ident.text = '%s:%s' % (name, ival) + ident.text = f'{name}:{ival}' if package_identifier is None: metadata.append(ident) else: @@ -836,7 +835,7 @@ def set_series(root, prefixes, refines, series, series_index): def dict_reader(name, load=json.loads, try2=True): - pq = '%s:%s' % (CALIBRE_PREFIX, name) + pq = f'{CALIBRE_PREFIX}:{name}' def reader(root, prefixes, refines): for meta in XPath('./opf:metadata/opf:meta[@property]')(root): @@ -868,7 +867,7 @@ read_author_link_map = dict_reader('author_link_map') def dict_writer(name, serialize=dump_dict, remove2=True): - pq = '%s:%s' % (CALIBRE_PREFIX, name) + pq = f'{CALIBRE_PREFIX}:{name}' def writer(root, prefixes, refines, val): if remove2: diff --git a/src/calibre/ebooks/metadata/opf3_test.py b/src/calibre/ebooks/metadata/opf3_test.py index b1a9dac4c4..3dd8f0657e 100644 --- a/src/calibre/ebooks/metadata/opf3_test.py +++ b/src/calibre/ebooks/metadata/opf3_test.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2016, Kovid Goyal @@ -292,7 +291,7 @@ class TestOPF3(unittest.TestCase): for name in 'author_link_map user_categories'.split(): root = self.get_opf('''''' % name) self.ae({'1':1}, rt(root, name)) - root = self.get_opf('''{"2":2}''' % (name, name)) + root = self.get_opf(f'''{{"2":2}}''') self.ae({'2':2}, rt(root, name)) self.ae({'3':3}, st(root, name, {3:3})) @@ -519,7 +518,7 @@ class TestOPF3(unittest.TestCase): for field in ALL_METADATA_FIELDS: if field not in 'manifest spine': v2, v3 = getattr(mi2, field, None), getattr(mi3, field, None) - self.ae(v2, v3, '%s: %r != %r' % (field, v2, v3)) + self.ae(v2, v3, f'{field}: {v2!r} != {v3!r}') mi2 = OPF(BytesIO(raw.encode('utf-8'))).to_book_metadata() root = safe_xml_fromstring(raw) diff --git a/src/calibre/ebooks/metadata/opf_2_to_3.py b/src/calibre/ebooks/metadata/opf_2_to_3.py index c29496d134..fda4760db8 100644 --- a/src/calibre/ebooks/metadata/opf_2_to_3.py +++ b/src/calibre/ebooks/metadata/opf_2_to_3.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2018, Kovid Goyal @@ -29,7 +28,7 @@ def upgrade_identifiers(root, data): if prefix and rest: scheme, val = prefix, rest if scheme and val: - ident.text = '{}:{}'.format(scheme, val) + ident.text = f'{scheme}:{val}' for attr in tuple(ident.attrib): if attr != 'id': del ident.attrib[attr] diff --git a/src/calibre/ebooks/metadata/pdb.py b/src/calibre/ebooks/metadata/pdb.py index 71fa243dbb..4ab2130fd1 100644 --- a/src/calibre/ebooks/metadata/pdb.py +++ b/src/calibre/ebooks/metadata/pdb.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - ''' Read meta information from pdb files. ''' diff --git a/src/calibre/ebooks/metadata/plucker.py b/src/calibre/ebooks/metadata/plucker.py index 0403879a4b..4fedecb0f4 100644 --- a/src/calibre/ebooks/metadata/plucker.py +++ b/src/calibre/ebooks/metadata/plucker.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - ''' Read meta information from Plucker pdb files. ''' diff --git a/src/calibre/ebooks/metadata/pml.py b/src/calibre/ebooks/metadata/pml.py index cab23eb411..b9ebb98f8f 100644 --- a/src/calibre/ebooks/metadata/pml.py +++ b/src/calibre/ebooks/metadata/pml.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - __license__ = 'GPL v3' __copyright__ = '2009, John Schember ' __docformat__ = 'restructuredtext en' diff --git a/src/calibre/ebooks/metadata/rtf.py b/src/calibre/ebooks/metadata/rtf.py index 799a166e19..103bc35746 100644 --- a/src/calibre/ebooks/metadata/rtf.py +++ b/src/calibre/ebooks/metadata/rtf.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2008, Kovid Goyal """ @@ -81,7 +80,7 @@ def detect_codepage(stream): def encode(unistr): if not isinstance(unistr, str): unistr = force_unicode(unistr) - return ''.join(c if ord(c) < 128 else '\\u{}?'.format(ord(c)) for c in unistr) + return ''.join(c if ord(c) < 128 else f'\\u{ord(c)}?' for c in unistr) def decode(raw, codec): diff --git a/src/calibre/ebooks/metadata/search_internet.py b/src/calibre/ebooks/metadata/search_internet.py index ef37782082..55b9915376 100644 --- a/src/calibre/ebooks/metadata/search_internet.py +++ b/src/calibre/ebooks/metadata/search_internet.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2017, Kovid Goyal diff --git a/src/calibre/ebooks/metadata/tag_mapper.py b/src/calibre/ebooks/metadata/tag_mapper.py index 2c32d61bb1..198e20ae2b 100644 --- a/src/calibre/ebooks/metadata/tag_mapper.py +++ b/src/calibre/ebooks/metadata/tag_mapper.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2015, Kovid Goyal diff --git a/src/calibre/ebooks/metadata/test_author_sort.py b/src/calibre/ebooks/metadata/test_author_sort.py index 54d1d65570..29e79eda78 100644 --- a/src/calibre/ebooks/metadata/test_author_sort.py +++ b/src/calibre/ebooks/metadata/test_author_sort.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2021, Kovid Goyal diff --git a/src/calibre/ebooks/metadata/topaz.py b/src/calibre/ebooks/metadata/topaz.py index abf09c18ed..df123fa59e 100644 --- a/src/calibre/ebooks/metadata/topaz.py +++ b/src/calibre/ebooks/metadata/topaz.py @@ -166,7 +166,7 @@ class MetadataUpdater: def dump_metadata(self): ''' Diagnostic ''' for tag in self.metadata: - print('%s: %s' % (tag, repr(self.metadata[tag]))) + print(f'{tag}: {repr(self.metadata[tag])}') def encode_vwi(self,value): ans = [] diff --git a/src/calibre/ebooks/metadata/txt.py b/src/calibre/ebooks/metadata/txt.py index 8c624053e5..366fefdc84 100644 --- a/src/calibre/ebooks/metadata/txt.py +++ b/src/calibre/ebooks/metadata/txt.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - __license__ = 'GPL v3' __copyright__ = '2009, John Schember ' diff --git a/src/calibre/ebooks/metadata/utils.py b/src/calibre/ebooks/metadata/utils.py index a0d815fe5e..c7f518a209 100644 --- a/src/calibre/ebooks/metadata/utils.py +++ b/src/calibre/ebooks/metadata/utils.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2016, Kovid Goyal from collections import namedtuple diff --git a/src/calibre/ebooks/metadata/worker.py b/src/calibre/ebooks/metadata/worker.py index 15b1f9d77f..2e3de51942 100644 --- a/src/calibre/ebooks/metadata/worker.py +++ b/src/calibre/ebooks/metadata/worker.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai # License: GPLv3 Copyright: 2009, Kovid Goyal import os diff --git a/src/calibre/ebooks/metadata/xisbn.py b/src/calibre/ebooks/metadata/xisbn.py index 53d8829847..d97c867549 100644 --- a/src/calibre/ebooks/metadata/xisbn.py +++ b/src/calibre/ebooks/metadata/xisbn.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/metadata/xmp.py b/src/calibre/ebooks/metadata/xmp.py index 9f9a3f89ff..33a01c6eeb 100644 --- a/src/calibre/ebooks/metadata/xmp.py +++ b/src/calibre/ebooks/metadata/xmp.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' @@ -48,7 +47,7 @@ KNOWN_ID_SCHEMES = {'isbn', 'url', 'doi'} def expand(name): prefix, name = name.partition(':')[::2] - return '{%s}%s' % (NS_MAP[prefix], name) + return f'{{{NS_MAP[prefix]}}}{name}' xpath_cache = {} @@ -313,7 +312,7 @@ def metadata_from_xmp_packet(raw_bytes): for namespace in ('prism', 'pdfx'): for scheme in KNOWN_ID_SCHEMES: if scheme not in identifiers: - val = first_simple('//%s:%s' % (namespace, scheme), root) + val = first_simple(f'//{namespace}:{scheme}', root) scheme = scheme.lower() if scheme == 'isbn': val = check_isbn(val) diff --git a/src/calibre/ebooks/mobi/__init__.py b/src/calibre/ebooks/mobi/__init__.py index 8c2c1b6db6..3a5db504e9 100644 --- a/src/calibre/ebooks/mobi/__init__.py +++ b/src/calibre/ebooks/mobi/__init__.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/mobi/debug/__init__.py b/src/calibre/ebooks/mobi/debug/__init__.py index bde05e4f59..65b1c31f65 100644 --- a/src/calibre/ebooks/mobi/debug/__init__.py +++ b/src/calibre/ebooks/mobi/debug/__init__.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/mobi/debug/containers.py b/src/calibre/ebooks/mobi/debug/containers.py index 0ee1cb92a3..e5a996ebee 100644 --- a/src/calibre/ebooks/mobi/debug/containers.py +++ b/src/calibre/ebooks/mobi/debug/containers.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/mobi/debug/headers.py b/src/calibre/ebooks/mobi/debug/headers.py index b886bdc563..59e62f68f0 100644 --- a/src/calibre/ebooks/mobi/debug/headers.py +++ b/src/calibre/ebooks/mobi/debug/headers.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/mobi/debug/index.py b/src/calibre/ebooks/mobi/debug/index.py index b412bcb380..7ded8ab4d2 100644 --- a/src/calibre/ebooks/mobi/debug/index.py +++ b/src/calibre/ebooks/mobi/debug/index.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/mobi/debug/main.py b/src/calibre/ebooks/mobi/debug/main.py index 82cf818863..de7fc6f7d4 100644 --- a/src/calibre/ebooks/mobi/debug/main.py +++ b/src/calibre/ebooks/mobi/debug/main.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/mobi/debug/mobi6.py b/src/calibre/ebooks/mobi/debug/mobi6.py index 36c81749d4..32193b9bd2 100644 --- a/src/calibre/ebooks/mobi/debug/mobi6.py +++ b/src/calibre/ebooks/mobi/debug/mobi6.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/mobi/debug/mobi8.py b/src/calibre/ebooks/mobi/debug/mobi8.py index dd619db2ea..f7c1cc0df5 100644 --- a/src/calibre/ebooks/mobi/debug/mobi8.py +++ b/src/calibre/ebooks/mobi/debug/mobi8.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/mobi/huffcdic.py b/src/calibre/ebooks/mobi/huffcdic.py index c17d4096df..20e6089ce1 100644 --- a/src/calibre/ebooks/mobi/huffcdic.py +++ b/src/calibre/ebooks/mobi/huffcdic.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/mobi/mobiml.py b/src/calibre/ebooks/mobi/mobiml.py index 7d44cc4d8e..f9a3b6c195 100644 --- a/src/calibre/ebooks/mobi/mobiml.py +++ b/src/calibre/ebooks/mobi/mobiml.py @@ -24,7 +24,7 @@ MBP_NS = 'http://mobipocket.com/ns/mbp' def MBP(name): - return '{%s}%s' % (MBP_NS, name) + return f'{{{MBP_NS}}}{name}' MOBI_NSMAP = {None: XHTML_NS, 'mbp': MBP_NS} diff --git a/src/calibre/ebooks/mobi/reader/__init__.py b/src/calibre/ebooks/mobi/reader/__init__.py index 6b2910c3df..c2a96b7708 100644 --- a/src/calibre/ebooks/mobi/reader/__init__.py +++ b/src/calibre/ebooks/mobi/reader/__init__.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/mobi/reader/containers.py b/src/calibre/ebooks/mobi/reader/containers.py index d2d990e9bb..fcdd1120b5 100644 --- a/src/calibre/ebooks/mobi/reader/containers.py +++ b/src/calibre/ebooks/mobi/reader/containers.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/mobi/reader/headers.py b/src/calibre/ebooks/mobi/reader/headers.py index c24c0c2006..1f2419fbcb 100644 --- a/src/calibre/ebooks/mobi/reader/headers.py +++ b/src/calibre/ebooks/mobi/reader/headers.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/mobi/reader/index.py b/src/calibre/ebooks/mobi/reader/index.py index 8e31211014..27f2b06eb1 100644 --- a/src/calibre/ebooks/mobi/reader/index.py +++ b/src/calibre/ebooks/mobi/reader/index.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/mobi/reader/markup.py b/src/calibre/ebooks/mobi/reader/markup.py index e18740b70e..979d7cf071 100644 --- a/src/calibre/ebooks/mobi/reader/markup.py +++ b/src/calibre/ebooks/mobi/reader/markup.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/mobi/reader/mobi6.py b/src/calibre/ebooks/mobi/reader/mobi6.py index 9ea4376a91..76c31881a4 100644 --- a/src/calibre/ebooks/mobi/reader/mobi6.py +++ b/src/calibre/ebooks/mobi/reader/mobi6.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' @@ -321,7 +320,7 @@ class MobiReader: css = [self.base_css_rules, '\n\n'] for cls, rule in self.tag_css_rules.items(): - css.append('.%s { %s }\n\n' % (cls, rule)) + css.append(f'.{cls} {{ {rule} }}\n\n') write_as_utf8('styles.css', ''.join(css)) if self.book_header.exth is not None or self.embedded_mi is not None: diff --git a/src/calibre/ebooks/mobi/reader/mobi8.py b/src/calibre/ebooks/mobi/reader/mobi8.py index 73318be22e..a866a7cdc4 100644 --- a/src/calibre/ebooks/mobi/reader/mobi8.py +++ b/src/calibre/ebooks/mobi/reader/mobi8.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/mobi/reader/ncx.py b/src/calibre/ebooks/mobi/reader/ncx.py index be49c2ea95..b9f9a735cb 100644 --- a/src/calibre/ebooks/mobi/reader/ncx.py +++ b/src/calibre/ebooks/mobi/reader/ncx.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/mobi/tweak.py b/src/calibre/ebooks/mobi/tweak.py index 591c4cd528..512fae4ea5 100644 --- a/src/calibre/ebooks/mobi/tweak.py +++ b/src/calibre/ebooks/mobi/tweak.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/mobi/utils.py b/src/calibre/ebooks/mobi/utils.py index ab34265fa9..66982233fc 100644 --- a/src/calibre/ebooks/mobi/utils.py +++ b/src/calibre/ebooks/mobi/utils.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/mobi/writer2/__init__.py b/src/calibre/ebooks/mobi/writer2/__init__.py index 792a0f633e..ee0e098f16 100644 --- a/src/calibre/ebooks/mobi/writer2/__init__.py +++ b/src/calibre/ebooks/mobi/writer2/__init__.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/mobi/writer2/indexer.py b/src/calibre/ebooks/mobi/writer2/indexer.py index 40b7502ac5..80f337abc1 100644 --- a/src/calibre/ebooks/mobi/writer2/indexer.py +++ b/src/calibre/ebooks/mobi/writer2/indexer.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/mobi/writer2/main.py b/src/calibre/ebooks/mobi/writer2/main.py index c583d927da..0f09b4e656 100644 --- a/src/calibre/ebooks/mobi/writer2/main.py +++ b/src/calibre/ebooks/mobi/writer2/main.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/mobi/writer2/resources.py b/src/calibre/ebooks/mobi/writer2/resources.py index 2bf2d22d96..701b98f220 100644 --- a/src/calibre/ebooks/mobi/writer2/resources.py +++ b/src/calibre/ebooks/mobi/writer2/resources.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/mobi/writer2/serializer.py b/src/calibre/ebooks/mobi/writer2/serializer.py index e8aaa11341..5d6d3d33a1 100644 --- a/src/calibre/ebooks/mobi/writer2/serializer.py +++ b/src/calibre/ebooks/mobi/writer2/serializer.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/mobi/writer8/__init__.py b/src/calibre/ebooks/mobi/writer8/__init__.py index 6b2910c3df..c2a96b7708 100644 --- a/src/calibre/ebooks/mobi/writer8/__init__.py +++ b/src/calibre/ebooks/mobi/writer8/__init__.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/mobi/writer8/cleanup.py b/src/calibre/ebooks/mobi/writer8/cleanup.py index 497f90f660..afcd76d036 100644 --- a/src/calibre/ebooks/mobi/writer8/cleanup.py +++ b/src/calibre/ebooks/mobi/writer8/cleanup.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/mobi/writer8/exth.py b/src/calibre/ebooks/mobi/writer8/exth.py index 1c3fc6d6a2..a6af8d21fa 100644 --- a/src/calibre/ebooks/mobi/writer8/exth.py +++ b/src/calibre/ebooks/mobi/writer8/exth.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/mobi/writer8/header.py b/src/calibre/ebooks/mobi/writer8/header.py index 19cc54bd01..33fe8ffcf4 100644 --- a/src/calibre/ebooks/mobi/writer8/header.py +++ b/src/calibre/ebooks/mobi/writer8/header.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/mobi/writer8/index.py b/src/calibre/ebooks/mobi/writer8/index.py index 20028f1d83..b56eb02774 100644 --- a/src/calibre/ebooks/mobi/writer8/index.py +++ b/src/calibre/ebooks/mobi/writer8/index.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' __copyright__ = '2012, Kovid Goyal ' @@ -126,7 +125,7 @@ class Index: # {{{ shifts = mask_to_bit_shifts[mask] ans |= mask & (nentries << shifts) if len(cbs) != cls.control_byte_count: - raise ValueError('The entry {!r} is invalid'.format([lead_text, tags])) + raise ValueError(f'The entry {[lead_text, tags]!r} is invalid') control_bytes.append(cbs) return control_bytes diff --git a/src/calibre/ebooks/mobi/writer8/main.py b/src/calibre/ebooks/mobi/writer8/main.py index 8657423929..29ac173c6e 100644 --- a/src/calibre/ebooks/mobi/writer8/main.py +++ b/src/calibre/ebooks/mobi/writer8/main.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/mobi/writer8/mobi.py b/src/calibre/ebooks/mobi/writer8/mobi.py index d22dd33d96..58130e4ce3 100644 --- a/src/calibre/ebooks/mobi/writer8/mobi.py +++ b/src/calibre/ebooks/mobi/writer8/mobi.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/mobi/writer8/skeleton.py b/src/calibre/ebooks/mobi/writer8/skeleton.py index 4a4b5c95df..a42ce358fc 100644 --- a/src/calibre/ebooks/mobi/writer8/skeleton.py +++ b/src/calibre/ebooks/mobi/writer8/skeleton.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/mobi/writer8/tbs.py b/src/calibre/ebooks/mobi/writer8/tbs.py index f5a28ea638..68f1c3c604 100644 --- a/src/calibre/ebooks/mobi/writer8/tbs.py +++ b/src/calibre/ebooks/mobi/writer8/tbs.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/mobi/writer8/toc.py b/src/calibre/ebooks/mobi/writer8/toc.py index d95ec819cb..33a3d884ca 100644 --- a/src/calibre/ebooks/mobi/writer8/toc.py +++ b/src/calibre/ebooks/mobi/writer8/toc.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/oeb/base.py b/src/calibre/ebooks/oeb/base.py index f57727c483..8934a4d174 100644 --- a/src/calibre/ebooks/oeb/base.py +++ b/src/calibre/ebooks/oeb/base.py @@ -60,39 +60,39 @@ OPF2_NSMAP = {'opf': OPF2_NS, 'dc': DC11_NS, 'dcterms': DCTERMS_NS, def XML(name): - return '{%s}%s' % (XML_NS, name) + return f'{{{XML_NS}}}{name}' def OPF(name): - return '{%s}%s' % (OPF2_NS, name) + return f'{{{OPF2_NS}}}{name}' def DC(name): - return '{%s}%s' % (DC11_NS, name) + return f'{{{DC11_NS}}}{name}' def XSI(name): - return '{%s}%s' % (XSI_NS, name) + return f'{{{XSI_NS}}}{name}' def DCTERMS(name): - return '{%s}%s' % (DCTERMS_NS, name) + return f'{{{DCTERMS_NS}}}{name}' def NCX(name): - return '{%s}%s' % (NCX_NS, name) + return f'{{{NCX_NS}}}{name}' def SVG(name): - return '{%s}%s' % (SVG_NS, name) + return f'{{{SVG_NS}}}{name}' def XLINK(name): - return '{%s}%s' % (XLINK_NS, name) + return f'{{{XLINK_NS}}}{name}' def CALIBRE(name): - return '{%s}%s' % (CALIBRE_NS, name) + return f'{{{CALIBRE_NS}}}{name}' _css_url_re = re.compile(r'url\s*\([\'"]{0,1}(.*?)[\'"]{0,1}\)', re.I) @@ -370,7 +370,7 @@ def qname(name, nsmap): prefix, local = name.split(':', 1) if prefix not in nsmap: return name - return '{%s}%s' % (nsmap[prefix], local) + return f'{{{nsmap[prefix]}}}{local}' def isqname(name): @@ -468,7 +468,7 @@ def urlnormalize(href): try: parts = urlparse(href) except ValueError as e: - raise ValueError('Failed to parse the URL: %r with underlying error: %s' % (href, as_unicode(e))) + raise ValueError(f'Failed to parse the URL: {href!r} with underlying error: {as_unicode(e)}') if not parts.scheme or parts.scheme == 'file': path, frag = urldefrag(href) parts = ('', '', path, '', '', frag) @@ -674,7 +674,7 @@ class Metadata: allowed = self.allowed if allowed is not None and term not in allowed: raise AttributeError( - 'attribute %r not valid for metadata term %r' % ( + 'attribute {!r} not valid for metadata term {!r}'.format( self.attr(term), barename(obj.term))) return self.attr(term) diff --git a/src/calibre/ebooks/oeb/display/__init__.py b/src/calibre/ebooks/oeb/display/__init__.py index 6b2910c3df..c2a96b7708 100644 --- a/src/calibre/ebooks/oeb/display/__init__.py +++ b/src/calibre/ebooks/oeb/display/__init__.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/oeb/display/webview.py b/src/calibre/ebooks/oeb/display/webview.py index 6a16022a22..ae9ada9517 100644 --- a/src/calibre/ebooks/oeb/display/webview.py +++ b/src/calibre/ebooks/oeb/display/webview.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/oeb/iterator/__init__.py b/src/calibre/ebooks/oeb/iterator/__init__.py index 128613218e..f821fc427e 100644 --- a/src/calibre/ebooks/oeb/iterator/__init__.py +++ b/src/calibre/ebooks/oeb/iterator/__init__.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/oeb/iterator/book.py b/src/calibre/ebooks/oeb/iterator/book.py index 1983e3694c..3f3ae5edfc 100644 --- a/src/calibre/ebooks/oeb/iterator/book.py +++ b/src/calibre/ebooks/oeb/iterator/book.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/oeb/iterator/bookmarks.py b/src/calibre/ebooks/oeb/iterator/bookmarks.py index 3146b5cc36..c28d2e5f21 100644 --- a/src/calibre/ebooks/oeb/iterator/bookmarks.py +++ b/src/calibre/ebooks/oeb/iterator/bookmarks.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/oeb/iterator/spine.py b/src/calibre/ebooks/oeb/iterator/spine.py index 5ae81275ae..5467b2b95d 100644 --- a/src/calibre/ebooks/oeb/iterator/spine.py +++ b/src/calibre/ebooks/oeb/iterator/spine.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/oeb/normalize_css.py b/src/calibre/ebooks/oeb/normalize_css.py index 19db58fd0f..d5cb2eb9b2 100644 --- a/src/calibre/ebooks/oeb/normalize_css.py +++ b/src/calibre/ebooks/oeb/normalize_css.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' @@ -79,10 +78,10 @@ def normalize_edge(name, cssvalue): if '-' in name: l, _, r = name.partition('-') for edge, value in zip(EDGES, values): - style['%s-%s-%s' % (l, edge, r)] = value + style[f'{l}-{edge}-{r}'] = value else: for edge, value in zip(EDGES, values): - style['%s-%s' % (name, edge)] = value + style[f'{name}-{edge}'] = value return style @@ -181,7 +180,7 @@ def normalize_filter_css(props): n = normalizers.get(prop, None) ans.add(prop) if n is not None and prop in SHORTHAND_DEFAULTS: - dec = p.parseStyle('%s: %s' % (prop, SHORTHAND_DEFAULTS[prop])) + dec = p.parseStyle(f'{prop}: {SHORTHAND_DEFAULTS[prop]}') cssvalue = dec.getPropertyCSSValue(dec.item(0)) ans |= set(n(prop, cssvalue)) return ans @@ -227,7 +226,7 @@ def condense_border(style, props): name = 'border-%s' % edge vals = [] for prop in BORDER_PROPS: - x = prop_map.get('%s-%s' % (name, prop), None) + x = prop_map.get(f'{name}-{prop}', None) if x is not None: vals.append(x) if len(vals) == 3: @@ -298,9 +297,9 @@ def test_normalization(return_tests=False): # {{{ def test_border_normalization(self): def border_edge_dict(expected, edge='right'): - ans = {'border-%s-%s' % (edge, x): DEFAULTS['border-%s-%s' % (edge, x)] for x in ('style', 'width', 'color')} + ans = {f'border-{edge}-{x}': DEFAULTS[f'border-{edge}-{x}'] for x in ('style', 'width', 'color')} for x, v in iteritems(expected): - ans['border-%s-%s' % (edge, x)] = v + ans[f'border-{edge}-{x}'] = v return ans def border_dict(expected): @@ -310,9 +309,9 @@ def test_normalization(return_tests=False): # {{{ return ans def border_val_dict(expected, val='color'): - ans = {'border-%s-%s' % (edge, val): DEFAULTS['border-%s-%s' % (edge, val)] for edge in EDGES} + ans = {f'border-{edge}-{val}': DEFAULTS[f'border-{edge}-{val}'] for edge in EDGES} for edge in EDGES: - ans['border-%s-%s' % (edge, val)] = expected + ans[f'border-{edge}-{val}'] = expected return ans for raw, expected in iteritems({ @@ -322,7 +321,7 @@ def test_normalization(return_tests=False): # {{{ }): for edge in EDGES: br = 'border-%s' % edge - val = tuple(parseStyle('%s: %s' % (br, raw), validate=False))[0].propertyValue + val = tuple(parseStyle(f'{br}: {raw}', validate=False))[0].propertyValue self.assertDictEqual(border_edge_dict(expected, edge), normalizers[br](br, val)) for raw, expected in iteritems({ @@ -330,18 +329,18 @@ def test_normalization(return_tests=False): # {{{ '1px': {'width': '1px'}, '#aaa': {'color': '#aaa'}, 'thin groove': {'width':'thin', 'style':'groove'}, }): - val = tuple(parseStyle('%s: %s' % ('border', raw), validate=False))[0].propertyValue + val = tuple(parseStyle('{}: {}'.format('border', raw), validate=False))[0].propertyValue self.assertDictEqual(border_dict(expected), normalizers['border']('border', val)) for name, val in iteritems({ 'width': '10%', 'color': 'rgb(0, 1, 1)', 'style': 'double', }): - cval = tuple(parseStyle('border-%s: %s' % (name, val), validate=False))[0].propertyValue + cval = tuple(parseStyle(f'border-{name}: {val}', validate=False))[0].propertyValue self.assertDictEqual(border_val_dict(val, name), normalizers['border-'+name]('border-'+name, cval)) def test_edge_normalization(self): def edge_dict(prefix, expected): - return {'%s-%s' % (prefix, edge) : x for edge, x in zip(EDGES, expected)} + return {f'{prefix}-{edge}' : x for edge, x in zip(EDGES, expected)} for raw, expected in iteritems({ '2px': ('2px', '2px', '2px', '2px'), '1em 2em': ('1em', '2em', '1em', '2em'), @@ -349,7 +348,7 @@ def test_normalization(return_tests=False): # {{{ '1 2 3 4': ('1', '2', '3', '4'), }): for prefix in ('margin', 'padding'): - cval = tuple(parseStyle('%s: %s' % (prefix, raw), validate=False))[0].propertyValue + cval = tuple(parseStyle(f'{prefix}: {raw}', validate=False))[0].propertyValue self.assertDictEqual(edge_dict(prefix, expected), normalizers[prefix](prefix, cval)) def test_list_style_normalization(self): @@ -371,13 +370,13 @@ def test_normalization(return_tests=False): # {{{ ae({'font'} | set(font_composition), normalize_filter_css({'font'})) for p in ('margin', 'padding'): ae({p} | {p + '-' + x for x in EDGES}, normalize_filter_css({p})) - bvals = {'border-%s-%s' % (edge, x) for edge in EDGES for x in BORDER_PROPS} + bvals = {f'border-{edge}-{x}' for edge in EDGES for x in BORDER_PROPS} ae(bvals | {'border'}, normalize_filter_css({'border'})) for x in BORDER_PROPS: - sbvals = {'border-%s-%s' % (e, x) for e in EDGES} + sbvals = {f'border-{e}-{x}' for e in EDGES} ae(sbvals | {'border-%s' % x}, normalize_filter_css({'border-%s' % x})) for e in EDGES: - sbvals = {'border-%s-%s' % (e, x) for x in BORDER_PROPS} + sbvals = {f'border-{e}-{x}' for x in BORDER_PROPS} ae(sbvals | {'border-%s' % e}, normalize_filter_css({'border-%s' % e})) ae({'list-style', 'list-style-image', 'list-style-type', 'list-style-position'}, normalize_filter_css({'list-style'})) @@ -393,32 +392,32 @@ def test_normalization(return_tests=False): # {{{ tuple('0 0 0 0'.split()) : '0', }): for prefix in ('margin', 'padding'): - css = {'%s-%s' % (prefix, x) : str(y)+'pt' if isinstance(y, numbers.Number) else y + css = {f'{prefix}-{x}' : str(y)+'pt' if isinstance(y, numbers.Number) else y for x, y in zip(('left', 'top', 'right', 'bottom'), s)} - css = '; '.join(('%s:%s' % (k, v) for k, v in iteritems(css))) + css = '; '.join((f'{k}:{v}' for k, v in iteritems(css))) style = parseStyle(css) condense_rule(style) val = getattr(style.getProperty(prefix), 'value', None) self.assertEqual(v, val) if val is not None: for edge in EDGES: - self.assertFalse(getattr(style.getProperty('%s-%s' % (prefix, edge)), 'value', None)) + self.assertFalse(getattr(style.getProperty(f'{prefix}-{edge}'), 'value', None)) def test_border_condensation(self): vals = 'red solid 5px' - css = '; '.join('border-%s-%s: %s' % (edge, p, v) for edge in EDGES for p, v in zip(BORDER_PROPS, vals.split())) + css = '; '.join(f'border-{edge}-{p}: {v}' for edge in EDGES for p, v in zip(BORDER_PROPS, vals.split())) style = parseStyle(css) condense_rule(style) for e, p in product(EDGES, BORDER_PROPS): - self.assertFalse(style.getProperty('border-%s-%s' % (e, p))) + self.assertFalse(style.getProperty(f'border-{e}-{p}')) self.assertFalse(style.getProperty('border-%s' % e)) self.assertFalse(style.getProperty('border-%s' % p)) self.assertEqual(style.getProperty('border').value, vals) - css = '; '.join('border-%s-%s: %s' % (edge, p, v) for edge in ('top',) for p, v in zip(BORDER_PROPS, vals.split())) + css = '; '.join(f'border-{edge}-{p}: {v}' for edge in ('top',) for p, v in zip(BORDER_PROPS, vals.split())) style = parseStyle(css) condense_rule(style) self.assertEqual(css_text(style), 'border-top: %s' % vals) - css += ';' + '; '.join('border-%s-%s: %s' % (edge, p, v) for edge in ('right', 'left', 'bottom') for p, v in + css += ';' + '; '.join(f'border-{edge}-{p}: {v}' for edge in ('right', 'left', 'bottom') for p, v in zip(BORDER_PROPS, vals.replace('red', 'green').split())) style = parseStyle(css) condense_rule(style) diff --git a/src/calibre/ebooks/oeb/parse_utils.py b/src/calibre/ebooks/oeb/parse_utils.py index 19707b982b..2d32420441 100644 --- a/src/calibre/ebooks/oeb/parse_utils.py +++ b/src/calibre/ebooks/oeb/parse_utils.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' @@ -37,7 +36,7 @@ def namespace(name): def XHTML(name): - return '{%s}%s' % (XHTML_NS, name) + return f'{{{XHTML_NS}}}{name}' def xpath(elem, expr): diff --git a/src/calibre/ebooks/oeb/polish/__init__.py b/src/calibre/ebooks/oeb/polish/__init__.py index 409db9d8ca..d91f720858 100644 --- a/src/calibre/ebooks/oeb/polish/__init__.py +++ b/src/calibre/ebooks/oeb/polish/__init__.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:fdm=marker:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/oeb/polish/cascade.py b/src/calibre/ebooks/oeb/polish/cascade.py index d6c42e86a6..07b738016d 100644 --- a/src/calibre/ebooks/oeb/polish/cascade.py +++ b/src/calibre/ebooks/oeb/polish/cascade.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2016, Kovid Goyal @@ -66,7 +65,7 @@ def iterrules(container, sheet_name, rules=None, media_rule_ok=media_allowed, ru name = container.href_to_name(rule.href, sheet_name) if container.has_name(name): if name in importing: - container.log.error('Recursive import of {} from {}, ignoring'.format(name, sheet_name)) + container.log.error(f'Recursive import of {name} from {sheet_name}, ignoring') else: csheet = container.parsed(name) if isinstance(csheet, CSSStyleSheet): @@ -174,7 +173,7 @@ def resolve_styles(container, name, select=None, sheet_callback=None): try: matches = tuple(select(text)) except SelectorError as err: - container.log.error('Ignoring CSS rule with invalid selector: %r (%s)' % (text, as_unicode(err))) + container.log.error(f'Ignoring CSS rule with invalid selector: {text!r} ({as_unicode(err)})') continue m = pseudo_pat.search(text) style = normalize_style_declaration(rule.style, sheet_name) diff --git a/src/calibre/ebooks/oeb/polish/check/__init__.py b/src/calibre/ebooks/oeb/polish/check/__init__.py index e4102b4b10..0cbf055ec8 100644 --- a/src/calibre/ebooks/oeb/polish/check/__init__.py +++ b/src/calibre/ebooks/oeb/polish/check/__init__.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/oeb/polish/check/base.py b/src/calibre/ebooks/oeb/polish/check/base.py index 292ebfe51e..0af5d4fe61 100644 --- a/src/calibre/ebooks/oeb/polish/check/base.py +++ b/src/calibre/ebooks/oeb/polish/check/base.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' @@ -28,7 +27,7 @@ class BaseError: self.all_locations = None def __str__(self): - return '%s:%s (%s, %s):%s' % (self.__class__.__name__, self.name, self.line, self.col, self.msg) + return f'{self.__class__.__name__}:{self.name} ({self.line}, {self.col}):{self.msg}' __repr__ = __str__ diff --git a/src/calibre/ebooks/oeb/polish/check/css.py b/src/calibre/ebooks/oeb/polish/check/css.py index 5e4987ae3e..8ea369e859 100644 --- a/src/calibre/ebooks/oeb/polish/check/css.py +++ b/src/calibre/ebooks/oeb/polish/check/css.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2020, Kovid Goyal import atexit @@ -148,7 +147,7 @@ class Worker(QWebEnginePage): self.pending = None def javaScriptConsoleMessage(self, level, msg, lineno, source_id): - msg = '{}:{}:{}'.format(source_id, lineno, msg) + msg = f'{source_id}:{lineno}:{msg}' self.console_messages.append(msg) try: print(msg) @@ -159,7 +158,7 @@ class Worker(QWebEnginePage): self.working = True self.console_messages = [] self.runJavaScript( - 'window.check_css({})'.format(json.dumps(src)), QWebEngineScript.ScriptWorldId.ApplicationWorld, self.check_done) + f'window.check_css({json.dumps(src)})', QWebEngineScript.ScriptWorldId.ApplicationWorld, self.check_done) def check_css_when_ready(self, src): if self.ready: diff --git a/src/calibre/ebooks/oeb/polish/check/fonts.py b/src/calibre/ebooks/oeb/polish/check/fonts.py index c942436084..247d667744 100644 --- a/src/calibre/ebooks/oeb/polish/check/fonts.py +++ b/src/calibre/ebooks/oeb/polish/check/fonts.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/oeb/polish/check/images.py b/src/calibre/ebooks/oeb/polish/check/images.py index 10cb4f1d86..47e82fb153 100644 --- a/src/calibre/ebooks/oeb/polish/check/images.py +++ b/src/calibre/ebooks/oeb/polish/check/images.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/oeb/polish/check/links.py b/src/calibre/ebooks/oeb/polish/check/links.py index 25041af698..5d1e0bc880 100644 --- a/src/calibre/ebooks/oeb/polish/check/links.py +++ b/src/calibre/ebooks/oeb/polish/check/links.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' @@ -439,7 +438,7 @@ def check_external_links(container, progress_callback=(lambda num, total:None), except Exception: ids = downloaded_html_ids[href] = frozenset() if frag not in ids: - ans.append((locations, ValueError('HTML anchor {} not found on the page'.format(frag)), full_href)) + ans.append((locations, ValueError(f'HTML anchor {frag} not found on the page'), full_href)) res.close() finally: done.append(None) diff --git a/src/calibre/ebooks/oeb/polish/check/main.py b/src/calibre/ebooks/oeb/polish/check/main.py index 4d84c5e5a8..1acc5bb9f4 100644 --- a/src/calibre/ebooks/oeb/polish/check/main.py +++ b/src/calibre/ebooks/oeb/polish/check/main.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/oeb/polish/check/opf.py b/src/calibre/ebooks/oeb/polish/check/opf.py index e2827e0a37..6e7625ff1e 100644 --- a/src/calibre/ebooks/oeb/polish/check/opf.py +++ b/src/calibre/ebooks/oeb/polish/check/opf.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/oeb/polish/check/parsing.py b/src/calibre/ebooks/oeb/polish/check/parsing.py index f626aa29c5..022369c568 100644 --- a/src/calibre/ebooks/oeb/polish/check/parsing.py +++ b/src/calibre/ebooks/oeb/polish/check/parsing.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/oeb/polish/container.py b/src/calibre/ebooks/oeb/polish/container.py index c7caf727b1..3bfa866237 100644 --- a/src/calibre/ebooks/oeb/polish/container.py +++ b/src/calibre/ebooks/oeb/polish/container.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:fdm=marker:ai # License: GPLv3 Copyright: 2013, Kovid Goyal @@ -410,11 +409,11 @@ class Container(ContainerBase): # {{{ raise ValueError('Renaming of %s is not allowed' % current_name) if self.exists(new_name) and (new_name == current_name or new_name.lower() != current_name.lower()): # The destination exists and does not differ from the current name only by case - raise ValueError('Cannot rename %s to %s as %s already exists' % (current_name, new_name, new_name)) + raise ValueError(f'Cannot rename {current_name} to {new_name} as {new_name} already exists') new_path = self.name_to_abspath(new_name) base = os.path.dirname(new_path) if os.path.isfile(base): - raise ValueError('Cannot rename %s to %s as %s is a file' % (current_name, new_name, base)) + raise ValueError(f'Cannot rename {current_name} to {new_name} as {base} is a file') if not os.path.exists(base): os.makedirs(base) old_path = parent_dir = self.name_to_abspath(current_name) @@ -1142,9 +1141,9 @@ class EpubContainer(Container): ans += ' 2' else: if not v.minor: - ans += ' {}'.format(v.major) + ans += f' {v.major}' else: - ans += ' {}.{}'.format(v.major, v.minor) + ans += f' {v.major}.{v.minor}' except Exception: pass return ans diff --git a/src/calibre/ebooks/oeb/polish/cover.py b/src/calibre/ebooks/oeb/polish/cover.py index 801068bfa1..46dc869e30 100644 --- a/src/calibre/ebooks/oeb/polish/cover.py +++ b/src/calibre/ebooks/oeb/polish/cover.py @@ -1,6 +1,3 @@ -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:fdm=marker:ai - - __license__ = 'GPL v3' __copyright__ = '2013, Kovid Goyal ' __docformat__ = 'restructuredtext en' @@ -501,7 +498,7 @@ def set_epub_cover(container, cover_path, report, options=None, image_callback=N if wrapped_image is not None: # The cover page is a simple wrapper around a single cover image, # we can remove it safely. - log('Existing cover page {} is a simple wrapper, removing it'.format(cover_page)) + log(f'Existing cover page {cover_page} is a simple wrapper, removing it') container.remove_item(cover_page) if wrapped_image != existing_image: if image_callback is not None and not image_callback_called: diff --git a/src/calibre/ebooks/oeb/polish/create.py b/src/calibre/ebooks/oeb/polish/create.py index 1add13275b..470bd8f7b0 100644 --- a/src/calibre/ebooks/oeb/polish/create.py +++ b/src/calibre/ebooks/oeb/polish/create.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/oeb/polish/css.py b/src/calibre/ebooks/oeb/polish/css.py index 9d0f83c450..bdae002c33 100644 --- a/src/calibre/ebooks/oeb/polish/css.py +++ b/src/calibre/ebooks/oeb/polish/css.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/oeb/polish/download.py b/src/calibre/ebooks/oeb/polish/download.py index e5e6d8185b..1ee8e42098 100644 --- a/src/calibre/ebooks/oeb/polish/download.py +++ b/src/calibre/ebooks/oeb/polish/download.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2016, Kovid Goyal @@ -150,9 +149,9 @@ def download_one(tdir, timeout, progress_report, data_uri_map, url): filename = sanitize_file_name(filename) mt = guess_type(filename) if mt in OEB_DOCS: - raise ValueError('The external resource {} looks like a HTML document ({})'.format(url, filename)) + raise ValueError(f'The external resource {url} looks like a HTML document ({filename})') if not mt or mt == 'application/octet-stream' or '.' not in filename: - raise ValueError('The external resource {} is not of a known type'.format(url)) + raise ValueError(f'The external resource {url} is not of a known type') return True, (url, filename, dest.name, mt) except Exception as err: return False, (url, as_unicode(err)) diff --git a/src/calibre/ebooks/oeb/polish/embed.py b/src/calibre/ebooks/oeb/polish/embed.py index cc0b08e461..c859473cd4 100644 --- a/src/calibre/ebooks/oeb/polish/embed.py +++ b/src/calibre/ebooks/oeb/polish/embed.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:fdm=marker:ai __license__ = 'GPL v3' @@ -142,7 +141,7 @@ def find_matching_font(fonts, weight='normal', style='normal', stretch='normal') def do_embed(container, font, report): from calibre.utils.fonts.scanner import font_scanner - report('Embedding font %s from %s' % (font['full_name'], font['path'])) + report('Embedding font {} from {}'.format(font['full_name'], font['path'])) data = font_scanner.get_font_data(font) fname = font['full_name'] ext = 'otf' if font['is_otf'] else 'ttf' @@ -236,7 +235,7 @@ def embed_all_fonts(container, stats, report): return False # Write out CSS - rules = [';\n\t'.join('%s: %s' % ( + rules = [';\n\t'.join('{}: {}'.format( k, '"%s"' % v if k == 'font-family' else v) for k, v in iteritems(rulel) if (k in props and props[k] != v and v != '400') or k == 'src') for rulel in rules] css = '\n\n'.join(['@font-face {\n\t%s\n}' % r for r in rules]) diff --git a/src/calibre/ebooks/oeb/polish/errors.py b/src/calibre/ebooks/oeb/polish/errors.py index 8ffd913ca1..4c1de5830a 100644 --- a/src/calibre/ebooks/oeb/polish/errors.py +++ b/src/calibre/ebooks/oeb/polish/errors.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:fdm=marker:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/oeb/polish/fonts.py b/src/calibre/ebooks/oeb/polish/fonts.py index f083021332..237f4df3d6 100644 --- a/src/calibre/ebooks/oeb/polish/fonts.py +++ b/src/calibre/ebooks/oeb/polish/fonts.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/oeb/polish/hyphenation.py b/src/calibre/ebooks/oeb/polish/hyphenation.py index d12dee6a18..1e63ed6e21 100644 --- a/src/calibre/ebooks/oeb/polish/hyphenation.py +++ b/src/calibre/ebooks/oeb/polish/hyphenation.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2019, Kovid Goyal from calibre.ebooks.oeb.base import OEB_DOCS diff --git a/src/calibre/ebooks/oeb/polish/images.py b/src/calibre/ebooks/oeb/polish/images.py index 7d325d92b9..f92a82e3be 100644 --- a/src/calibre/ebooks/oeb/polish/images.py +++ b/src/calibre/ebooks/oeb/polish/images.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2015, Kovid Goyal diff --git a/src/calibre/ebooks/oeb/polish/import_book.py b/src/calibre/ebooks/oeb/polish/import_book.py index b65c612b3c..8664467574 100644 --- a/src/calibre/ebooks/oeb/polish/import_book.py +++ b/src/calibre/ebooks/oeb/polish/import_book.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' @@ -27,7 +26,7 @@ def auto_fill_manifest(container): mitem = container.generate_item(name, unique_href=False) gname = container.href_to_name(mitem.get('href'), container.opf_name) if gname != name: - raise ValueError('This should never happen (gname=%r, name=%r, href=%r)' % (gname, name, mitem.get('href'))) + raise ValueError('This should never happen (gname={!r}, name={!r}, href={!r})'.format(gname, name, mitem.get('href'))) manifest_name_map[name] = mitem.get('id') manifest_id_map[mitem.get('id')] = name diff --git a/src/calibre/ebooks/oeb/polish/jacket.py b/src/calibre/ebooks/oeb/polish/jacket.py index 348a9eda8d..d5eee3514e 100644 --- a/src/calibre/ebooks/oeb/polish/jacket.py +++ b/src/calibre/ebooks/oeb/polish/jacket.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:fdm=marker:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/oeb/polish/main.py b/src/calibre/ebooks/oeb/polish/main.py index 746601ba69..43fac8ed43 100644 --- a/src/calibre/ebooks/oeb/polish/main.py +++ b/src/calibre/ebooks/oeb/polish/main.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:fdm=marker:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/oeb/polish/opf.py b/src/calibre/ebooks/oeb/polish/opf.py index 95e5a76cf4..f4448e2fda 100644 --- a/src/calibre/ebooks/oeb/polish/opf.py +++ b/src/calibre/ebooks/oeb/polish/opf.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/oeb/polish/parsing.py b/src/calibre/ebooks/oeb/polish/parsing.py index be85e69d43..5f47df916c 100644 --- a/src/calibre/ebooks/oeb/polish/parsing.py +++ b/src/calibre/ebooks/oeb/polish/parsing.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' @@ -28,8 +27,8 @@ def parse_html5(raw, decoder=None, log=None, discard_namespaces=False, line_numb raw = clean_xml_chars(raw) root = html5_parser.parse(raw, maybe_xhtml=not discard_namespaces, line_number_attr=linenumber_attribute, keep_doctype=False, sanitize_names=True) if (discard_namespaces and root.tag != 'html') or ( - not discard_namespaces and (root.tag != '{%s}%s' % (XHTML_NS, 'html') or root.prefix)): - raise ValueError('Failed to parse correctly, root has tag: %s and prefix: %s' % (root.tag, root.prefix)) + not discard_namespaces and (root.tag != '{{{}}}{}'.format(XHTML_NS, 'html') or root.prefix)): + raise ValueError(f'Failed to parse correctly, root has tag: {root.tag} and prefix: {root.prefix}') return root diff --git a/src/calibre/ebooks/oeb/polish/pretty.py b/src/calibre/ebooks/oeb/polish/pretty.py index 005699f964..071c29728f 100644 --- a/src/calibre/ebooks/oeb/polish/pretty.py +++ b/src/calibre/ebooks/oeb/polish/pretty.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/oeb/polish/replace.py b/src/calibre/ebooks/oeb/polish/replace.py index 6815554922..f8e60e50df 100644 --- a/src/calibre/ebooks/oeb/polish/replace.py +++ b/src/calibre/ebooks/oeb/polish/replace.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:fdm=marker:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/oeb/polish/report.py b/src/calibre/ebooks/oeb/polish/report.py index 1497c3005d..31b2e3da35 100644 --- a/src/calibre/ebooks/oeb/polish/report.py +++ b/src/calibre/ebooks/oeb/polish/report.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' @@ -287,8 +286,8 @@ def css_data(container, book_locale, result_data, *args): if ans is None: tag = elem.tag.rpartition('}')[-1] if elem.attrib: - attribs = ' '.join('%s="%s"' % (k, prepare_string_for_xml(elem.get(k, ''), True)) for k in elem.keys()) - return '<%s %s>' % (tag, attribs) + attribs = ' '.join('{}="{}"'.format(k, prepare_string_for_xml(elem.get(k, ''), True)) for k in elem.keys()) + return f'<{tag} {attribs}>' ans = tt_cache[elem] = '<%s>' % tag def matches_for_selector(selector, select, class_map, rule): diff --git a/src/calibre/ebooks/oeb/polish/spell.py b/src/calibre/ebooks/oeb/polish/spell.py index 7e7ede6764..bf7080e1a8 100644 --- a/src/calibre/ebooks/oeb/polish/spell.py +++ b/src/calibre/ebooks/oeb/polish/spell.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' @@ -64,7 +63,7 @@ class Location: self.location_node, self.node_item, self.sourceline = location_node, node_item, location_node.sourceline def __repr__(self): - return '%s @ %s:%s' % (self.original_word, self.file_name, self.sourceline) + return f'{self.original_word} @ {self.file_name}:{self.sourceline}' __str__ = __repr__ def replace(self, new_word): diff --git a/src/calibre/ebooks/oeb/polish/split.py b/src/calibre/ebooks/oeb/polish/split.py index 689f7ab3c7..47151d20f4 100644 --- a/src/calibre/ebooks/oeb/polish/split.py +++ b/src/calibre/ebooks/oeb/polish/split.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' @@ -231,12 +230,12 @@ def split(container, name, loc_or_xpath, before=True, totals=None): purl = urlparse(url) if purl.fragment in anchors_in_top: if r is root2: - a.set('href', '%s#%s' % (container.name_to_href(name, bottom_name), purl.fragment)) + a.set('href', f'{container.name_to_href(name, bottom_name)}#{purl.fragment}') else: a.set('href', '#' + purl.fragment) elif purl.fragment in anchors_in_bottom: if r is root1: - a.set('href', '%s#%s' % (container.name_to_href(bottom_name, name), purl.fragment)) + a.set('href', f'{container.name_to_href(bottom_name, name)}#{purl.fragment}') else: a.set('href', '#' + purl.fragment) diff --git a/src/calibre/ebooks/oeb/polish/stats.py b/src/calibre/ebooks/oeb/polish/stats.py index 028e24ab63..54d062c850 100644 --- a/src/calibre/ebooks/oeb/polish/stats.py +++ b/src/calibre/ebooks/oeb/polish/stats.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:fdm=marker:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/oeb/polish/subset.py b/src/calibre/ebooks/oeb/polish/subset.py index ffbbf7da27..64bca7ddd1 100644 --- a/src/calibre/ebooks/oeb/polish/subset.py +++ b/src/calibre/ebooks/oeb/polish/subset.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:fdm=marker:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/oeb/polish/tests/__init__.py b/src/calibre/ebooks/oeb/polish/tests/__init__.py index e4102b4b10..0cbf055ec8 100644 --- a/src/calibre/ebooks/oeb/polish/tests/__init__.py +++ b/src/calibre/ebooks/oeb/polish/tests/__init__.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/oeb/polish/tests/base.py b/src/calibre/ebooks/oeb/polish/tests/base.py index 791b5c4231..8cffaddd3b 100644 --- a/src/calibre/ebooks/oeb/polish/tests/base.py +++ b/src/calibre/ebooks/oeb/polish/tests/base.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' @@ -111,4 +110,4 @@ class BaseTest(unittest.TestCase): for link in container.iterlinks(name, get_line_numbers=False): dest = container.href_to_name(link, name) if dest: - self.assertTrue(container.exists(dest), 'The link %s in %s does not exist' % (link, name)) + self.assertTrue(container.exists(dest), f'The link {link} in {name} does not exist') diff --git a/src/calibre/ebooks/oeb/polish/tests/cascade.py b/src/calibre/ebooks/oeb/polish/tests/cascade.py index b56ea68286..aa7ca98cfa 100644 --- a/src/calibre/ebooks/oeb/polish/tests/cascade.py +++ b/src/calibre/ebooks/oeb/polish/tests/cascade.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' @@ -98,7 +97,7 @@ class CascadeTest(BaseTest): self.assertEqual(val, ans.cssText) def get_maps(html, styles=None, pseudo=False): - html = '{}'.format(html) + html = f'{html}' c = VirtualContainer({'index.html':html, 'styles.css':styles or 'body { color: red; font-family: "Kovid Goyal", sans-serif }'}) resolve_property, resolve_pseudo_property, select = resolve_styles(c, 'index.html') if pseudo: @@ -151,7 +150,7 @@ class CascadeTest(BaseTest): def get_stats(html, *fonts): styles = [] - html = '{}'.format(html) + html = f'{html}' files = {'index.html':html, 'X.otf':b'xxx', 'XB.otf': b'xbxb'} for font in fonts: styles.append('@font-face {') @@ -159,9 +158,9 @@ class CascadeTest(BaseTest): if k == 'src': files[v] = b'xxx' v = 'url(%s)' % v - styles.append('%s : %s;' % (k, v)) + styles.append(f'{k} : {v};') styles.append('}\n') - html = '{}'.format(html) + html = f'{html}' files['styles.css'] = embeds + '\n'.join(styles) c = VirtualContainer(files) return StatsCollector(c, do_embed=True) diff --git a/src/calibre/ebooks/oeb/polish/tests/container.py b/src/calibre/ebooks/oeb/polish/tests/container.py index 6da8d73388..b84f9973ac 100644 --- a/src/calibre/ebooks/oeb/polish/tests/container.py +++ b/src/calibre/ebooks/oeb/polish/tests/container.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/oeb/polish/tests/main.py b/src/calibre/ebooks/oeb/polish/tests/main.py index f8a78fb2b8..c383be43fa 100644 --- a/src/calibre/ebooks/oeb/polish/tests/main.py +++ b/src/calibre/ebooks/oeb/polish/tests/main.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/oeb/polish/tests/parsing.py b/src/calibre/ebooks/oeb/polish/tests/parsing.py index d7443ef739..25a8e65430 100644 --- a/src/calibre/ebooks/oeb/polish/tests/parsing.py +++ b/src/calibre/ebooks/oeb/polish/tests/parsing.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' @@ -39,7 +38,7 @@ def namespaces(test, parse_function): ae(len(matches), 1, err) ae(matches[0].prefix, prefix, err) - markup = ''' '''.format(xhtml=XHTML_NS) + markup = f''' ''' root = parse_function(markup) ae( len(XPath('//h:body[@id="test"]')(root)), 1, @@ -193,7 +192,7 @@ class ParsingTests(BaseTest): root = parse(src, discard_namespaces=ds) for tag, lnum in iteritems({'html':2, 'head':3, 'body':3, 'p':3, 'svg':4, 'image':4, 'b':5}): elem = root.xpath('//*[local-name()="%s"]' % tag)[0] - self.assertEqual(lnum, elem.sourceline, 'Line number incorrect for %s, source: %s:' % (tag, src)) + self.assertEqual(lnum, elem.sourceline, f'Line number incorrect for {tag}, source: {src}:') for ds in (False, True): src = '\n\n

\n' @@ -226,4 +225,4 @@ def timing(): f(raw) timings.append(monotonic() - st) avg = sum(timings)/len(timings) - print('Average time for %s: %.2g' % (name, avg)) + print(f'Average time for {name}: {avg:.2g}') diff --git a/src/calibre/ebooks/oeb/polish/tests/structure.py b/src/calibre/ebooks/oeb/polish/tests/structure.py index 4d575c73d5..912ea380ac 100644 --- a/src/calibre/ebooks/oeb/polish/tests/structure.py +++ b/src/calibre/ebooks/oeb/polish/tests/structure.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2016, Kovid Goyal @@ -42,7 +41,7 @@ cmi = create_manifest_item def create_epub(manifest, spine=(), guide=(), meta_cover=None, ver=3): mo = [] for name, data, properties in manifest: - mo.append('' % ( + mo.append(''.format( name, name, guess_type(name), ('properties="%s"' % properties if properties else ''))) mo = ''.join(mo) metadata = '' @@ -51,7 +50,7 @@ def create_epub(manifest, spine=(), guide=(), meta_cover=None, ver=3): if not spine: spine = [x[0] for x in manifest if guess_type(x[0]) in OEB_DOCS] spine = ''.join('' % name for name in spine) - guide = ''.join('' % (name, typ, title) for name, typ, title in guide) + guide = ''.join(f'' for name, typ, title in guide) opf = OPF_TEMPLATE.format(manifest=mo, ver='%d.0'%ver, metadata=metadata, spine=spine, guide=guide) buf = BytesIO() with ZipFile(buf, 'w', ZIP_STORED) as zf: diff --git a/src/calibre/ebooks/oeb/polish/toc.py b/src/calibre/ebooks/oeb/polish/toc.py index 99e525cfcc..a49a30567c 100644 --- a/src/calibre/ebooks/oeb/polish/toc.py +++ b/src/calibre/ebooks/oeb/polish/toc.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:fdm=marker:ai __license__ = 'GPL v3' @@ -355,7 +354,7 @@ def ensure_id(elem, all_ids): c = 0 while True: c += 1 - q = 'toc_{}'.format(c) + q = f'toc_{c}' if q not in all_ids: elem.set('id', q) all_ids.add(q) diff --git a/src/calibre/ebooks/oeb/polish/upgrade.py b/src/calibre/ebooks/oeb/polish/upgrade.py index 0aac8aaadb..f241a01ce2 100644 --- a/src/calibre/ebooks/oeb/polish/upgrade.py +++ b/src/calibre/ebooks/oeb/polish/upgrade.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2018, Kovid Goyal diff --git a/src/calibre/ebooks/oeb/polish/utils.py b/src/calibre/ebooks/oeb/polish/utils.py index added0bb97..25c6da7497 100644 --- a/src/calibre/ebooks/oeb/polish/utils.py +++ b/src/calibre/ebooks/oeb/polish/utils.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/oeb/reader.py b/src/calibre/ebooks/oeb/reader.py index 961187a91a..ba48e805e9 100644 --- a/src/calibre/ebooks/oeb/reader.py +++ b/src/calibre/ebooks/oeb/reader.py @@ -89,10 +89,10 @@ class OEBReader: continue if namespace(elem.tag) in DC_NSES: tag = barename(elem.tag).lower() - elem.tag = '{%s}%s' % (DC11_NS, tag) + elem.tag = f'{{{DC11_NS}}}{tag}' if elem.tag.startswith('dc:'): tag = elem.tag.partition(':')[-1].lower() - elem.tag = '{%s}%s' % (DC11_NS, tag) + elem.tag = f'{{{DC11_NS}}}{tag}' metadata.append(elem) for element in xpath(opf, 'o2:metadata//o2:meta'): metadata.append(element) diff --git a/src/calibre/ebooks/oeb/stylizer.py b/src/calibre/ebooks/oeb/stylizer.py index 55551116f3..43c0358a0a 100644 --- a/src/calibre/ebooks/oeb/stylizer.py +++ b/src/calibre/ebooks/oeb/stylizer.py @@ -1,6 +1,3 @@ -# -*- encoding: utf-8 -*- - - ''' CSS property propagation class. ''' @@ -312,7 +309,7 @@ class Stylizer: try: matches = tuple(select(text)) except SelectorError as err: - self.logger.error('Ignoring CSS rule with invalid selector: %r (%s)' % (text, as_unicode(err))) + self.logger.error(f'Ignoring CSS rule with invalid selector: {text!r} ({as_unicode(err)})') continue if fl is not None: @@ -403,7 +400,7 @@ class Stylizer: size = float(style['font-size'][:-2]) style['font-size'] = "%.2fpt" % (size * font_scale) style = ';\n '.join(': '.join(item) for item in style.items()) - rules.append('%s {\n %s;\n}' % (selector, style)) + rules.append(f'{selector} {{\n {style};\n}}') return '\n'.join(rules) @@ -798,7 +795,7 @@ class Style: def __str__(self): items = sorted(iteritems(self._style)) - return '; '.join("%s: %s" % (key, val) for key, val in items) + return '; '.join(f"{key}: {val}" for key, val in items) def cssdict(self): return dict(self._style) diff --git a/src/calibre/ebooks/oeb/transforms/__init__.py b/src/calibre/ebooks/oeb/transforms/__init__.py index d8edc6064a..872a71567f 100644 --- a/src/calibre/ebooks/oeb/transforms/__init__.py +++ b/src/calibre/ebooks/oeb/transforms/__init__.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/oeb/transforms/cover.py b/src/calibre/ebooks/oeb/transforms/cover.py index ccbd567f95..4275e3168e 100644 --- a/src/calibre/ebooks/oeb/transforms/cover.py +++ b/src/calibre/ebooks/oeb/transforms/cover.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/oeb/transforms/data_url.py b/src/calibre/ebooks/oeb/transforms/data_url.py index 7c580f3512..fedbf8a65c 100644 --- a/src/calibre/ebooks/oeb/transforms/data_url.py +++ b/src/calibre/ebooks/oeb/transforms/data_url.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/oeb/transforms/embed_fonts.py b/src/calibre/ebooks/oeb/transforms/embed_fonts.py index 6e7780e409..a10d0d1813 100644 --- a/src/calibre/ebooks/oeb/transforms/embed_fonts.py +++ b/src/calibre/ebooks/oeb/transforms/embed_fonts.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 __license__ = 'GPL v3' @@ -235,7 +234,7 @@ class EmbedFonts: item.unload_data_from_memory() page_sheet = self.get_page_sheet() href = page_sheet.relhref(item.href) - css = '''@font-face { font-family: "%s"; font-weight: %s; font-style: %s; font-stretch: %s; src: url(%s) }''' % ( + css = '''@font-face {{ font-family: "{}"; font-weight: {}; font-style: {}; font-stretch: {}; src: url({}) }}'''.format( f['font-family'], f['font-weight'], f['font-style'], f['font-stretch'], href) sheet = self.parser.parseString(css, validate=False) page_sheet.data.insertRule(sheet.cssRules[0], len(page_sheet.data.cssRules)) @@ -243,7 +242,7 @@ class EmbedFonts: for f in fonts: if f['weight'] == weight and f['font-style'] == style.get('font-style', 'normal') and f['font-stretch'] == style.get('font-stretch', 'normal'): - self.log('Embedding font %s from %s' % (f['full_name'], f['path'])) + self.log('Embedding font {} from {}'.format(f['full_name'], f['path'])) return do_embed(f) try: f = find_matching_font(fonts, style.get('font-weight', 'normal'), style.get('font-style', 'normal'), style.get('font-stretch', 'normal')) @@ -252,5 +251,5 @@ class EmbedFonts: self.log.exception('Failed to find a matching font for family', ff, 'not embedding') self.warned2.add(ff) return - self.log('Embedding font %s from %s' % (f['full_name'], f['path'])) + self.log('Embedding font {} from {}'.format(f['full_name'], f['path'])) return do_embed(f) diff --git a/src/calibre/ebooks/oeb/transforms/filenames.py b/src/calibre/ebooks/oeb/transforms/filenames.py index 1986b1db75..36b55a30ce 100644 --- a/src/calibre/ebooks/oeb/transforms/filenames.py +++ b/src/calibre/ebooks/oeb/transforms/filenames.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/oeb/transforms/flatcss.py b/src/calibre/ebooks/oeb/transforms/flatcss.py index e9ee981765..11f36dd9a3 100644 --- a/src/calibre/ebooks/oeb/transforms/flatcss.py +++ b/src/calibre/ebooks/oeb/transforms/flatcss.py @@ -332,7 +332,7 @@ class CSSFlattener: dlineh = self.lineh for kind in ('margin', 'padding'): for edge in ('bottom', 'top'): - property = "%s-%s" % (kind, edge) + property = f"{kind}-{edge}" if property not in cssdict: continue if '%' in cssdict[property]: @@ -529,7 +529,7 @@ class CSSFlattener: if cssdict: items = sorted(iteritems(cssdict)) - css = ';\n'.join('%s: %s' % (key, val) for key, val in items) + css = ';\n'.join(f'{key}: {val}' for key, val in items) classes = node.get('class', '').strip() or 'calibre' classes_list = classes.split() # lower() because otherwise if the document uses the same class @@ -547,7 +547,7 @@ class CSSFlattener: for psel, cssdict in iteritems(pseudo_classes): items = sorted(iteritems(cssdict)) - css = ';\n'.join('%s: %s' % (key, val) for key, val in items) + css = ';\n'.join(f'{key}: {val}' for key, val in items) pstyles = pseudo_styles[psel] if css in pstyles: match = pstyles[css] @@ -627,7 +627,7 @@ class CSSFlattener: stylizer.page_rule['margin-bottom'] = '%gpt'%\ float(self.context.margin_bottom) items = sorted(stylizer.page_rule.items()) - css = ';\n'.join("%s: %s" % (key, val) for key, val in items) + css = ';\n'.join(f"{key}: {val}" for key, val in items) css = ('@page {\n%s\n}\n'%css) if items else '' rules = [css_text(r) for r in stylizer.font_face_rules + self.embed_font_rules] raw = '\n\n'.join(rules) @@ -675,7 +675,7 @@ class CSSFlattener: x = sorted(((k+':'+psel, v) for v, k in iteritems(styles))) items.extend(x) - css = ''.join(".%s {\n%s;\n}\n\n" % (key, val) for key, val in items) + css = ''.join(f".{key} {{\n{val};\n}}\n\n" for key, val in items) href = self.replace_css(css) global_css = self.collect_global_css() diff --git a/src/calibre/ebooks/oeb/transforms/guide.py b/src/calibre/ebooks/oeb/transforms/guide.py index 50c0083e2c..28ab75b3c6 100644 --- a/src/calibre/ebooks/oeb/transforms/guide.py +++ b/src/calibre/ebooks/oeb/transforms/guide.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/oeb/transforms/jacket.py b/src/calibre/ebooks/oeb/transforms/jacket.py index fc621a032f..70ce8b3820 100644 --- a/src/calibre/ebooks/oeb/transforms/jacket.py +++ b/src/calibre/ebooks/oeb/transforms/jacket.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' @@ -386,7 +385,7 @@ def render_jacket(mi, output_profile, print("Custom column values available in jacket template:") for key in args.keys(): if key.startswith('_') and not key.endswith('_label'): - print(" %s: %s" % ('#' + key[1:], args[key])) + print(" {}: {}".format('#' + key[1:], args[key])) # Used in the comment describing use of custom columns in templates # Don't change this unless you also change it in template.xhtml diff --git a/src/calibre/ebooks/oeb/transforms/linearize_tables.py b/src/calibre/ebooks/oeb/transforms/linearize_tables.py index 12dc0c4417..3578614dba 100644 --- a/src/calibre/ebooks/oeb/transforms/linearize_tables.py +++ b/src/calibre/ebooks/oeb/transforms/linearize_tables.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/oeb/transforms/metadata.py b/src/calibre/ebooks/oeb/transforms/metadata.py index 735b1981f6..12a3ce2dfa 100644 --- a/src/calibre/ebooks/oeb/transforms/metadata.py +++ b/src/calibre/ebooks/oeb/transforms/metadata.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/oeb/transforms/page_margin.py b/src/calibre/ebooks/oeb/transforms/page_margin.py index 0f4190e487..07392d6c4a 100644 --- a/src/calibre/ebooks/oeb/transforms/page_margin.py +++ b/src/calibre/ebooks/oeb/transforms/page_margin.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/oeb/transforms/rescale.py b/src/calibre/ebooks/oeb/transforms/rescale.py index 54023158ee..958a013316 100644 --- a/src/calibre/ebooks/oeb/transforms/rescale.py +++ b/src/calibre/ebooks/oeb/transforms/rescale.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/oeb/transforms/split.py b/src/calibre/ebooks/oeb/transforms/split.py index ff42b8666a..b6b4ea55b4 100644 --- a/src/calibre/ebooks/oeb/transforms/split.py +++ b/src/calibre/ebooks/oeb/transforms/split.py @@ -118,7 +118,7 @@ class Split: elem.set('pb_before', '1' if before else '0') page_breaks.add(elem) except SelectorError as err: - self.log.warn('Ignoring page breaks specified with invalid CSS selector: %r (%s)' % (selector, as_unicode(err))) + self.log.warn(f'Ignoring page breaks specified with invalid CSS selector: {selector!r} ({as_unicode(err)})') for i, elem in enumerate(item.data.iter('*')): try: diff --git a/src/calibre/ebooks/oeb/transforms/structure.py b/src/calibre/ebooks/oeb/transforms/structure.py index 53551feda7..161bdc1a98 100644 --- a/src/calibre/ebooks/oeb/transforms/structure.py +++ b/src/calibre/ebooks/oeb/transforms/structure.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/oeb/transforms/subset.py b/src/calibre/ebooks/oeb/transforms/subset.py index 0e62aff9b4..a11f295a7f 100644 --- a/src/calibre/ebooks/oeb/transforms/subset.py +++ b/src/calibre/ebooks/oeb/transforms/subset.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:fdm=marker:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/oeb/transforms/unsmarten.py b/src/calibre/ebooks/oeb/transforms/unsmarten.py index 2f77bbeeea..a26d2529eb 100644 --- a/src/calibre/ebooks/oeb/transforms/unsmarten.py +++ b/src/calibre/ebooks/oeb/transforms/unsmarten.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - __license__ = 'GPL 3' __copyright__ = '2011, John Schember ' __docformat__ = 'restructuredtext en' diff --git a/src/calibre/ebooks/pdb/__init__.py b/src/calibre/ebooks/pdb/__init__.py index 059cebda30..12d74a04a8 100644 --- a/src/calibre/ebooks/pdb/__init__.py +++ b/src/calibre/ebooks/pdb/__init__.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - __license__ = 'GPL v3' __copyright__ = '2009, John Schember ' __docformat__ = 'restructuredtext en' diff --git a/src/calibre/ebooks/pdb/ereader/__init__.py b/src/calibre/ebooks/pdb/ereader/__init__.py index 4d8c509cec..818d7f7ecc 100644 --- a/src/calibre/ebooks/pdb/ereader/__init__.py +++ b/src/calibre/ebooks/pdb/ereader/__init__.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - __license__ = 'GPL v3' __copyright__ = '2009, John Schember ' __docformat__ = 'restructuredtext en' @@ -19,12 +16,12 @@ def image_name(name, taken_names=()): cut = len(name) - 32 names = name[:10] namee = name[10+cut:] - name = '%s%s.png' % (names, namee) + name = f'{names}{namee}.png' i = 0 base_name, ext = os.path.splitext(name) while name in taken_names: i += 1 - name = '%s%s%s' % (base_name, i, ext) + name = f'{base_name}{i}{ext}' return name.ljust(32, '\x00')[:32] diff --git a/src/calibre/ebooks/pdb/ereader/inspector.py b/src/calibre/ebooks/pdb/ereader/inspector.py index ebd112e64f..975c413467 100644 --- a/src/calibre/ebooks/pdb/ereader/inspector.py +++ b/src/calibre/ebooks/pdb/ereader/inspector.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- ''' Inspect the header of ereader files. This is primarily used for debugging. ''' diff --git a/src/calibre/ebooks/pdb/ereader/reader.py b/src/calibre/ebooks/pdb/ereader/reader.py index 15a39070e2..fd547e6c2b 100644 --- a/src/calibre/ebooks/pdb/ereader/reader.py +++ b/src/calibre/ebooks/pdb/ereader/reader.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - ''' Read content from ereader pdb file. ''' diff --git a/src/calibre/ebooks/pdb/ereader/reader132.py b/src/calibre/ebooks/pdb/ereader/reader132.py index 4e653de423..16c35b8345 100644 --- a/src/calibre/ebooks/pdb/ereader/reader132.py +++ b/src/calibre/ebooks/pdb/ereader/reader132.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - ''' Read content from ereader pdb file with a 132 byte header created by Dropbook. ''' diff --git a/src/calibre/ebooks/pdb/ereader/reader202.py b/src/calibre/ebooks/pdb/ereader/reader202.py index 9ecec974af..152b3d17e9 100644 --- a/src/calibre/ebooks/pdb/ereader/reader202.py +++ b/src/calibre/ebooks/pdb/ereader/reader202.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - ''' Read content from ereader pdb file with a 116 and 202 byte header created by Makebook. ''' diff --git a/src/calibre/ebooks/pdb/ereader/writer.py b/src/calibre/ebooks/pdb/ereader/writer.py index 03f6551d58..385681238a 100644 --- a/src/calibre/ebooks/pdb/ereader/writer.py +++ b/src/calibre/ebooks/pdb/ereader/writer.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - ''' Write content to ereader pdb file. ''' @@ -186,7 +183,7 @@ class Writer(FormatWriter): if len(metadata.publisher) >= 1: publisher = metadata.publisher[0].value - return as_bytes('%s\x00%s\x00%s\x00%s\x00%s\x00' % (title, author, copyright, publisher, isbn)) + return as_bytes(f'{title}\x00{author}\x00{copyright}\x00{publisher}\x00{isbn}\x00') def _header_record(self, text_count, chapter_count, link_count, image_count): ''' diff --git a/src/calibre/ebooks/pdb/formatreader.py b/src/calibre/ebooks/pdb/formatreader.py index a201a7dd3d..9581c51c6f 100644 --- a/src/calibre/ebooks/pdb/formatreader.py +++ b/src/calibre/ebooks/pdb/formatreader.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - ''' Interface defining the necessary public functions for a pdb format reader. ''' diff --git a/src/calibre/ebooks/pdb/formatwriter.py b/src/calibre/ebooks/pdb/formatwriter.py index b9c90c9922..015d0e3672 100644 --- a/src/calibre/ebooks/pdb/formatwriter.py +++ b/src/calibre/ebooks/pdb/formatwriter.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - ''' Interface defining the necessary public functions for a pdb format writer. ''' diff --git a/src/calibre/ebooks/pdb/haodoo/__init__.py b/src/calibre/ebooks/pdb/haodoo/__init__.py index 6b2910c3df..c2a96b7708 100644 --- a/src/calibre/ebooks/pdb/haodoo/__init__.py +++ b/src/calibre/ebooks/pdb/haodoo/__init__.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/pdb/haodoo/reader.py b/src/calibre/ebooks/pdb/haodoo/reader.py index cdf3400dd3..d308cb98ef 100644 --- a/src/calibre/ebooks/pdb/haodoo/reader.py +++ b/src/calibre/ebooks/pdb/haodoo/reader.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - ''' Read content from Haodoo.net pdb file. ''' diff --git a/src/calibre/ebooks/pdb/header.py b/src/calibre/ebooks/pdb/header.py index b85be834a1..b4acdf0e5a 100644 --- a/src/calibre/ebooks/pdb/header.py +++ b/src/calibre/ebooks/pdb/header.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - ''' Read the header data from a pdb file. ''' diff --git a/src/calibre/ebooks/pdb/palmdoc/reader.py b/src/calibre/ebooks/pdb/palmdoc/reader.py index 63953a27b7..4dd0a2a113 100644 --- a/src/calibre/ebooks/pdb/palmdoc/reader.py +++ b/src/calibre/ebooks/pdb/palmdoc/reader.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - ''' Read content from palmdoc pdb file. ''' diff --git a/src/calibre/ebooks/pdb/palmdoc/writer.py b/src/calibre/ebooks/pdb/palmdoc/writer.py index 90d57313df..43de51e008 100644 --- a/src/calibre/ebooks/pdb/palmdoc/writer.py +++ b/src/calibre/ebooks/pdb/palmdoc/writer.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - ''' Writer content to palmdoc pdb file. ''' diff --git a/src/calibre/ebooks/pdb/pdf/reader.py b/src/calibre/ebooks/pdb/pdf/reader.py index 5b6a022035..936eda4670 100644 --- a/src/calibre/ebooks/pdb/pdf/reader.py +++ b/src/calibre/ebooks/pdb/pdf/reader.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - ''' Read content from palmdoc pdb file. ''' diff --git a/src/calibre/ebooks/pdb/plucker/reader.py b/src/calibre/ebooks/pdb/plucker/reader.py index fa7af3cb44..35a45c8a5c 100644 --- a/src/calibre/ebooks/pdb/plucker/reader.py +++ b/src/calibre/ebooks/pdb/plucker/reader.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - __license__ = 'GPL v3' __copyright__ = '20011, John Schember ' __docformat__ = 'restructuredtext en' @@ -363,7 +360,7 @@ class Reader(FormatReader): # plugin assemble the order based on hyperlinks. with CurrentDir(output_dir): for uid, num in self.uid_text_secion_number.items(): - self.log.debug('Writing record with uid: %s as %s.html' % (uid, uid)) + self.log.debug(f'Writing record with uid: {uid} as {uid}.html') with open('%s.html' % uid, 'wb') as htmlf: html = '' section_header, section_data = self.sections[num] @@ -396,9 +393,9 @@ class Reader(FormatReader): try: save_cover_data_to(idata, '%s.jpg' % uid, compression_quality=70) images.add(uid) - self.log.debug('Wrote image with uid %s to images/%s.jpg' % (uid, uid)) + self.log.debug(f'Wrote image with uid {uid} to images/{uid}.jpg') except Exception as e: - self.log.error('Failed to write image with uid %s: %s' % (uid, e)) + self.log.error(f'Failed to write image with uid {uid}: {e}') else: self.log.error('Failed to write image with uid %s: No data.' % uid) # Composite images. @@ -439,9 +436,9 @@ class Reader(FormatReader): y_off += largest_height with lopen('%s.jpg' % uid) as out: out.write(canvas.export(compression_quality=70)) - self.log.debug('Wrote composite image with uid %s to images/%s.jpg' % (uid, uid)) + self.log.debug(f'Wrote composite image with uid {uid} to images/{uid}.jpg') except Exception as e: - self.log.error('Failed to write composite image with uid %s: %s' % (uid, e)) + self.log.error(f'Failed to write composite image with uid {uid}: {e}') # Run the HTML through the html processing plugin. from calibre.customize.ui import plugin_for_input_format @@ -524,7 +521,7 @@ class Reader(FormatReader): offset += 2 pid = struct.unpack('>H', d[offset:offset+2])[0] if id in self.uid_text_secion_number: - html += '' % (id, pid) + html += f'' link_open = True offset += 1 # Targeted paragraph link begins diff --git a/src/calibre/ebooks/pdb/ztxt/__init__.py b/src/calibre/ebooks/pdb/ztxt/__init__.py index 9c80210a38..93d954254e 100644 --- a/src/calibre/ebooks/pdb/ztxt/__init__.py +++ b/src/calibre/ebooks/pdb/ztxt/__init__.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - __license__ = 'GPL v3' __copyright__ = '2009, John Schember ' __docformat__ = 'restructuredtext en' diff --git a/src/calibre/ebooks/pdb/ztxt/reader.py b/src/calibre/ebooks/pdb/ztxt/reader.py index 21df8ddc95..ef0ebebc2b 100644 --- a/src/calibre/ebooks/pdb/ztxt/reader.py +++ b/src/calibre/ebooks/pdb/ztxt/reader.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - ''' Read content from ztxt pdb file. ''' diff --git a/src/calibre/ebooks/pdb/ztxt/writer.py b/src/calibre/ebooks/pdb/ztxt/writer.py index 0f18ab8b77..4a75c471d8 100644 --- a/src/calibre/ebooks/pdb/ztxt/writer.py +++ b/src/calibre/ebooks/pdb/ztxt/writer.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - ''' Writer content to ztxt pdb file. ''' diff --git a/src/calibre/ebooks/pdf/develop.py b/src/calibre/ebooks/pdf/develop.py index b190dc166e..9732fd9d8c 100644 --- a/src/calibre/ebooks/pdf/develop.py +++ b/src/calibre/ebooks/pdf/develop.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2019, Kovid Goyal diff --git a/src/calibre/ebooks/pdf/html_writer.py b/src/calibre/ebooks/pdf/html_writer.py index d3bd5b0d5e..ecf8b1304b 100644 --- a/src/calibre/ebooks/pdf/html_writer.py +++ b/src/calibre/ebooks/pdf/html_writer.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2019, Kovid Goyal # Imports {{{ @@ -190,7 +189,7 @@ class Renderer(QWebEnginePage): self.load_hang_check_timer.start() def on_load_hang(self): - self.log(self.log_prefix, 'Loading not complete after {} seconds, aborting.'.format(int(monotonic() - self.load_started_at))) + self.log(self.log_prefix, f'Loading not complete after {int(monotonic() - self.load_started_at)} seconds, aborting.') self.load_finished(False) def title_changed(self, title): @@ -206,7 +205,7 @@ class Renderer(QWebEnginePage): self.load_hang_check_timer.stop() if not ok: self.working = False - self.work_done.emit(self, 'Load of {} failed'.format(self.url().toString())) + self.work_done.emit(self, f'Load of {self.url().toString()} failed') return if self.wait_for_title and self.title() != self.wait_for_title: self.log(self.log_prefix, 'Load finished, waiting for title to change to:', self.wait_for_title) @@ -215,7 +214,7 @@ class Renderer(QWebEnginePage): def javaScriptConsoleMessage(self, level, message, linenum, source_id): try: - self.log('{}:{}:{}'.format(source_id, linenum, message)) + self.log(f'{source_id}:{linenum}:{message}') except Exception: pass @@ -245,18 +244,18 @@ class RequestInterceptor(QWebEngineUrlRequestInterceptor): def interceptRequest(self, request_info): method = bytes(request_info.requestMethod()) if method not in (b'GET', b'HEAD'): - self.log.warn('Blocking URL request with method: {}'.format(method)) + self.log.warn(f'Blocking URL request with method: {method}') request_info.block(True) return qurl = request_info.requestUrl() if qurl.scheme() != 'file': - self.log.warn('Blocking URL request with scheme: {}'.format(qurl.scheme())) + self.log.warn(f'Blocking URL request with scheme: {qurl.scheme()}') request_info.block(True) return path = qurl.toLocalFile() path = os.path.normcase(os.path.abspath(path)) if not path.startswith(self.container_root) and not path.startswith(self.resources_root): - self.log.warn('Blocking request with path: {}'.format(path)) + self.log.warn(f'Blocking request with path: {path}') request_info.block(True) return @@ -502,7 +501,7 @@ def make_anchors_unique(container, log): new_frag = mapping.get(key) if new_frag is None: if name in spine_names: - log.warn('Link anchor: {}#{} not found, linking to top of file instead'.format(name, frag)) + log.warn(f'Link anchor: {name}#{frag} not found, linking to top of file instead') replacer.replaced = True return 'https://calibre-pdf-anchor.n#' + name return url.rstrip('#') @@ -520,12 +519,12 @@ def make_anchors_unique(container, log): count += 1 key = spine_name, elem.get('id') if key not in mapping: - new_id = mapping[key] = 'a{}'.format(count) + new_id = mapping[key] = f'a{count}' elem.set('id', new_id) body = last_tag(root) if not body.get('id'): count += 1 - body.set('id', 'a{}'.format(count)) + body.set('id', f'a{count}') name_anchor_map[spine_name] = body.get('id') for name in container.mime_map: @@ -558,7 +557,7 @@ def get_anchor_locations(name, pdf_doc, first_page_num, toc_uuid, log): except KeyError: toc_pagenum = None if toc_pagenum is None: - log.warn('Failed to find ToC anchor in {}'.format(name)) + log.warn(f'Failed to find ToC anchor in {name}') toc_pagenum = 0 if toc_pagenum > 1: pdf_doc.delete_pages(toc_pagenum, pdf_doc.page_count() - toc_pagenum + 1) @@ -579,11 +578,11 @@ def fix_links(pdf_doc, anchor_locations, name_anchor_map, mark_links, log): if purl.netloc == 'calibre-pdf-anchor.a': loc = anchor_locations.get(purl.fragment) if loc is None: - log.warn('Anchor location for link to {} not found'.format(purl.fragment)) + log.warn(f'Anchor location for link to {purl.fragment} not found') else: loc = anchor_locations.get(name_anchor_map.get(purl.fragment)) if loc is None: - log.warn('Anchor location for link to {} not found'.format(purl.fragment)) + log.warn(f'Anchor location for link to {purl.fragment} not found') return None if loc is None else loc.as_tuple pdf_doc.alter_links(replace_link, mark_links) @@ -614,7 +613,7 @@ def annotate_toc(toc, anchor_locations, name_anchor_map, log): else: loc = anchor_locations[frag] except Exception: - log.warn('Could not find anchor location for ToC entry: {} with href: {}'.format(child.title, frag)) + log.warn(f'Could not find anchor location for ToC entry: {child.title} with href: {frag}') loc = AnchorLocation(1, 0, 0, 0) child.pdf_loc = loc @@ -652,7 +651,7 @@ def get_page_number_display_map(render_manager, opts, num_pages, log): if not isinstance(result, dict): raise ValueError('Not a dict') except Exception: - log.warn('Could not do page number mapping, got unexpected result: {}'.format(repr(result))) + log.warn(f'Could not do page number mapping, got unexpected result: {repr(result)}') else: default_map = {int(k): int(v) for k, v in iteritems(result)} return default_map @@ -701,7 +700,7 @@ def add_pagenum_toc(root, toc, opts, page_number_display_map): E('td', text=node.title or _('Unknown'), parent=tr) num = node.pdf_loc.pagenum num = page_number_display_map.get(num, num) - E('td', text='{}'.format(num), parent=tr) + E('td', text=f'{num}', parent=tr) # }}} @@ -833,7 +832,7 @@ def add_header_footer(manager, opts, pdf_doc, container, page_number_display_map if text is not None: ans.text = text if style is not None: - style = '; '.join('{}: {}'.format(k, v) for k, v in iteritems(style)) + style = '; '.join(f'{k}: {v}' for k, v in iteritems(style)) ans.set('style', style) return ans @@ -919,8 +918,8 @@ def add_header_footer(manager, opts, pdf_doc, container, page_number_display_map 'flex-direction': 'column', 'height': '100vh', 'justify-content': justify, - 'margin-left': '{}pt'.format(margins.left), - 'margin-right': '{}pt'.format(margins.right), + 'margin-left': f'{margins.left}pt', + 'margin-right': f'{margins.right}pt', 'margin-top': '0', 'margin-bottom': '0', 'padding': '0', @@ -929,7 +928,7 @@ def add_header_footer(manager, opts, pdf_doc, container, page_number_display_map 'background-color': 'unset', } - ans = m('div', style=style, id='p{}'.format(page_num)) + ans = m('div', style=style, id=f'p{page_num}') return ans def format_template(template, page_num, height): diff --git a/src/calibre/ebooks/pdf/image_writer.py b/src/calibre/ebooks/pdf/image_writer.py index 12c2e8bb1e..0e84b59a7a 100644 --- a/src/calibre/ebooks/pdf/image_writer.py +++ b/src/calibre/ebooks/pdf/image_writer.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2019, Kovid Goyal diff --git a/src/calibre/ebooks/pdf/pageoptions.py b/src/calibre/ebooks/pdf/pageoptions.py index 7d74452fce..514c1830a1 100644 --- a/src/calibre/ebooks/pdf/pageoptions.py +++ b/src/calibre/ebooks/pdf/pageoptions.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - __license__ = 'GPL 3' __copyright__ = '2009, John Schember ' __docformat__ = 'restructuredtext en' diff --git a/src/calibre/ebooks/pdf/pdftohtml.py b/src/calibre/ebooks/pdf/pdftohtml.py index 7d1244b46c..7fb4345840 100644 --- a/src/calibre/ebooks/pdf/pdftohtml.py +++ b/src/calibre/ebooks/pdf/pdftohtml.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2008, Kovid Goyal import errno diff --git a/src/calibre/ebooks/pdf/reflow.py b/src/calibre/ebooks/pdf/reflow.py index 7aec7f8458..4169f63c95 100644 --- a/src/calibre/ebooks/pdf/reflow.py +++ b/src/calibre/ebooks/pdf/reflow.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/pdf/render/__init__.py b/src/calibre/ebooks/pdf/render/__init__.py index 3610d3374c..fba7748a38 100644 --- a/src/calibre/ebooks/pdf/render/__init__.py +++ b/src/calibre/ebooks/pdf/render/__init__.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:fdm=marker:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/pdf/render/common.py b/src/calibre/ebooks/pdf/render/common.py index 71205f19d9..6c64fdd5c2 100644 --- a/src/calibre/ebooks/pdf/render/common.py +++ b/src/calibre/ebooks/pdf/render/common.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:fdm=marker:ai __license__ = 'GPL v3' @@ -91,7 +90,7 @@ class Name(str): sharp = ord(b'#') buf = ( codepoint_to_chr(x).encode('ascii') if 33 < x < 126 and x != sharp else - '#{:x}'.format(x).encode('ascii') for x in raw) + f'#{x:x}'.encode('ascii') for x in raw) stream.write(b'/'+b''.join(buf)) diff --git a/src/calibre/ebooks/pdf/render/fonts.py b/src/calibre/ebooks/pdf/render/fonts.py index 5ddd7e4f2f..6f59ac9ee0 100644 --- a/src/calibre/ebooks/pdf/render/fonts.py +++ b/src/calibre/ebooks/pdf/render/fonts.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:fdm=marker:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/pdf/render/gradients.py b/src/calibre/ebooks/pdf/render/gradients.py index f2d6d88440..4880d25f16 100644 --- a/src/calibre/ebooks/pdf/render/gradients.py +++ b/src/calibre/ebooks/pdf/render/gradients.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:fdm=marker:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/pdf/render/graphics.py b/src/calibre/ebooks/pdf/render/graphics.py index 0278cf7512..2d28f9a830 100644 --- a/src/calibre/ebooks/pdf/render/graphics.py +++ b/src/calibre/ebooks/pdf/render/graphics.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:fdm=marker:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/pdf/render/links.py b/src/calibre/ebooks/pdf/render/links.py index 60c59f826a..7425fbbf47 100644 --- a/src/calibre/ebooks/pdf/render/links.py +++ b/src/calibre/ebooks/pdf/render/links.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:fdm=marker:ai __license__ = 'GPL v3' @@ -26,7 +25,7 @@ class Destination(Array): pos['left'] = pos['top'] = 0 q -= 1 if q != pnum: - current_log().warn('Could not find page {} for link destination, using page {} instead'.format(pnum, q)) + current_log().warn(f'Could not find page {pnum} for link destination, using page {q} instead') super().__init__([ pref, Name('XYZ'), pos['left'], pos['top'], None ]) diff --git a/src/calibre/ebooks/pdf/render/serialize.py b/src/calibre/ebooks/pdf/render/serialize.py index c922da96a5..5b2aafe4ce 100644 --- a/src/calibre/ebooks/pdf/render/serialize.py +++ b/src/calibre/ebooks/pdf/render/serialize.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:fdm=marker:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/pml/__init__.py b/src/calibre/ebooks/pml/__init__.py index 3670569966..569247ccba 100644 --- a/src/calibre/ebooks/pml/__init__.py +++ b/src/calibre/ebooks/pml/__init__.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - __license__ = 'GPL v3' __copyright__ = '2009, John Schember ' __docformat__ = 'restructuredtext en' diff --git a/src/calibre/ebooks/pml/pmlconverter.py b/src/calibre/ebooks/pml/pmlconverter.py index 1cab2ea247..0e361258ba 100644 --- a/src/calibre/ebooks/pml/pmlconverter.py +++ b/src/calibre/ebooks/pml/pmlconverter.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - ''' Convert pml markup to and from html ''' @@ -223,9 +220,9 @@ class PML_HTMLizer: for key in self.STATES_TAGS: open, close = self.STATES_TAGS[key] if key in self.STATES_VALUE_REQ: - html = re.sub(r'(?u)%s\s*%s' % (open % '.*?', close), '', html) + html = re.sub(r'(?u){}\s*{}'.format(open % '.*?', close), '', html) else: - html = re.sub(r'(?u)%s\s*%s' % (open, close), '', html) + html = re.sub(fr'(?u){open}\s*{close}', '', html) html = re.sub(r'(?imu)

\s*

', '', html) return html @@ -446,7 +443,7 @@ class PML_HTMLizer: if code in self.LINK_STATES: val = val.lstrip('#') if pre: - val = '%s-%s' % (pre, val) + val = f'{pre}-{val}' if code in self.STATES_VALUE_REQ: text += self.STATES_TAGS[code][0] % val else: @@ -575,13 +572,13 @@ class PML_HTMLizer: text = self.process_code(c, line) elif c in 'FS': l = line.read(1) - if '%s%s' % (c, l) == 'Fn': + if f'{c}{l}' == 'Fn': text = self.process_code('Fn', line, 'fn') - elif '%s%s' % (c, l) == 'FN': + elif f'{c}{l}' == 'FN': text = self.process_code('FN', line) - elif '%s%s' % (c, l) == 'SB': + elif f'{c}{l}' == 'SB': text = self.process_code('SB', line) - elif '%s%s' % (c, l) == 'Sd': + elif f'{c}{l}' == 'Sd': text = self.process_code('Sd', line, 'sb') elif c in 'xXC': empty = False @@ -597,12 +594,12 @@ class PML_HTMLizer: if c == 'x': t = self.process_code(c, line) elif c == 'X': - t = self.process_code('%s%s' % (c, level), line) + t = self.process_code(f'{c}{level}', line) if not value or value == '': text = t else: self.toc.append((level, (os.path.basename(self.file_name), id, value))) - text = '%s' % (t, id) + text = f'{t}' elif c == 'm': empty = False src = self.code_value(line) @@ -758,7 +755,7 @@ def pml_to_html(pml): def footnote_sidebar_to_html(pre_id, id, pml): id = id.strip('\x01') if id.strip(): - html = '

' % ( + html = '

'.format( pre_id, id, pml_to_html(pml), pre_id, id) else: html = '

%s
' % pml_to_html(pml) diff --git a/src/calibre/ebooks/pml/pmlml.py b/src/calibre/ebooks/pml/pmlml.py index 3b3853ef91..7394158636 100644 --- a/src/calibre/ebooks/pml/pmlml.py +++ b/src/calibre/ebooks/pml/pmlml.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - __license__ = 'GPL 3' __copyright__ = '2009, John Schember ' __docformat__ = 'restructuredtext en' @@ -149,7 +146,7 @@ class PMLMLizer: return self.get_anchor(page, '') def get_anchor_id(self, href, aid): - aid = '%s#%s' % (href, aid) + aid = f'{href}#{aid}' if aid not in self.link_hrefs.keys(): self.link_hrefs[aid] = 'calibre_link-%s' % len(self.link_hrefs.keys()) aid = self.link_hrefs[aid] @@ -288,7 +285,7 @@ class PMLMLizer: toc_title, toc_depth = self.toc[toc_page].get(toc_x, (None, 0)) if toc_title: toc_depth = max(min(toc_depth, 4), 0) - text.append(r'\C%s="%s"' % (toc_depth, toc_title)) + text.append(fr'\C{toc_depth}="{toc_title}"') # Process style information that needs holds a single tag. # Commented out because every page in an OEB book starts with this style. diff --git a/src/calibre/ebooks/rb/__init__.py b/src/calibre/ebooks/rb/__init__.py index 6d0b69b892..04f2e2045b 100644 --- a/src/calibre/ebooks/rb/__init__.py +++ b/src/calibre/ebooks/rb/__init__.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - __license__ = 'GPL 3' __copyright__ = '2009, John Schember ' __docformat__ = 'restructuredtext en' @@ -23,7 +20,7 @@ def unique_name(name, used_names): ext = os.path.splitext(name)[1][:3] base_name = name[:22] for i in range(0, 9999): - name = '%s-%s.%s' % (str(i).rjust('0', 4)[:4], base_name, ext) + name = '{}-{}.{}'.format(str(i).rjust('0', 4)[:4], base_name, ext) if name not in used_names: break return name diff --git a/src/calibre/ebooks/rb/rbml.py b/src/calibre/ebooks/rb/rbml.py index a023094b8e..557dccc82d 100644 --- a/src/calibre/ebooks/rb/rbml.py +++ b/src/calibre/ebooks/rb/rbml.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - __license__ = 'GPL 3' __copyright__ = '2009, John Schember ' __docformat__ = 'restructuredtext en' @@ -104,7 +101,7 @@ class RBMLizer: toc.append('

%s

    \n' % _('Table of Contents:')) for item in self.oeb_book.toc: if item.href in self.link_hrefs.keys(): - toc.append('
  • %s
  • \n' % (self.link_hrefs[item.href], item.title)) + toc.append(f'
  • {item.title}
  • \n') else: self.oeb.warn('Ignoring toc item: %s not found in document.' % item) toc.append('
') @@ -126,7 +123,7 @@ class RBMLizer: return self.get_anchor(page, '') def get_anchor(self, page, aid): - aid = '%s#%s' % (page.href, aid) + aid = f'{page.href}#{aid}' if aid not in self.link_hrefs.keys(): self.link_hrefs[aid] = 'calibre_link-%s' % len(self.link_hrefs.keys()) aid = self.link_hrefs[aid] diff --git a/src/calibre/ebooks/rb/reader.py b/src/calibre/ebooks/rb/reader.py index cda2f3898e..58a5ecb5bb 100644 --- a/src/calibre/ebooks/rb/reader.py +++ b/src/calibre/ebooks/rb/reader.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - __license__ = 'GPL 3' __copyright__ = '2009, John Schember ' __docformat__ = 'restructuredtext en' diff --git a/src/calibre/ebooks/rb/writer.py b/src/calibre/ebooks/rb/writer.py index b95354b131..195339e3da 100644 --- a/src/calibre/ebooks/rb/writer.py +++ b/src/calibre/ebooks/rb/writer.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - __license__ = 'GPL 3' __copyright__ = '2009, John Schember ' __docformat__ = 'restructuredtext en' @@ -145,7 +142,7 @@ class RBWriter: if len(metadata.creator) >= 1: from calibre.ebooks.metadata import authors_to_string text += 'AUTHOR=%s\n' % authors_to_string([x.value for x in metadata.creator]) - text += 'GENERATOR=%s - %s\n' % (__appname__, __version__) + text += f'GENERATOR={__appname__} - {__version__}\n' text += 'PARSE=1\n' text += 'OUTPUT=1\n' text += 'BODY=index.html\n' diff --git a/src/calibre/ebooks/readability/cleaners.py b/src/calibre/ebooks/readability/cleaners.py index d30216c4d8..1f67810c89 100644 --- a/src/calibre/ebooks/readability/cleaners.py +++ b/src/calibre/ebooks/readability/cleaners.py @@ -9,7 +9,7 @@ non_space = '[^ "\'>]+' htmlstrip = re.compile("<" # open "([^>]+) " # prefix "(?:%s) *" % ('|'.join(bad_attrs),) + # undesirable attributes - '= *(?:%s|%s|%s)' % (non_space, single_quoted, double_quoted) + # value + f'= *(?:{non_space}|{single_quoted}|{double_quoted})' + # value "([^>]*)" # postfix ">" # end , re.I) diff --git a/src/calibre/ebooks/readability/readability.py b/src/calibre/ebooks/readability/readability.py index 52c8e8dc5c..edffc0c4ff 100644 --- a/src/calibre/ebooks/readability/readability.py +++ b/src/calibre/ebooks/readability/readability.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai import re, sys @@ -196,7 +195,7 @@ class Document: sorted_candidates = sorted(candidates.values(), key=lambda x: x['content_score'], reverse=True) for candidate in sorted_candidates[:5]: elem = candidate['elem'] - self.debug("Top 5 : %6.3f %s" % (candidate['content_score'], describe(elem))) + self.debug("Top 5 : {:6.3f} {}".format(candidate['content_score'], describe(elem))) if len(sorted_candidates) == 0: return None @@ -257,7 +256,7 @@ class Document: candidate = candidates[elem] ld = self.get_link_density(elem) score = candidate['content_score'] - self.debug("Candid: %6.3f %s link density %.3f -> %6.3f" % (score, describe(elem), ld, score*(1-ld))) + self.debug(f"Candid: {score:6.3f} {describe(elem)} link density {ld:.3f} -> {score*(1-ld):6.3f}") candidate['content_score'] *= (1 - ld) return candidates @@ -304,7 +303,7 @@ class Document: for elem in self.html.iter(): if elem in self.keep_elements: continue - s = "%s %s" % (elem.get('class', ''), elem.get('id', '')) + s = "{} {}".format(elem.get('class', ''), elem.get('id', '')) # self.debug(s) if REGEXES['unlikelyCandidatesRe'].search(s) and (not REGEXES['okMaybeItsACandidateRe'].search(s)) and elem.tag != 'body': self.debug("Removing unlikely candidate - %s" % describe(elem)) @@ -408,10 +407,10 @@ class Document: reason = "too short content length %s without a single image" % content_length to_remove = True elif weight < 25 and link_density > 0.2: - reason = "too many links %.3f for its weight %s" % (link_density, weight) + reason = f"too many links {link_density:.3f} for its weight {weight}" to_remove = True elif weight >= 25 and link_density > 0.5: - reason = "too many links %.3f for its weight %s" % (link_density, weight) + reason = f"too many links {link_density:.3f} for its weight {weight}" to_remove = True elif (counts["embed"] == 1 and content_length < 75) or counts["embed"] > 1: reason = "s with too short content length, or too many s" diff --git a/src/calibre/ebooks/render_html.py b/src/calibre/ebooks/render_html.py index 5603885703..2e063afe52 100644 --- a/src/calibre/ebooks/render_html.py +++ b/src/calibre/ebooks/render_html.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2019, Kovid Goyal diff --git a/src/calibre/ebooks/rtf/preprocess.py b/src/calibre/ebooks/rtf/preprocess.py index 6f86da8c62..9d3412fc3a 100644 --- a/src/calibre/ebooks/rtf/preprocess.py +++ b/src/calibre/ebooks/rtf/preprocess.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai __license__ = 'GPL v3' diff --git a/src/calibre/ebooks/rtf/rtfml.py b/src/calibre/ebooks/rtf/rtfml.py index f28844c0c9..7dd24b199c 100644 --- a/src/calibre/ebooks/rtf/rtfml.py +++ b/src/calibre/ebooks/rtf/rtfml.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- - - __license__ = 'GPL 3' __copyright__ = '2009, John Schember ' __docformat__ = 'restructuredtext en' @@ -90,7 +87,7 @@ def txt2rtf(text): buf.write(x) else: # python2 and ur'\u' does not work - c = '\\u{:d}?'.format(val) + c = f'\\u{val:d}?' buf.write(c) return buf.getvalue() @@ -153,7 +150,7 @@ class RTFMLizer: return text def header(self): - header = '{\\rtf1{\\info{\\title %s}{\\author %s}}\\ansi\\ansicpg1252\\deff0\\deflang1033\n' % ( + header = '{{\\rtf1{{\\info{{\\title {}}}{{\\author {}}}}}\\ansi\\ansicpg1252\\deff0\\deflang1033\n'.format( self.oeb_book.metadata.title[0].value, authors_to_string([x.value for x in self.oeb_book.metadata.creator])) return header + ( '{\\fonttbl{\\f0\\froman\\fprq2\\fcharset128 Times New Roman;}{\\f1\\froman\\fprq2\\fcharset128 Times New Roman;}{\\f2\\fswiss\\fprq2\\fcharset128 Arial;}{\\f3\\fnil\\fprq2\\fcharset128 Arial;}{\\f4\\fnil\\fprq2\\fcharset128 MS Mincho;}{\\f5\\fnil\\fprq2\\fcharset128 Tahoma;}{\\f6\\fnil\\fprq0\\fcharset128 Tahoma;}}\n' # noqa @@ -198,7 +195,7 @@ class RTFMLizer: def clean_text(self, text): # Remove excessive newlines - text = re.sub('%s{3,}' % os.linesep, '%s%s' % (os.linesep, os.linesep), text) + text = re.sub('%s{3,}' % os.linesep, f'{os.linesep}{os.linesep}', text) # Remove excessive spaces text = re.sub('[ ]{2,}', ' ', text) @@ -255,7 +252,7 @@ class RTFMLizer: if 'block' not in tag_stack: block_start = r'{\par\pard\hyphpar ' block_end = '}' - text += '%s SPECIAL_IMAGE-%s-REPLACE_ME %s' % (block_start, src, block_end) + text += f'{block_start} SPECIAL_IMAGE-{src}-REPLACE_ME {block_end}' single_tag = SINGLE_TAGS.get(tag, None) if single_tag: diff --git a/src/calibre/ebooks/rtf2xml/ParseRtf.py b/src/calibre/ebooks/rtf2xml/ParseRtf.py index 2e9d024baa..13c7510daa 100644 --- a/src/calibre/ebooks/rtf2xml/ParseRtf.py +++ b/src/calibre/ebooks/rtf2xml/ParseRtf.py @@ -552,7 +552,7 @@ class ParseRtf: pass # sys.stderr.write( msg + ' in ' + file_name + "\n") else: - msg = '%s in file %s' % (msg, file_name) + msg = f'{msg} in file {file_name}' print(msg, file=sys.stderr) def __return_code(self, num): diff --git a/src/calibre/ebooks/rtf2xml/add_brackets.py b/src/calibre/ebooks/rtf2xml/add_brackets.py index 43cc9cb061..60bde3c7a9 100644 --- a/src/calibre/ebooks/rtf2xml/add_brackets.py +++ b/src/calibre/ebooks/rtf2xml/add_brackets.py @@ -162,7 +162,7 @@ class AddBrackets: ) self.__open_bracket = False - inline_string = ''.join(['%s 3: @@ -154,7 +154,7 @@ class ConvertToTags: att = att.replace('"', '"') att = att.replace("'", '"') self.__write_obj.write( - ' %s="%s"' % (val, att)) + f' {val}="{att}"') self.__write_obj.write('/>') self.__new_line = 0 if element_name in self.__block: diff --git a/src/calibre/ebooks/rtf2xml/field_strings.py b/src/calibre/ebooks/rtf2xml/field_strings.py index 31316c7404..314d2ab951 100644 --- a/src/calibre/ebooks/rtf2xml/field_strings.py +++ b/src/calibre/ebooks/rtf2xml/field_strings.py @@ -215,10 +215,10 @@ class FieldStrings: the_list = action(field_name, name, changed_string) else: # change -1 to 0--for now, I want users to report bugs - msg = 'no key for "%s" "%s"\n' % (field_name, changed_string) + msg = f'no key for "{field_name}" "{changed_string}"\n' sys.stderr.write(msg) if self.__run_level > 3: - msg = 'no key for "%s" "%s"\n' % (field_name, changed_string) + msg = f'no key for "{field_name}" "{changed_string}"\n' raise self.__bug_handler(msg) the_list = self.__fall_back_func(field_name, line) return the_list @@ -602,7 +602,7 @@ class FieldStrings: """ fields = line.split() label = fields[1] - my_string = '%s