From e0022f21cf9ce3092c88614ccfbe3cbbb9aa8596 Mon Sep 17 00:00:00 2001
From: un-pogaz <46523284+un-pogaz@users.noreply.github.com>
Date: Fri, 24 Jan 2025 11:14:16 +0100
Subject: [PATCH] upgrade code to Python 3 (extra-edit)
---
manual/conf.py | 1 -
setup/lc_data.py | 2 +-
setup/plugins_mirror.py | 2 +-
src/calibre/devices/eb600/driver.py | 6 +--
src/calibre/devices/jetbook/driver.py | 12 ++---
.../ebooks/conversion/plugins/rtf_input.py | 2 +-
src/calibre/ebooks/lrf/pylrs/pylrs.py | 2 +-
src/calibre/ebooks/oeb/base.py | 4 +-
src/calibre/ebooks/textile/functions.py | 4 +-
src/calibre/ebooks/textile/unsmarten.py | 6 +--
src/calibre/gui2/actions/all_actions.py | 2 +-
.../gui2/dialogs/edit_category_notes.py | 2 +-
src/calibre/gui2/tweak_book/spell.py | 4 +-
src/calibre/utils/zipfile.py | 4 +-
src/odf/attrconverters.py | 50 +++++++++----------
src/odf/namespaces.py | 2 +-
16 files changed, 52 insertions(+), 53 deletions(-)
diff --git a/manual/conf.py b/manual/conf.py
index f9a896fd2a..fd72148cf3 100644
--- a/manual/conf.py
+++ b/manual/conf.py
@@ -1,4 +1,3 @@
-#
# calibre documentation build configuration file, created by
# sphinx-quickstart.py on Sun Mar 23 01:23:55 2008.
#
diff --git a/setup/lc_data.py b/setup/lc_data.py
index 91abf51c8d..a386e71228 100644
--- a/setup/lc_data.py
+++ b/setup/lc_data.py
@@ -26,7 +26,7 @@ def generate_data():
return ans
def main():
- if sys.version_info[0] < 3:
+ if sys.version_info[0] < 3: # noqa: UP036
raise RuntimeError('Must be run using python 3.x')
locale.setlocale(locale.LC_ALL, '')
dest = os.path.abspath(__file__)
diff --git a/setup/plugins_mirror.py b/setup/plugins_mirror.py
index 9c6e8adb48..1790b98b42 100644
--- a/setup/plugins_mirror.py
+++ b/setup/plugins_mirror.py
@@ -722,7 +722,7 @@ class HelloWorld(FileTypePlugin):
name = _('name') # Name of the plugin
description = {1, 2}
supported_platforms = ['windows', 'osx', 'linux'] # Platforms this plugin will run on
- author = u'Acme Inc.' # The author of this plugin
+ author = 'Acme Inc.' # The author of this plugin
version = {1:'a', 'b':2}
file_types = set(['epub', 'mobi']) # The file types that this plugin will be applied to
on_postprocess = True # Run this plugin after conversion is complete
diff --git a/src/calibre/devices/eb600/driver.py b/src/calibre/devices/eb600/driver.py
index ea09009b64..b27201b352 100644
--- a/src/calibre/devices/eb600/driver.py
+++ b/src/calibre/devices/eb600/driver.py
@@ -7,9 +7,9 @@ Device driver for the Netronix EB600
Windows PNP strings:
('USBSTOR\\DISK&VEN_NETRONIX&PROD_EBOOK&REV_062E\\6&1A275569&0&EB6001009
-2W00000&0', 2, u'F:\\')
+2W00000&0', 2, 'F:\\')
('USBSTOR\\DISK&VEN_NETRONIX&PROD_EBOOK&REV_062E\\6&1A275569&0&EB6001009
-2W00000&1', 3, u'G:\\')
+2W00000&1', 3, 'G:\\')
'''
import re
@@ -184,7 +184,7 @@ class SHINEBOOK(EB600):
class POCKETBOOK360(EB600):
# Device info on OS X
- # (8069L, 5768L, 272L, u'', u'', u'1.00')
+ # (8069L, 5768L, 272L,'', '', '1.00')
name = 'PocketBook 360 Device Interface'
diff --git a/src/calibre/devices/jetbook/driver.py b/src/calibre/devices/jetbook/driver.py
index 914fc98f22..837a5ab419 100644
--- a/src/calibre/devices/jetbook/driver.py
+++ b/src/calibre/devices/jetbook/driver.py
@@ -128,12 +128,12 @@ class JETBOOK_MINI(USBMS):
class JETBOOK_COLOR(USBMS):
'''
-set([(u'0x951',
- u'0x160b',
- u'0x0',
- u'Freescale',
- u'Mass Storage Device',
- u'0802270905553')])
+set([('0x951',
+ '0x160b',
+ '0x0',
+ 'Freescale',
+ 'Mass Storage Device',
+ '0802270905553')])
'''
FORMATS = ['epub', 'mobi', 'prc', 'fb2', 'rtf', 'txt', 'pdf', 'djvu']
diff --git a/src/calibre/ebooks/conversion/plugins/rtf_input.py b/src/calibre/ebooks/conversion/plugins/rtf_input.py
index 5f5d8f206d..5809e6fc7a 100644
--- a/src/calibre/ebooks/conversion/plugins/rtf_input.py
+++ b/src/calibre/ebooks/conversion/plugins/rtf_input.py
@@ -300,7 +300,7 @@ class RTFInput(InputFormatPlugin):
# Replace newlines inserted by the 'empty_paragraphs' option in rtf2xml with html blank lines
# res = re.sub('\s*
', '', res)
# res = re.sub('(?<=\n)\n{2}',
- # u'\u00a0
\n'.encode('utf-8'), res)
+ # '\u00a0
\n'.encode('utf-8'), res)
f.write(res)
self.write_inline_css(inline_class, border_styles)
stream.seek(0)
diff --git a/src/calibre/ebooks/lrf/pylrs/pylrs.py b/src/calibre/ebooks/lrf/pylrs/pylrs.py
index 9a473e17f0..d045936465 100644
--- a/src/calibre/ebooks/lrf/pylrs/pylrs.py
+++ b/src/calibre/ebooks/lrf/pylrs/pylrs.py
@@ -195,7 +195,7 @@ class Delegator:
self.applySetting(setting, value, testValid)
'''
if setting not in self.delegatedSettingsDict:
- raise LrsError, "setting %s not valid" % setting
+ raise LrsError("setting %s not valid" % setting)
delegates = self.delegatedSettingsDict[setting]
for d in delegates:
setattr(d, setting, value)
diff --git a/src/calibre/ebooks/oeb/base.py b/src/calibre/ebooks/oeb/base.py
index 842bb269ad..2900083f71 100644
--- a/src/calibre/ebooks/oeb/base.py
+++ b/src/calibre/ebooks/oeb/base.py
@@ -585,7 +585,7 @@ class DirContainer:
def _unquote(self, path):
# unquote must run on a bytestring and will return a bytestring
# If it runs on a unicode object, it returns a double encoded unicode
- # string: unquote(u'%C3%A4') != unquote(b'%C3%A4').decode('utf-8')
+ # string: unquote('%C3%A4') != unquote(b'%C3%A4').decode('utf-8')
# and the latter is correct
if isinstance(path, str):
path = path.encode('utf-8')
@@ -619,7 +619,7 @@ class DirContainer:
# On linux, if LANG is unset, the os.stat call tries to encode the
# unicode path using ASCII
# To replicate try:
- # LANG=en_US.ASCII python -c "import os; os.stat(u'Espa\xf1a')"
+ # LANG=en_US.ASCII python -c "import os; os.stat('Espa\xf1a')"
return os.path.isfile(path.encode(filesystem_encoding))
def namelist(self):
diff --git a/src/calibre/ebooks/textile/functions.py b/src/calibre/ebooks/textile/functions.py
index 0502a7d49c..0fc53b151b 100644
--- a/src/calibre/ebooks/textile/functions.py
+++ b/src/calibre/ebooks/textile/functions.py
@@ -277,11 +277,11 @@ class Textile:
'''
>>> import textile
>>> textile.textile('some textile')
- u'\\tsome textile
'
+ '\\tsome textile
'
'''
self.html_type = html_type
- # text = type(u'')(text)
+ # text = str(text)
text = _normalize_newlines(text)
if self.restricted:
diff --git a/src/calibre/ebooks/textile/unsmarten.py b/src/calibre/ebooks/textile/unsmarten.py
index d7f91a4415..6481b436f4 100644
--- a/src/calibre/ebooks/textile/unsmarten.py
+++ b/src/calibre/ebooks/textile/unsmarten.py
@@ -119,8 +119,8 @@ def unsmarten(txt):
txt = re.sub('♦|♦|♦', r'{diamond}', txt) # diamond
# Move into main code?
- # txt = re.sub(u'\xa0', r'p. ', txt) # blank paragraph
- # txt = re.sub(u'\n\n\n\n', r'\n\np. \n\n', txt) # blank paragraph
- # txt = re.sub(u'\n \n', r'\n
\n', txt) # blank paragraph - br tag
+ # txt = re.sub('\xa0', r'p. ', txt) # blank paragraph
+ # txt = re.sub('\n\n\n\n', r'\n\np. \n\n', txt) # blank paragraph
+ # txt = re.sub('\n \n', r'\n
\n', txt) # blank paragraph - br tag
return txt
diff --git a/src/calibre/gui2/actions/all_actions.py b/src/calibre/gui2/actions/all_actions.py
index 2c91f85e7c..a89f9e632b 100644
--- a/src/calibre/gui2/actions/all_actions.py
+++ b/src/calibre/gui2/actions/all_actions.py
@@ -106,7 +106,7 @@ class AllGUIActions(InterfaceAction):
for n,v in kbd.keys_map.items():
act_name = kbd.shortcuts[n]['name'].lower()
if act_name in lower_names:
- shortcuts = list(sc.toString() for sc in v)
+ shortcuts = [sc.toString() for sc in v]
shortcut_map[act_name] = f'\t{", ".join(shortcuts)}'
# This function constructs a menu action, dealing with the action being
diff --git a/src/calibre/gui2/dialogs/edit_category_notes.py b/src/calibre/gui2/dialogs/edit_category_notes.py
index 23260a14dc..4093bc0c58 100644
--- a/src/calibre/gui2/dialogs/edit_category_notes.py
+++ b/src/calibre/gui2/dialogs/edit_category_notes.py
@@ -194,7 +194,7 @@ class AskImage(Dialog):
'No image is present in the system clipboard'), show=True)
@property
- def image_layout(self) -> 'QTextFrameFormat.Position':
+ def image_layout(self) -> QTextFrameFormat.Position:
b = self.image_layout_group.checkedButton()
if b is self.inline:
return QTextFrameFormat.Position.InFlow
diff --git a/src/calibre/gui2/tweak_book/spell.py b/src/calibre/gui2/tweak_book/spell.py
index fb0fd91356..ab73bac22c 100644
--- a/src/calibre/gui2/tweak_book/spell.py
+++ b/src/calibre/gui2/tweak_book/spell.py
@@ -241,11 +241,11 @@ class AddDictionary(QDialog): # {{{
except:
import traceback
return error_dialog(self, _('Failed to download dictionaries'), _(
- 'Failed to download dictionaries for "{:s}". Click "Show details" for more information').format(data['text']),
+ 'Failed to download dictionaries for "{}". Click "Show details" for more information').format(data['text']),
det_msg=traceback.format_exc(), show=True)
if num == 0:
return error_dialog(self, _('No dictionaries'), _(
- 'No dictionary was found for "{:s}"').format(data['text']), show=True)
+ 'No dictionary was found for "{}"').format(data['text']), show=True)
def accept(self):
idx = self.tabs.currentIndex()
diff --git a/src/calibre/utils/zipfile.py b/src/calibre/utils/zipfile.py
index 6b94abe609..a62980e1c2 100644
--- a/src/calibre/utils/zipfile.py
+++ b/src/calibre/utils/zipfile.py
@@ -1049,9 +1049,9 @@ class ZipFile:
print(('WARNING: Header (%r) and directory (%r) filenames do not'
' match inside ZipFile')%(fname, zinfo.orig_filename))
print('Using directory filename %r'%zinfo.orig_filename)
- # raise BadZipfile, \
+ # raise BadZipfile(
# 'File name in directory "%r" and header "%r" differ.' % (
- # zinfo.orig_filename, fname)
+ # zinfo.orig_filename, fname))
# check for encrypted flag & handle password
is_encrypted = zinfo.flag_bits & 0x1
diff --git a/src/odf/attrconverters.py b/src/odf/attrconverters.py
index 1d362c750f..945ea5fef8 100644
--- a/src/odf/attrconverters.py
+++ b/src/odf/attrconverters.py
@@ -126,7 +126,7 @@ def __save_prefix(attribute, arg, element):
return str(arg)
namespace = element.get_knownns(prefix)
if namespace is None:
- # raise ValueError, "'%s' is an unknown prefix" % unicode_type(prefix)
+ # raise ValueError("'%s' is an unknown prefix" % unicode_type(prefix))
return str(arg)
return str(arg)
@@ -333,7 +333,7 @@ attrconverters = {
((ANIMNS,'name'), None): cnv_string,
((ANIMNS,'sub-item'), None): cnv_string,
((ANIMNS,'value'), None): cnv_string,
- # ((DBNS,u'type'), None): cnv_namespacedToken,
+ # ((DBNS,'type'), None): cnv_namespacedToken,
((CHARTNS,'attached-axis'), None): cnv_string,
((CHARTNS,'class'), (CHARTNS,'grid')): cnv_major_minor,
((CHARTNS,'class'), None): cnv_namespacedToken,
@@ -555,8 +555,8 @@ attrconverters = {
((DRAWNS,'handle-range-y-maximum'), None): cnv_string,
((DRAWNS,'handle-range-y-minimum'), None): cnv_string,
((DRAWNS,'handle-switched'), None): cnv_boolean,
- # ((DRAWNS,u'id'), None): cnv_ID,
- # ((DRAWNS,u'id'), None): cnv_nonNegativeInteger, # ?? line 6581 in RNG
+ # ((DRAWNS,'id'), None): cnv_ID,
+ # ((DRAWNS,'id'), None): cnv_nonNegativeInteger, # ?? line 6581 in RNG
((DRAWNS,'id'), None): cnv_string,
((DRAWNS,'image-opacity'), None): cnv_string,
((DRAWNS,'kind'), None): cnv_string,
@@ -579,7 +579,7 @@ attrconverters = {
((DRAWNS,'mirror-vertical'), None): cnv_boolean,
((DRAWNS,'modifiers'), None): cnv_string,
((DRAWNS,'name'), None): cnv_NCName,
- # ((DRAWNS,u'name'), None): cnv_string,
+ # ((DRAWNS,'name'), None): cnv_string,
((DRAWNS,'nav-order'), None): cnv_IDREF,
((DRAWNS,'nohref'), None): cnv_string,
((DRAWNS,'notify-on-update-of-ranges'), None): cnv_string,
@@ -716,10 +716,10 @@ attrconverters = {
((FORMNS,'convert-empty-to-null'), None): cnv_boolean,
((FORMNS,'current-selected'), None): cnv_boolean,
((FORMNS,'current-state'), None): cnv_string,
- # ((FORMNS,u'current-value'), None): cnv_date,
- # ((FORMNS,u'current-value'), None): cnv_double,
+ # ((FORMNS,'current-value'), None): cnv_date,
+ # ((FORMNS,'current-value'), None): cnv_double,
((FORMNS,'current-value'), None): cnv_string,
- # ((FORMNS,u'current-value'), None): cnv_time,
+ # ((FORMNS,'current-value'), None): cnv_time,
((FORMNS,'data-field'), None): cnv_string,
((FORMNS,'datasource'), None): cnv_string,
((FORMNS,'default-button'), None): cnv_boolean,
@@ -744,15 +744,15 @@ attrconverters = {
((FORMNS,'list-source-type'), None): cnv_string,
((FORMNS,'master-fields'), None): cnv_string,
((FORMNS,'max-length'), None): cnv_nonNegativeInteger,
- # ((FORMNS,u'max-value'), None): cnv_date,
- # ((FORMNS,u'max-value'), None): cnv_double,
+ # ((FORMNS,'max-value'), None): cnv_date,
+ # ((FORMNS,'max-value'), None): cnv_double,
((FORMNS,'max-value'), None): cnv_string,
- # ((FORMNS,u'max-value'), None): cnv_time,
+ # ((FORMNS,'max-value'), None): cnv_time,
((FORMNS,'method'), None): cnv_string,
- # ((FORMNS,u'min-value'), None): cnv_date,
- # ((FORMNS,u'min-value'), None): cnv_double,
+ # ((FORMNS,'min-value'), None): cnv_date,
+ # ((FORMNS,'min-value'), None): cnv_double,
((FORMNS,'min-value'), None): cnv_string,
- # ((FORMNS,u'min-value'), None): cnv_time,
+ # ((FORMNS,'min-value'), None): cnv_time,
((FORMNS,'multi-line'), None): cnv_boolean,
((FORMNS,'multiple'), None): cnv_boolean,
((FORMNS,'name'), None): cnv_string,
@@ -774,10 +774,10 @@ attrconverters = {
((FORMNS,'title'), None): cnv_string,
((FORMNS,'toggle'), None): cnv_boolean,
((FORMNS,'validation'), None): cnv_boolean,
- # ((FORMNS,u'value'), None): cnv_date,
- # ((FORMNS,u'value'), None): cnv_double,
+ # ((FORMNS,'value'), None): cnv_date,
+ # ((FORMNS,'value'), None): cnv_double,
((FORMNS,'value'), None): cnv_string,
- # ((FORMNS,u'value'), None): cnv_time,
+ # ((FORMNS,'value'), None): cnv_time,
((FORMNS,'visual-effect'), None): cnv_string,
((FORMNS,'xforms-list-source'), None): cnv_string,
((FORMNS,'xforms-submission'), None): cnv_string,
@@ -1205,7 +1205,7 @@ attrconverters = {
((TABLENS,'border-color'), None): cnv_string,
((TABLENS,'border-model'), None): cnv_string,
((TABLENS,'buttons'), None): cnv_string,
- # ((TABLENS,u'case-sensitive'), None): cnv_boolean,
+ # ((TABLENS,'case-sensitive'), None): cnv_boolean,
((TABLENS,'case-sensitive'), None): cnv_string,
((TABLENS,'cell-address'), None): cnv_string,
((TABLENS,'cell-range-address'), None): cnv_string,
@@ -1252,7 +1252,7 @@ attrconverters = {
((TABLENS,'execute'), None): cnv_boolean,
((TABLENS,'expression'), None): cnv_formula,
((TABLENS,'field-name'), None): cnv_string,
- # ((TABLENS,u'field-number'), None): cnv_nonNegativeInteger,
+ # ((TABLENS,'field-number'), None): cnv_nonNegativeInteger,
((TABLENS,'field-number'), None): cnv_string,
((TABLENS,'filter-name'), None): cnv_string,
((TABLENS,'filter-options'), None): cnv_string,
@@ -1311,7 +1311,7 @@ attrconverters = {
((TABLENS,'protection-key'), None): cnv_string,
((TABLENS,'query-name'), None): cnv_string,
((TABLENS,'range-usable-as'), None): cnv_string,
- # ((TABLENS,u'refresh-delay'), None): cnv_boolean,
+ # ((TABLENS,'refresh-delay'), None): cnv_boolean,
((TABLENS,'refresh-delay'), None): cnv_duration,
((TABLENS,'rejecting-change-id'), None): cnv_string,
((TABLENS,'row'), None): cnv_integer,
@@ -1319,7 +1319,7 @@ attrconverters = {
((TABLENS,'search-criteria-must-apply-to-whole-cell'), None): cnv_boolean,
((TABLENS,'selected-page'), None): cnv_string,
((TABLENS,'show-details'), None): cnv_boolean,
- # ((TABLENS,u'show-empty'), None): cnv_boolean,
+ # ((TABLENS,'show-empty'), None): cnv_boolean,
((TABLENS,'show-empty'), None): cnv_string,
((TABLENS,'show-filter-button'), None): cnv_boolean,
((TABLENS,'sort-mode'), None): cnv_string,
@@ -1402,7 +1402,7 @@ attrconverters = {
((TEXTNS,'database-name'), None): cnv_string,
((TEXTNS,'date-adjust'), None): cnv_duration,
((TEXTNS,'date-value'), None): cnv_date,
- # ((TEXTNS,u'date-value'), None): cnv_dateTime,
+ # ((TEXTNS,'date-value'), None): cnv_dateTime,
((TEXTNS,'default-style-name'), None): cnv_StyleNameRef,
((TEXTNS,'description'), None): cnv_string,
((TEXTNS,'display'), None): cnv_string,
@@ -1421,7 +1421,7 @@ attrconverters = {
((TEXTNS,'global'), None): cnv_boolean,
((TEXTNS,'howpublished'), None): cnv_string,
((TEXTNS,'id'), None): cnv_ID,
- # ((TEXTNS,u'id'), None): cnv_string,
+ # ((TEXTNS,'id'), None): cnv_string,
((TEXTNS,'identifier'), None): cnv_string,
((TEXTNS,'ignore-case'), None): cnv_boolean,
((TEXTNS,'increment'), None): cnv_nonNegativeInteger,
@@ -1486,7 +1486,7 @@ attrconverters = {
((TEXTNS,'sort-by-position'), None): cnv_boolean,
((TEXTNS,'space-before'), None): cnv_string,
((TEXTNS,'start-numbering-at'), None): cnv_string,
- # ((TEXTNS,u'start-value'), None): cnv_nonNegativeInteger,
+ # ((TEXTNS,'start-value'), None): cnv_nonNegativeInteger,
((TEXTNS,'start-value'), None): cnv_positiveInteger,
((TEXTNS,'string-value'), None): cnv_string,
((TEXTNS,'string-value-if-false'), None): cnv_string,
@@ -1498,7 +1498,7 @@ attrconverters = {
((TEXTNS,'table-name'), None): cnv_string,
((TEXTNS,'table-type'), None): cnv_string,
((TEXTNS,'time-adjust'), None): cnv_duration,
- # ((TEXTNS,u'time-value'), None): cnv_dateTime,
+ # ((TEXTNS,'time-value'), None): cnv_dateTime,
((TEXTNS,'time-value'), None): cnv_time,
((TEXTNS,'title'), None): cnv_string,
((TEXTNS,'track-changes'), None): cnv_boolean,
diff --git a/src/odf/namespaces.py b/src/odf/namespaces.py
index 32b66c63a9..511e69ea08 100644
--- a/src/odf/namespaces.py
+++ b/src/odf/namespaces.py
@@ -24,7 +24,7 @@ CHARTNS = 'urn:oasis:names:tc:opendocument:xmlns:chart:1.0'
CHARTOOONS = 'http://openoffice.org/2010/chart'
CONFIGNS = 'urn:oasis:names:tc:opendocument:xmlns:config:1.0'
CSS3TNS = 'http://www.w3.org/TR/css3-text/'
-# DBNS = u'http://openoffice.org/2004/database'
+# DBNS = 'http://openoffice.org/2004/database'
DBNS = 'urn:oasis:names:tc:opendocument:xmlns:database:1.0'
DCNS = 'http://purl.org/dc/elements/1.1/'
DOMNS = 'http://www.w3.org/2001/xml-events'