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:
2026-06-22 19:52:56 -05:00
co-authored by Claude Opus 4.8
parent 838700fbec
commit 38dedea32b
3 changed files with 13 additions and 13 deletions
+1 -1
View File
@@ -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('<title>Page %d - %s by %s</title>\n' % (pageid, meta_array['Title'],meta_array['Authors']))
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)
if (previd) :
mlst.append('var prevpage="page%04d.xhtml";\n' % (previd))
+7 -7
View File
@@ -39,7 +39,7 @@ def decryptepub(infile, outdir, rscpath):
if ineptepub.adeptBook(zippath):
# try with any keyfiles (*.der) in the rscpath
files = os.listdir(rscpath)
filefilter = re.compile("\.der$", re.IGNORECASE)
filefilter = re.compile(r"\.der$", re.IGNORECASE)
files = filter(filefilter.search, files)
if files:
for filename in files:
@@ -58,7 +58,7 @@ def decryptepub(infile, outdir, rscpath):
# now try with ignoble epub
# try with any keyfiles (*.b64) in the rscpath
files = os.listdir(rscpath)
filefilter = re.compile("\.b64$", re.IGNORECASE)
filefilter = re.compile(r"\.b64$", re.IGNORECASE)
files = filter(filefilter.search, files)
if files:
for filename in files:
@@ -98,7 +98,7 @@ def decryptpdf(infile, outdir, rscpath):
# try with any keyfiles (*.der) in the rscpath
files = os.listdir(rscpath)
filefilter = re.compile("\.der$", re.IGNORECASE)
filefilter = re.compile(r"\.der$", re.IGNORECASE)
files = filter(filefilter.search, files)
if files:
for filename in files:
@@ -167,7 +167,7 @@ def decryptk4mobi(infile, outdir, rscpath):
serialnums = serialstr.split(',')
kDatabaseFiles = []
files = os.listdir(rscpath)
filefilter = re.compile("\.k4i$", re.IGNORECASE)
filefilter = re.compile(r"\.k4i$", re.IGNORECASE)
files = filter(filefilter.search, files)
if files:
for filename in files:
@@ -175,21 +175,21 @@ def decryptk4mobi(infile, outdir, rscpath):
kDatabaseFiles.append(dpath)
androidFiles = []
files = os.listdir(rscpath)
filefilter = re.compile("\.ab$", re.IGNORECASE)
filefilter = re.compile(r"\.ab$", re.IGNORECASE)
files = filter(filefilter.search, files)
if files:
for filename in files:
dpath = os.path.join(rscpath,filename)
androidFiles.append(dpath)
files = os.listdir(rscpath)
filefilter = re.compile("\.db$", re.IGNORECASE)
filefilter = re.compile(r"\.db$", re.IGNORECASE)
files = filter(filefilter.search, files)
if files:
for filename in files:
dpath = os.path.join(rscpath,filename)
androidFiles.append(dpath)
files = os.listdir(rscpath)
filefilter = re.compile("\.xml$", re.IGNORECASE)
filefilter = re.compile(r"\.xml$", re.IGNORECASE)
files = filter(filefilter.search, files)
if files:
for filename in files:
+5 -5
View File
@@ -413,7 +413,7 @@ class KoboLibrary(object):
"""The list of all MAC addresses on this machine."""
macaddrs = []
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:
output = subprocess.Popen('ipconfig /all', shell=True, stdout=subprocess.PIPE, text=True).stdout
for line in output:
@@ -427,7 +427,7 @@ class KoboLibrary(object):
if m:
macaddrs.append(re.sub("-", ":", m.group(1)).upper())
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')
matches = c.findall(output)
for m in matches:
@@ -443,14 +443,14 @@ class KoboLibrary(object):
else:
# final fallback
# 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'):
m = c.search(line)
if m:
macaddrs.append(m.group(1).upper())
# 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'):
m = c.search(line)
if m:
@@ -649,7 +649,7 @@ def decrypt_book(book, lib):
print("Converting {0}".format(book.title))
zin = zipfile.ZipFile(book.filename, "r")
# 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'):
print("DRM-free book, conversion is not needed")
shutil.copyfile(book.filename, outname)