]> git.ipfire.org Git - people/ms/libloc.git/commitdiff
Fix string escaping in location tool
authorPetr Písař <ppisar@redhat.com>
Mon, 24 Jul 2023 08:57:49 +0000 (10:57 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 24 Jul 2023 10:21:12 +0000 (10:21 +0000)
Python 3.12 started to warn on an invalid string escape sequence:

$ location list-networks-by-as --format ipset 1
/usr/bin/location:583: SyntaxWarning: invalid escape sequence '\d'
  m = re.match("^AS(\d+)$", object)
IpsetOutputWriter requires family being set

This patch fixes the warning as well as the regular expression by
using a raw string.

<https://docs.python.org/3.12/whatsnew/changelog.html#id77>

Fixes: #13188 - Invalid escape sequence with Python 3.12
Signed-off-by: Petr Písař <ppisar@redhat.com>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/scripts/location.in

index 60b11d636622a2f0e380f9cf71a7233c04936ee6..b34cc912105f1c2ce032bea76427aa9e62e69c7f 100644 (file)
@@ -580,7 +580,7 @@ class CLI(object):
                        families = [ socket.AF_INET6, socket.AF_INET ]
 
                for object in ns.objects:
-                       m = re.match("^AS(\d+)$", object)
+                       m = re.match(r"^AS(\d+)$", object)
                        if m:
                                object = int(m.group(1))