Use raw strings to eliminate syntax warnings

This commit is contained in:
Zdenek Dohnal 2023-07-20 16:15:39 +02:00
parent aef1ccce5b
commit f22496015e

290
hplip-use-raw-strings.patch Normal file
View File

@ -0,0 +1,290 @@
diff --git a/base/device.py b/base/device.py
index fbe6c34..a551403 100644
--- a/base/device.py
+++ b/base/device.py
@@ -47,7 +47,7 @@ from . import models, mdns, slp, avahi
from .strings import *
from .sixext import PY3, to_bytes_utf8, to_unicode, to_string_latin, to_string_utf8, xStringIO
-http_result_pat = re.compile("""HTTP/\d.\d\s(\d+)""", re.I)
+http_result_pat = re.compile(r"""HTTP/\d.\d\s(\d+)""", re.I)
HTTP_OK = 200
HTTP_ERROR = 500
diff --git a/base/g.py b/base/g.py
index 96b3131..023aeea 100644
--- a/base/g.py
+++ b/base/g.py
@@ -302,7 +302,7 @@ prop.hpcups_build = to_bool(sys_conf.get('configure', 'hpcups-install', '0'))
prop.hpijs_build = to_bool(sys_conf.get('configure', 'hpijs-install', '0'))
# Spinner, ala Gentoo Portage
-spinner = "\|/-\|/-"
+spinner = r"\|/-\|/-"
spinpos = 0
enable_spinner = True
@@ -352,7 +352,7 @@ def check_extension_module_env(ext_mod):
log.error('%s not present in the system. Please re-install HPLIP.' %ext_mod)
sys.exit(1)
- m = re.search('python(\d(\.\d){0,2})', ext_path) #get the python version where the .so file is found
+ m = re.search(r'python(\d(\.\d){0,2})', ext_path) #get the python version where the .so file is found
ext_ver = xint(m.group(1))
if ext_ver[0] == 3:
diff --git a/base/logger.py b/base/logger.py
index dd92a9c..68e4f13 100644
--- a/base/logger.py
+++ b/base/logger.py
@@ -437,10 +437,10 @@ class Logger(object):
start = start + " "
number_chars = number_chars + 1
try:
- elem_start = re.findall("(\<\W{0,1}\w+) ?", line)[0]
- elem_finished = re.findall("([?|\]\]]*\>)", line)[0]
+ elem_start = re.findall(r"(\<\W{0,1}\w+) ?", line)[0]
+ elem_finished = re.findall(r"([?|\]\]]*\>)", line)[0]
#should not have *
- attrs = re.findall("(\S*?\=\".*?\")", line)
+ attrs = re.findall(r"(\S*?\=\".*?\")", line)
#output.write(start + elem_start)
self.log(start+elem_start, level, False)
number_chars = len(start + elem_start)
diff --git a/base/models.py b/base/models.py
index dc6cc39..48dd2ef 100644
--- a/base/models.py
+++ b/base/models.py
@@ -35,7 +35,7 @@ except ImportError:
datetime = None
-pat_prod_num = re.compile("""(\d+)""", re.I)
+pat_prod_num = re.compile(r"""(\d+)""", re.I)
TYPE_UNKNOWN = 0
TYPE_STRING = 1
@@ -427,25 +427,25 @@ class ModelData:
}
self.RE_FIELD_TYPES = {
- re.compile('^r(\d+)-agent(\d+)-kind', re.IGNORECASE) : TYPE_INT,
- re.compile('^r(\d+)-agent(\d+)-type', re.IGNORECASE) : TYPE_INT,
- re.compile('^r(\d+)-agent(\d+)-sku', re.IGNORECASE) : TYPE_STR,
- re.compile('^agent(\d+)-desc', re.IGNORECASE) : TYPE_STR,
- re.compile('^agent(\d+)-virgin', re.IGNORECASE) : TYPE_BOOL,
- re.compile('^agent(\d+)-dvc', re.IGNORECASE) : TYPE_INT,
- re.compile('^agent(\d+)-kind', re.IGNORECASE) : TYPE_INT,
- re.compile('^agent(\d+)-type', re.IGNORECASE) : TYPE_INT,
- re.compile('^agent(\d+)-id', re.IGNORECASE) : TYPE_INT,
- re.compile('^agent(\d+)-hp-ink', re.IGNORECASE) : TYPE_BOOL,
- re.compile('^agent(\d+)-health-desc', re.IGNORECASE) : TYPE_STR,
- re.compile('^agent(\d+)-health$', re.IGNORECASE) : TYPE_INT,
- re.compile('^agent(\d+)-known', re.IGNORECASE) : TYPE_BOOL,
- re.compile('^agent(\d+)-level', re.IGNORECASE) : TYPE_INT,
- re.compile('^agent(\d+)-ack', re.IGNORECASE) : TYPE_BOOL,
- re.compile('^agent(\d+)-sku', re.IGNORECASE) : TYPE_STR,
- re.compile('^in-tray(\d+)', re.IGNORECASE) : TYPE_BOOL,
- re.compile('^out-tray(\d+)', re.IGNORECASE) : TYPE_BOOL,
- re.compile('^model(\d+)', re.IGNORECASE) : TYPE_STR,
+ re.compile(r'^r(\d+)-agent(\d+)-kind', re.IGNORECASE) : TYPE_INT,
+ re.compile(r'^r(\d+)-agent(\d+)-type', re.IGNORECASE) : TYPE_INT,
+ re.compile(r'^r(\d+)-agent(\d+)-sku', re.IGNORECASE) : TYPE_STR,
+ re.compile(r'^agent(\d+)-desc', re.IGNORECASE) : TYPE_STR,
+ re.compile(r'^agent(\d+)-virgin', re.IGNORECASE) : TYPE_BOOL,
+ re.compile(r'^agent(\d+)-dvc', re.IGNORECASE) : TYPE_INT,
+ re.compile(r'^agent(\d+)-kind', re.IGNORECASE) : TYPE_INT,
+ re.compile(r'^agent(\d+)-type', re.IGNORECASE) : TYPE_INT,
+ re.compile(r'^agent(\d+)-id', re.IGNORECASE) : TYPE_INT,
+ re.compile(r'^agent(\d+)-hp-ink', re.IGNORECASE) : TYPE_BOOL,
+ re.compile(r'^agent(\d+)-health-desc', re.IGNORECASE) : TYPE_STR,
+ re.compile(r'^agent(\d+)-health$', re.IGNORECASE) : TYPE_INT,
+ re.compile(r'^agent(\d+)-known', re.IGNORECASE) : TYPE_BOOL,
+ re.compile(r'^agent(\d+)-level', re.IGNORECASE) : TYPE_INT,
+ re.compile(r'^agent(\d+)-ack', re.IGNORECASE) : TYPE_BOOL,
+ re.compile(r'^agent(\d+)-sku', re.IGNORECASE) : TYPE_STR,
+ re.compile(r'^in-tray(\d+)', re.IGNORECASE) : TYPE_BOOL,
+ re.compile(r'^out-tray(\d+)', re.IGNORECASE) : TYPE_BOOL,
+ re.compile(r'^model(\d+)', re.IGNORECASE) : TYPE_STR,
}
self.TYPE_CACHE = {}
diff --git a/base/password.py b/base/password.py
index 259bf82..a4ed107 100644
--- a/base/password.py
+++ b/base/password.py
@@ -167,8 +167,8 @@ class Password(object):
elif i == 1: # TIMEOUT
if('true' in cmd and self.__password_prompt_str == ""): # sudo true or su -c "true"
- cb = cb.replace("[", "\[")
- cb = cb.replace("]", "\]")
+ cb = cb.replace("[", r"\[")
+ cb = cb.replace("]", r"\]")
self.__password_prompt_str = cb
try:
diff --git a/base/status.py b/base/status.py
index 37c774e..01f455d 100644
--- a/base/status.py
+++ b/base/status.py
@@ -1341,7 +1341,7 @@ def MapPJLErrorCode(error_code, str_code=None):
return status_code
-pjl_code_pat = re.compile("""^CODE\s*=\s*(\d.*)$""", re.IGNORECASE)
+pjl_code_pat = re.compile(r"""^CODE\s*=\s*(\d.*)$""", re.IGNORECASE)
diff --git a/base/tui.py b/base/tui.py
index 0f90f92..3b36c65 100644
--- a/base/tui.py
+++ b/base/tui.py
@@ -217,7 +217,7 @@ class ProgressMeter(object):
self.progress = 0
self.prompt = prompt
self.prev_length = 0
- self.spinner = "\|/-\|/-*"
+ self.spinner = r"\|/-\|/-*"
self.spinner_pos = 0
self.max_size = ttysize()[1] - len(prompt) - 25
self.update(0)
diff --git a/base/utils.py b/base/utils.py
index 2b631ce..2fb57c4 100644
--- a/base/utils.py
+++ b/base/utils.py
@@ -148,7 +148,7 @@ def get_cups_systemgroup_list():
return lis
try:
- lis = ((re.findall('SystemGroup [\w* ]*',fp.read()))[0].replace('SystemGroup ','')).split(' ')
+ lis = ((re.findall(r'SystemGroup [\w* ]*',fp.read()))[0].replace('SystemGroup ','')).split(' ')
except IndexError:
return lis
@@ -1597,7 +1597,7 @@ def mixin(cls):
# ------------------------- Usage Help
USAGE_OPTIONS = ("[OPTIONS]", "", "heading", False)
USAGE_LOGGING1 = ("Set the logging level:", "-l<level> or --logging=<level>", 'option', False)
-USAGE_LOGGING2 = ("", "<level>: none, info\*, error, warn, debug (\*default)", "option", False)
+USAGE_LOGGING2 = ("", r"<level>: none, info\*, error, warn, debug (\*default)", "option", False)
USAGE_LOGGING3 = ("Run in debug mode:", "-g (same as option: -ldebug)", "option", False)
USAGE_LOGGING_PLAIN = ("Output plain text only:", "-t", "option", False)
USAGE_ARGS = ("[PRINTER|DEVICE-URI]", "", "heading", False)
@@ -1605,13 +1605,13 @@ USAGE_ARGS2 = ("[PRINTER]", "", "heading", False)
USAGE_DEVICE = ("To specify a device-URI:", "-d<device-uri> or --device=<device-uri>", "option", False)
USAGE_PRINTER = ("To specify a CUPS printer:", "-p<printer> or --printer=<printer>", "option", False)
USAGE_BUS1 = ("Bus to probe (if device not specified):", "-b<bus> or --bus=<bus>", "option", False)
-USAGE_BUS2 = ("", "<bus>: cups\*, usb\*, net, bt, fw, par\* (\*defaults) (Note: bt and fw not supported in this release.)", 'option', False)
+USAGE_BUS2 = ("", r"<bus>: cups\*, usb\*, net, bt, fw, par\* (\*defaults) (Note: bt and fw not supported in this release.)", 'option', False)
USAGE_HELP = ("This help information:", "-h or --help", "option", True)
USAGE_SPACE = ("", "", "space", False)
USAGE_EXAMPLES = ("Examples:", "", "heading", False)
USAGE_NOTES = ("Notes:", "", "heading", False)
USAGE_STD_NOTES1 = ("If device or printer is not specified, the local device bus is probed and the program enters interactive mode.", "", "note", False)
-USAGE_STD_NOTES2 = ("If -p\* is specified, the default CUPS printer will be used.", "", "note", False)
+USAGE_STD_NOTES2 = (r"If -p\* is specified, the default CUPS printer will be used.", "", "note", False)
USAGE_SEEALSO = ("See Also:", "", "heading", False)
USAGE_LANGUAGE = ("Set the language:", "--loc=<lang> or --lang=<lang>. Use --loc=? or --lang=? to see a list of available language codes.", "option", False)
USAGE_LANGUAGE2 = ("Set the language:", "--lang=<lang>. Use --lang=? to see a list of available language codes.", "option", False)
@@ -1839,7 +1839,7 @@ encoding: utf8
elif typ == 'man':
log.info('.TH "%s" 1 "%s" Linux "User Manuals"' % (crumb, version))
- log.info(".SH NAME\n%s \- %s" % (crumb, title))
+ log.info(r".SH NAME\n%s \- %s" % (crumb, title))
for line in text_list:
text1, text2, format, trailing_space = line
@@ -1938,7 +1938,7 @@ def unescape(text):
except KeyError:
pass
return text # leave as is
- return re.sub("&#?\w+;", fixup, text)
+ return re.sub(r"&#?\w+;", fixup, text)
# Adds HTML or XML character references and entities from a text string
@@ -1991,7 +1991,7 @@ def Is_HPLIP_older_version(installed_version, available_version):
log.debug("HPLIP Installed_version=%s Available_version=%s"%(installed_version,available_version))
cnt = 0
Is_older = False
- pat=re.compile('''(\d{1,})([a-z]{1,})''')
+ pat=re.compile(r'''(\d{1,})([a-z]{1,})''')
try:
while cnt <len(installed_array) and cnt <len(available_array):
diff --git a/installer/dcheck.py b/installer/dcheck.py
index a1a4f02..4dbee59 100644
--- a/installer/dcheck.py
+++ b/installer/dcheck.py
@@ -33,8 +33,8 @@ from base.g import *
from base import utils, services
from base.sixext import to_bytes_utf8
-ver1_pat = re.compile("""(\d+\.\d+\.\d+)""", re.IGNORECASE)
-ver_pat = re.compile("""(\d+.\d+)""", re.IGNORECASE)
+ver1_pat = re.compile(r"""(\d+\.\d+\.\d+)""", re.IGNORECASE)
+ver_pat = re.compile(r"""(\d+.\d+)""", re.IGNORECASE)
PID = 0
CMDLINE = 1
@@ -358,7 +358,7 @@ def get_xsane_version():
if output:
- xsane_ver_pat =re.compile('''xsane-(\d{1,}\.\d{1,}).*''')
+ xsane_ver_pat =re.compile(r'''xsane-(\d{1,}\.\d{1,}).*''')
xsane_ver_info = output.splitlines()[0]
if xsane_ver_pat.search(xsane_ver_info):
installed_ver = xsane_ver_pat.search(xsane_ver_info).group(1)
diff --git a/prnt/cups.py b/prnt/cups.py
index 1ea3099..78b8adc 100644
--- a/prnt/cups.py
+++ b/prnt/cups.py
@@ -168,7 +168,7 @@ CUPS_ERROR_BAD_NAME = 0x0f00
CUPS_ERROR_BAD_PARAMETERS = 0x0f01
nickname_pat = re.compile(r'''\*NickName:\s*\"(.*)"''', re.MULTILINE)
-pat_cups_error_log = re.compile("""^loglevel\s?(debug|debug2|warn|info|error|none)""", re.I)
+pat_cups_error_log = re.compile(r"""^loglevel\s?(debug|debug2|warn|info|error|none)""", re.I)
ppd_pat = re.compile(r'''.*hp-(.*?)(-.*)*\.ppd.*''', re.I)
ppd_pat1 = re.compile(r'''.*hp-(.*?)(_.*)*\.ppd.*''', re.I)
diff --git a/probe.py b/probe.py
index 2041fb6..2b43ece 100755
--- a/probe.py
+++ b/probe.py
@@ -42,11 +42,11 @@ USAGE = [(__doc__, "", "name", True),
("Usage: %s [OPTIONS]" % __mod__, "", "summary", True),
utils.USAGE_OPTIONS,
("Bus to probe:", "-b<bus> or --bus=<bus>", "option", False),
- ("", "<bus>: cups, usb\*, net, bt, fw, par (\*default) (Note: bt and fw not supported in this release.)", "option", False),
+ ("", r"<bus>: cups, usb\*, net, bt, fw, par (\*default) (Note: bt and fw not supported in this release.)", "option", False),
("Set Time to Live (TTL):", "-t<ttl> or --ttl=<ttl> (Default is 4).", "option", False),
("Set timeout:", "-o<timeout in secs.> or --timeout=<timeout is secs.>", "option", False),
("Filter by functionality:", "-e<filter list> or --filter=<filter list>", "option", False),
- ("", "<filter list>: comma separated list of one or more of: scan, pcard, fax, copy, or none\*. (\*none is the default)", "option", False),
+ ("", r"<filter list>: comma separated list of one or more of: scan, pcard, fax, copy, or none\*. (\*none is the default)", "option", False),
("Search:", "-s<search re> or --search=<search re>", "option", False),
("", "<search re> must be a valid regular expression (not case sensitive)", "option", False),
("Network discovery method:", "-m<method> or --method=<method>: <method> is 'slp'* or 'mdns'.", "option", False),
diff --git a/setup.py b/setup.py
index 98f57fd..539be50 100755
--- a/setup.py
+++ b/setup.py
@@ -79,11 +79,11 @@ USAGE = [ (__doc__, "", "name", True),
utils.USAGE_SPACE,
utils.USAGE_OPTIONS,
("Automatic mode:", "-a or --auto (-i mode only)", "option", False),
- ("To specify the port on a multi-port JetDirect:", "--port=<port> (Valid values are 1\*, 2, and 3. \*default)", "option", False),
+ (r"To specify the port on a multi-port JetDirect:", "--port=<port> (Valid values are 1\*, 2, and 3. \*default)", "option", False),
("No testpage in automatic mode:", "-x (-i mode only)", "option", False),
("To specify a CUPS printer queue name:", "-p<printer> or --printer=<printer> (-i mode only)", "option", False),
("To specify a CUPS fax queue name:", "-f<fax> or --fax=<fax> (-i mode only)", "option", False),
- ("Type of queue(s) to install:", "-t<typelist> or --type=<typelist>. <typelist>: print*, fax\* (\*default) (-i mode only)", "option", False),
+ (r"Type of queue(s) to install:", "-t<typelist> or --type=<typelist>. <typelist>: print*, fax\* (\*default) (-i mode only)", "option", False),
("To specify the device URI to install:", "-d<device> or --device=<device> (--qt4 mode only)", "option", False),
("Remove printers or faxes instead of setting-up:", "-r or --rm or --remove", "option", False),
utils.USAGE_LANGUAGE,