upgrade code to Python 3 (extra-edit)

This commit is contained in:
un-pogaz 2025-01-24 11:14:16 +01:00
parent 5572105076
commit e0022f21cf
16 changed files with 52 additions and 53 deletions

View File

@ -1,4 +1,3 @@
#
# calibre documentation build configuration file, created by
# sphinx-quickstart.py on Sun Mar 23 01:23:55 2008.
#

View File

@ -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__)

View File

@ -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

View File

@ -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'

View File

@ -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']

View File

@ -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*<body>', '<body>', res)
# res = re.sub('(?<=\n)\n{2}',
# u'<p>\u00a0</p>\n'.encode('utf-8'), res)
# '<p>\u00a0</p>\n'.encode('utf-8'), res)
f.write(res)
self.write_inline_css(inline_class, border_styles)
stream.seek(0)

View File

@ -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)

View File

@ -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):

View File

@ -277,11 +277,11 @@ class Textile:
'''
>>> import textile
>>> textile.textile('some textile')
u'\\t<p>some textile</p>'
'\\t<p>some textile</p>'
'''
self.html_type = html_type
# text = type(u'')(text)
# text = str(text)
text = _normalize_newlines(text)
if self.restricted:

View File

@ -119,8 +119,8 @@ def unsmarten(txt):
txt = re.sub('&#9830;|&diams;|♦', 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<br />\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<br />\n', txt) # blank paragraph - br tag
return txt

View File

@ -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

View File

@ -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

View File

@ -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()

View File

@ -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

View File

@ -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,

View File

@ -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'