[Git][NTPsec/ntpsec][master] Eliminate invalid escape sequence warnings from Python 3.12.0a4

Richard Laager (@rlaager) gitlab at mg.gitlab.com
Thu Jan 19 06:19:02 UTC 2023



Richard Laager pushed to branch master at NTPsec / ntpsec


Commits:
64e50c9d by Matt Selsky at 2023-01-18T11:12:56-05:00
Eliminate invalid escape sequence warnings from Python 3.12.0a4

- Use raw-string notation for regular expressions
- Don't escape characters that don't need it

Fixes NTPsec/ntpsec#762

- - - - -


3 changed files:

- ntpclients/ntplogtemp.py
- ntpclients/ntpviz.py
- pylib/util.py


Changes:

=====================================
ntpclients/ntplogtemp.py
=====================================
@@ -82,7 +82,7 @@ class CpuTemp:
             self.has_sensors = True
 
         # pattern that matches the string that has the cpu temp
-        self._pattern = re.compile('^\s+temp\d+_input:\s+([\d\.]+).*$')
+        self._pattern = re.compile(r'^\s+temp\d+_input:\s+([\d\.]+).*$')
 
     def get_data(self):
         "Collects the data and return the output as an array"


=====================================
ntpclients/ntpviz.py
=====================================
@@ -137,7 +137,7 @@ class MyArgumentParser(argparse.ArgumentParser):
     def convert_arg_line_to_args(self, arg_line):
         '''Make options file more tolerant'''
         # strip out trailing comments
-        arg_line = re.sub('\s+#.*$', '', arg_line)
+        arg_line = re.sub(r'\s+#.*$', '', arg_line)
 
         # ignore blank lines
         if not arg_line:


=====================================
pylib/util.py
=====================================
@@ -638,7 +638,7 @@ def canonicalize_dns(inhost, family=socket.AF_UNSPEC):
     if resname is not None:
         return resname
     # Catch garbaged hostnames in corrupted Mode 6 responses
-    m = re.match("([:.[\]]|\w)*", inhost)
+    m = re.match(r"([:.[\]]|\w)*", inhost)
     if not m:
         raise TypeError
     (hostname, portsuffix) = portsplit(inhost)
@@ -1395,7 +1395,7 @@ class IfstatsSummary:
         # FIXME, a brutal and slow way to check for invalid chars..
         # maybe just strip non-printing chars?
         for c in s:
-            if not c.isalnum() and c not in "/.:[] \%\n":
+            if not c.isalnum() and c not in "/.:[] %\n":
                 return ''
         return s
 



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/-/commit/64e50c9d0ff5523a75e7f412207b72d197de4b85

-- 
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/-/commit/64e50c9d0ff5523a75e7f412207b72d197de4b85
You're receiving this email because of your account on gitlab.com.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20230119/4ca0515e/attachment-0001.htm>


More information about the vc mailing list