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