Fix invalid string escape sequences
Python 3.12+ emits SyntaxWarning for unrecognised backslash escapes (and
these will eventually become SyntaxErrors). Convert the affected string
literals to raw strings so the escapes are explicit:
- scriptinterface.py: filename filter regexes (\.der, \.b64, ...).
- obok.py: MAC-address detection regexes (\s, \-) and the title
sanitiser ([^\s\w]).
- flatxml2svg.py: the emitted JavaScript snippet contains \? and \d but
also a trailing newline, so the regex part is made a raw string and
the "\n" is concatenated separately.
All changes are value-preserving (an unrecognised escape already evaluated
to the backslash plus the character); verified the emitted JS string and
the compiled regexes are unchanged, and that both plugins now compile with
zero SyntaxWarnings.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -199,7 +199,7 @@ def convert2SVG(gdict, flat_xml, pageid, previd, nextid, svgDir, raw, meta_array
|
|||||||
mlst.append('<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" ><head>\n')
|
mlst.append('<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" ><head>\n')
|
||||||
mlst.append('<title>Page %d - %s by %s</title>\n' % (pageid, meta_array['Title'],meta_array['Authors']))
|
mlst.append('<title>Page %d - %s by %s</title>\n' % (pageid, meta_array['Title'],meta_array['Authors']))
|
||||||
mlst.append('<script><![CDATA[\n')
|
mlst.append('<script><![CDATA[\n')
|
||||||
mlst.append('function gd(){var p=window.location.href.replace(/^.*\?dpi=(\d+).*$/i,"$1");return p;}\n')
|
mlst.append(r'function gd(){var p=window.location.href.replace(/^.*\?dpi=(\d+).*$/i,"$1");return p;}' + '\n')
|
||||||
mlst.append('var dpi=%d;\n' % scaledpi)
|
mlst.append('var dpi=%d;\n' % scaledpi)
|
||||||
if (previd) :
|
if (previd) :
|
||||||
mlst.append('var prevpage="page%04d.xhtml";\n' % (previd))
|
mlst.append('var prevpage="page%04d.xhtml";\n' % (previd))
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ def decryptepub(infile, outdir, rscpath):
|
|||||||
if ineptepub.adeptBook(zippath):
|
if ineptepub.adeptBook(zippath):
|
||||||
# try with any keyfiles (*.der) in the rscpath
|
# try with any keyfiles (*.der) in the rscpath
|
||||||
files = os.listdir(rscpath)
|
files = os.listdir(rscpath)
|
||||||
filefilter = re.compile("\.der$", re.IGNORECASE)
|
filefilter = re.compile(r"\.der$", re.IGNORECASE)
|
||||||
files = filter(filefilter.search, files)
|
files = filter(filefilter.search, files)
|
||||||
if files:
|
if files:
|
||||||
for filename in files:
|
for filename in files:
|
||||||
@@ -58,7 +58,7 @@ def decryptepub(infile, outdir, rscpath):
|
|||||||
# now try with ignoble epub
|
# now try with ignoble epub
|
||||||
# try with any keyfiles (*.b64) in the rscpath
|
# try with any keyfiles (*.b64) in the rscpath
|
||||||
files = os.listdir(rscpath)
|
files = os.listdir(rscpath)
|
||||||
filefilter = re.compile("\.b64$", re.IGNORECASE)
|
filefilter = re.compile(r"\.b64$", re.IGNORECASE)
|
||||||
files = filter(filefilter.search, files)
|
files = filter(filefilter.search, files)
|
||||||
if files:
|
if files:
|
||||||
for filename in files:
|
for filename in files:
|
||||||
@@ -98,7 +98,7 @@ def decryptpdf(infile, outdir, rscpath):
|
|||||||
|
|
||||||
# try with any keyfiles (*.der) in the rscpath
|
# try with any keyfiles (*.der) in the rscpath
|
||||||
files = os.listdir(rscpath)
|
files = os.listdir(rscpath)
|
||||||
filefilter = re.compile("\.der$", re.IGNORECASE)
|
filefilter = re.compile(r"\.der$", re.IGNORECASE)
|
||||||
files = filter(filefilter.search, files)
|
files = filter(filefilter.search, files)
|
||||||
if files:
|
if files:
|
||||||
for filename in files:
|
for filename in files:
|
||||||
@@ -167,7 +167,7 @@ def decryptk4mobi(infile, outdir, rscpath):
|
|||||||
serialnums = serialstr.split(',')
|
serialnums = serialstr.split(',')
|
||||||
kDatabaseFiles = []
|
kDatabaseFiles = []
|
||||||
files = os.listdir(rscpath)
|
files = os.listdir(rscpath)
|
||||||
filefilter = re.compile("\.k4i$", re.IGNORECASE)
|
filefilter = re.compile(r"\.k4i$", re.IGNORECASE)
|
||||||
files = filter(filefilter.search, files)
|
files = filter(filefilter.search, files)
|
||||||
if files:
|
if files:
|
||||||
for filename in files:
|
for filename in files:
|
||||||
@@ -175,21 +175,21 @@ def decryptk4mobi(infile, outdir, rscpath):
|
|||||||
kDatabaseFiles.append(dpath)
|
kDatabaseFiles.append(dpath)
|
||||||
androidFiles = []
|
androidFiles = []
|
||||||
files = os.listdir(rscpath)
|
files = os.listdir(rscpath)
|
||||||
filefilter = re.compile("\.ab$", re.IGNORECASE)
|
filefilter = re.compile(r"\.ab$", re.IGNORECASE)
|
||||||
files = filter(filefilter.search, files)
|
files = filter(filefilter.search, files)
|
||||||
if files:
|
if files:
|
||||||
for filename in files:
|
for filename in files:
|
||||||
dpath = os.path.join(rscpath,filename)
|
dpath = os.path.join(rscpath,filename)
|
||||||
androidFiles.append(dpath)
|
androidFiles.append(dpath)
|
||||||
files = os.listdir(rscpath)
|
files = os.listdir(rscpath)
|
||||||
filefilter = re.compile("\.db$", re.IGNORECASE)
|
filefilter = re.compile(r"\.db$", re.IGNORECASE)
|
||||||
files = filter(filefilter.search, files)
|
files = filter(filefilter.search, files)
|
||||||
if files:
|
if files:
|
||||||
for filename in files:
|
for filename in files:
|
||||||
dpath = os.path.join(rscpath,filename)
|
dpath = os.path.join(rscpath,filename)
|
||||||
androidFiles.append(dpath)
|
androidFiles.append(dpath)
|
||||||
files = os.listdir(rscpath)
|
files = os.listdir(rscpath)
|
||||||
filefilter = re.compile("\.xml$", re.IGNORECASE)
|
filefilter = re.compile(r"\.xml$", re.IGNORECASE)
|
||||||
files = filter(filefilter.search, files)
|
files = filter(filefilter.search, files)
|
||||||
if files:
|
if files:
|
||||||
for filename in files:
|
for filename in files:
|
||||||
|
|||||||
@@ -413,7 +413,7 @@ class KoboLibrary(object):
|
|||||||
"""The list of all MAC addresses on this machine."""
|
"""The list of all MAC addresses on this machine."""
|
||||||
macaddrs = []
|
macaddrs = []
|
||||||
if sys.platform.startswith('win'):
|
if sys.platform.startswith('win'):
|
||||||
c = re.compile('\s?(' + '[0-9a-f]{2}[:\-]' * 5 + '[0-9a-f]{2})(\s|$)', re.IGNORECASE)
|
c = re.compile(r'\s?(' + r'[0-9a-f]{2}[:\-]' * 5 + r'[0-9a-f]{2})(\s|$)', re.IGNORECASE)
|
||||||
try:
|
try:
|
||||||
output = subprocess.Popen('ipconfig /all', shell=True, stdout=subprocess.PIPE, text=True).stdout
|
output = subprocess.Popen('ipconfig /all', shell=True, stdout=subprocess.PIPE, text=True).stdout
|
||||||
for line in output:
|
for line in output:
|
||||||
@@ -427,7 +427,7 @@ class KoboLibrary(object):
|
|||||||
if m:
|
if m:
|
||||||
macaddrs.append(re.sub("-", ":", m.group(1)).upper())
|
macaddrs.append(re.sub("-", ":", m.group(1)).upper())
|
||||||
elif sys.platform.startswith('darwin'):
|
elif sys.platform.startswith('darwin'):
|
||||||
c = re.compile('\s(' + '[0-9a-f]{2}:' * 5 + '[0-9a-f]{2})(\s|$)', re.IGNORECASE)
|
c = re.compile(r'\s(' + '[0-9a-f]{2}:' * 5 + r'[0-9a-f]{2})(\s|$)', re.IGNORECASE)
|
||||||
output = subprocess.check_output('/sbin/ifconfig -a', shell=True, encoding='utf-8')
|
output = subprocess.check_output('/sbin/ifconfig -a', shell=True, encoding='utf-8')
|
||||||
matches = c.findall(output)
|
matches = c.findall(output)
|
||||||
for m in matches:
|
for m in matches:
|
||||||
@@ -443,14 +443,14 @@ class KoboLibrary(object):
|
|||||||
else:
|
else:
|
||||||
# final fallback
|
# final fallback
|
||||||
# let's try ip
|
# let's try ip
|
||||||
c = re.compile('\s(' + '[0-9a-f]{2}:' * 5 + '[0-9a-f]{2})(\s|$)', re.IGNORECASE)
|
c = re.compile(r'\s(' + '[0-9a-f]{2}:' * 5 + r'[0-9a-f]{2})(\s|$)', re.IGNORECASE)
|
||||||
for line in os.popen('ip -br link'):
|
for line in os.popen('ip -br link'):
|
||||||
m = c.search(line)
|
m = c.search(line)
|
||||||
if m:
|
if m:
|
||||||
macaddrs.append(m.group(1).upper())
|
macaddrs.append(m.group(1).upper())
|
||||||
|
|
||||||
# let's try ipconfig under wine
|
# let's try ipconfig under wine
|
||||||
c = re.compile('\s(' + '[0-9a-f]{2}-' * 5 + '[0-9a-f]{2})(\s|$)', re.IGNORECASE)
|
c = re.compile(r'\s(' + '[0-9a-f]{2}-' * 5 + r'[0-9a-f]{2})(\s|$)', re.IGNORECASE)
|
||||||
for line in os.popen('ipconfig /all'):
|
for line in os.popen('ipconfig /all'):
|
||||||
m = c.search(line)
|
m = c.search(line)
|
||||||
if m:
|
if m:
|
||||||
@@ -649,7 +649,7 @@ def decrypt_book(book, lib):
|
|||||||
print("Converting {0}".format(book.title))
|
print("Converting {0}".format(book.title))
|
||||||
zin = zipfile.ZipFile(book.filename, "r")
|
zin = zipfile.ZipFile(book.filename, "r")
|
||||||
# make filename out of Unicode alphanumeric and whitespace equivalents from title
|
# make filename out of Unicode alphanumeric and whitespace equivalents from title
|
||||||
outname = "{0}.epub".format(re.sub('[^\s\w]', '_', book.title, 0, re.UNICODE))
|
outname = "{0}.epub".format(re.sub(r'[^\s\w]', '_', book.title, 0, re.UNICODE))
|
||||||
if (book.type == 'drm-free'):
|
if (book.type == 'drm-free'):
|
||||||
print("DRM-free book, conversion is not needed")
|
print("DRM-free book, conversion is not needed")
|
||||||
shutil.copyfile(book.filename, outname)
|
shutil.copyfile(book.filename, outname)
|
||||||
|
|||||||
Reference in New Issue
Block a user