native_string_type (pep8)

This commit is contained in:
un-pogaz 2025-11-16 18:27:08 +01:00
parent 3147274b38
commit 9df759ad36
8 changed files with 32 additions and 32 deletions

View File

@ -22,4 +22,4 @@ class ConversionUserFeedBack(Exception):
# Ensure exception uses fully qualified name as this is used to detect it in
# the GUI.
ConversionUserFeedBack.__name__ = str('calibre.ebooks.conversion.ConversionUserFeedBack')
ConversionUserFeedBack.__name__ = 'calibre.ebooks.conversion.ConversionUserFeedBack'

View File

@ -243,7 +243,7 @@ class DOCX:
namespaces = self.namespace.namespaces
E = ElementMaker(namespace=namespaces['cp'], nsmap={x:namespaces[x] for x in 'cp dc dcterms xsi'.split()})
cp = E.coreProperties(E.revision('1'), E.lastModifiedBy('calibre'))
ts = utcnow().isoformat(str('T')).rpartition('.')[0] + 'Z'
ts = utcnow().isoformat('T').rpartition('.')[0] + 'Z'
for x in 'created modified'.split():
x = cp.makeelement('{{{}}}{}'.format(namespaces['dcterms'], x), **{'{{{}}}type'.format(namespaces['xsi']):'dcterms:W3CDTF'})
x.text = ts

View File

@ -15,8 +15,8 @@ def ceil(num):
def print_xml(elem):
from calibre.ebooks.lrf.pylrs.pylrs import ElementWriter
elem = elem.toElement(str('utf8'))
ew = ElementWriter(elem, sourceEncoding=str('utf8'))
elem = elem.toElement('utf8')
ew = ElementWriter(elem, sourceEncoding='utf8')
ew.write(sys.stdout)
print()

View File

@ -674,7 +674,7 @@ class Info(Delegator):
# NB: generates an encoding attribute, which lrs2lrf does not
tree = ElementTree(element=info)
f = io.BytesIO()
tree.write(f, encoding=str('utf-8'), xml_declaration=True)
tree.write(f, encoding='utf-8', xml_declaration=True)
xmlInfo = f.getvalue().decode('utf-8')
xmlInfo = re.sub(r'<CThumbnail.*?>\n', '', xmlInfo)
xmlInfo = xmlInfo.replace('SumPage>', 'Page>')

View File

@ -31,39 +31,39 @@ class JavascriptLexer(RegexLexer):
flags = re.UNICODE | re.MULTILINE
tokens = {
str('commentsandwhitespace'): [
'commentsandwhitespace': [
(r'\s+', Text),
(r'<!--', Comment),
(r'//.*?$', Comment.Single),
(r'/\*', Comment.Multiline, str('comment'))
(r'/\*', Comment.Multiline, 'comment')
],
str('comment'): [
'comment': [
(r'[^*/]+', Comment.Multiline),
(r'\*/', Comment.Multiline, str('#pop')),
(r'\*/', Comment.Multiline, '#pop'),
(r'[*/]', Comment.Multiline),
],
str('slashstartsregex'): [
include(str('commentsandwhitespace')),
'slashstartsregex': [
include('commentsandwhitespace'),
(r'/(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/'
r'([gim]+\b|\B)', String.Regex, str('#pop')),
(r'(?=/)', Text, (str('#pop'), str('badregex'))),
default(str('#pop'))
r'([gim]+\b|\B)', String.Regex, '#pop'),
(r'(?=/)', Text, ('#pop', 'badregex')),
default('#pop')
],
str('badregex'): [
(r'\n', Text, str('#pop'))
'badregex': [
(r'\n', Text, '#pop')
],
str('root'): [
'root': [
(r'\A#! ?/.*?\n', Comment), # shebang lines are recognized by node.js
(r'^(?=\s|/|<!--)', Text, str('slashstartsregex')),
include(str('commentsandwhitespace')),
(r'^(?=\s|/|<!--)', Text, 'slashstartsregex'),
include('commentsandwhitespace'),
(r'\+\+|--|~|&&|\?|:|\|\||\\(?=\n)|'
r'(<<|>>>?|==?|!=?|[-<>+*%&|^/])=?', Operator, str('slashstartsregex')),
(r'[{(\[;,]', Punctuation, str('slashstartsregex')),
r'(<<|>>>?|==?|!=?|[-<>+*%&|^/])=?', Operator, 'slashstartsregex'),
(r'[{(\[;,]', Punctuation, 'slashstartsregex'),
(r'[})\].]', Punctuation),
(r'(for|in|while|do|break|return|continue|switch|case|default|if|else|'
r'throw|try|catch|finally|new|delete|typeof|instanceof|void|yield|'
r'this)\b', Keyword, str('slashstartsregex')),
(r'(var|let|with|function)\b', Keyword.Declaration, str('slashstartsregex')),
r'this)\b', Keyword, 'slashstartsregex'),
(r'(var|let|with|function)\b', Keyword.Declaration, 'slashstartsregex'),
(r'(abstract|boolean|byte|char|class|const|debugger|double|enum|export|'
r'extends|final|float|goto|implements|import|int|interface|long|native|'
r'package|private|protected|public|short|static|super|synchronized|throws|'

View File

@ -77,7 +77,7 @@ def adapt_datetime(dt):
sqlite.register_adapter(datetime, adapt_datetime)
sqlite.register_converter(str('timestamp'), convert_timestamp)
sqlite.register_converter('timestamp', convert_timestamp)
def convert_bool(val):
@ -85,8 +85,8 @@ def convert_bool(val):
sqlite.register_adapter(bool, lambda x: 1 if x else 0)
sqlite.register_converter(str('bool'), convert_bool)
sqlite.register_converter(str('BOOL'), convert_bool)
sqlite.register_converter('bool', convert_bool)
sqlite.register_converter('BOOL', convert_bool)
class DynamicFilter:
@ -261,7 +261,7 @@ def do_connect(path, row_factory=None):
conn.row_factory = sqlite.Row if row_factory else (lambda cursor, row: list(row))
conn.create_aggregate('concat', 1, Concatenate)
conn.create_aggregate('aum_sortconcat', 4, AumSortedConcatenate)
conn.create_collation(str('PYNOCASE'), partial(pynocase,
conn.create_collation('PYNOCASE', partial(pynocase,
encoding=encoding))
conn.create_function('title_sort', 1, title_sort)
conn.create_function('author_to_author_sort', 1,
@ -269,7 +269,7 @@ def do_connect(path, row_factory=None):
conn.create_function('uuid4', 0, lambda: str(uuid.uuid4()))
# Dummy functions for dynamically created filters
conn.create_function('books_list_filter', 1, lambda x: 1)
conn.create_collation(str('icucollate'), icu_collator)
conn.create_collation('icucollate', icu_collator)
plugins.load_sqlite3_extension(conn, 'sqlite_extension')
return conn

View File

@ -117,9 +117,9 @@ class Worker:
@property
def env(self):
env = os.environ.copy()
env[str('CALIBRE_WORKER')] = environ_item('1')
env['CALIBRE_WORKER'] = environ_item('1')
td = as_hex_unicode(msgpack_dumps(base_dir()))
env[str('CALIBRE_WORKER_TEMP_DIR')] = environ_item(td)
env['CALIBRE_WORKER_TEMP_DIR'] = environ_item(td)
env.update(self._env)
return env
@ -180,7 +180,7 @@ class Worker:
except OSError:
# cwd no longer exists
origwd = cwd or os.path.expanduser('~')
env[str('ORIGWD')] = environ_item(as_hex_unicode(msgpack_dumps(origwd)))
env['ORIGWD'] = environ_item(as_hex_unicode(msgpack_dumps(origwd)))
_cwd = cwd
if priority is None:
priority = prefs['worker_process_priority']

View File

@ -157,7 +157,7 @@ def get_smtp_class(use_ssl=False, debuglevel=0):
from polyglot import smtplib
cls = smtplib.SMTP_SSL if use_ssl else smtplib.SMTP
bases = (cls,)
return type(str('SMTP'), bases, {str('debuglevel'): debuglevel})
return type('SMTP', bases, {'debuglevel': debuglevel})
def sendmail(msg, from_, to, localhost=None, verbose=0, timeout=None,