From 503f526afd628001c48b2e7c20ac9c434c6eb61c Mon Sep 17 00:00:00 2001 From: zakriya Date: Tue, 30 Jul 2024 18:10:12 +0200 Subject: [PATCH] Convert all the strings passed to Re.match to raw string notation --- dim-testsuite/tests/pdns_util.py | 2 +- dim/dim/dns.py | 6 +++--- dim/dim/models/dns.py | 2 +- dim/dim/models/ip.py | 2 +- dim/dim/models/migrate.py | 2 +- dim/dim/rrtype.py | 4 ++-- ndcli/dimcli/__init__.py | 6 +++--- ndcli/dimcli/cliparse.py | 2 +- 8 files changed, 13 insertions(+), 13 deletions(-) diff --git a/dim-testsuite/tests/pdns_util.py b/dim-testsuite/tests/pdns_util.py index 540ced61..37d87653 100644 --- a/dim-testsuite/tests/pdns_util.py +++ b/dim-testsuite/tests/pdns_util.py @@ -28,7 +28,7 @@ def onetab(s): return re.sub('\t+', '\t', s) def compact(zone): - return sorted(set(onetab(l) for l in zone.splitlines() if not re.match('^\s*(;.*)?\s*?$', l))) + return sorted(set(onetab(l) for l in zone.splitlines() if not re.match(r'^\s*(;.*)?\s*?$', l))) def zones_equal(a, b): diff --git a/dim/dim/dns.py b/dim/dim/dns.py index a056d85b..896b4a8f 100644 --- a/dim/dim/dns.py +++ b/dim/dim/dns.py @@ -86,14 +86,14 @@ def get_ip_from_ptr_name(ptr_name, strict=True): if ptr_name.endswith('.in-addr.arpa.'): labels = list(reversed(ptr_name[:-len('.in-addr.arpa.')].split('.'))) # remove rfc 2317 subnet markers - labels = [p for p in labels if re.match('^\d+$', p)] + labels = [p for p in labels if re.match(r'^\d+$', p)] if not strict and len(labels) < 4: labels += ['0'] * (4 - len(labels)) if len(labels) == 4: return '.'.join(labels) elif ptr_name.endswith('.ip6.arpa.'): labels = list(reversed(ptr_name[:-len('.ip6.arpa.')].split('.'))) - labels = [p for p in labels if re.match('^[0-9a-fA-F]+$', p)] + labels = [p for p in labels if re.match(r'^[0-9a-fA-F]+$', p)] if not strict and len(labels) < 32: labels += ['0'] * (32 - len(labels)) if len(labels) == 32: @@ -507,7 +507,7 @@ def check_view_removal_from_output(view, output): def get_subzones(zone): descendants = Zone.query.filter(Zone.name.like('%.' + zone.name)).all() - return [s for s in descendants if re.match('^[^\.]+\.%s$' % zone.name, s.name)] + return [s for s in descendants if re.match(r'^[^\.]+\.%s$' % zone.name, s.name)] def get_parent_zone(zone_name): diff --git a/dim/dim/models/dns.py b/dim/dim/models/dns.py index da14a7c2..8c08dcdb 100644 --- a/dim/dim/models/dns.py +++ b/dim/dim/models/dns.py @@ -97,7 +97,7 @@ def check_nsec3params(nsec3_algorithm, nsec3_iterations, nsec3_salt): raise InvalidParameterError('Invalid NSEC3 algorithm (must be 0 for disabled or 1 for sha1)') if not (0 <= nsec3_iterations <= 65535): raise InvalidParameterError('Invalid NSEC3 iteration count (must be between 0 and 65535)') - if not (nsec3_salt == '-' or (re.match('^[0-9a-fA-F]+$', nsec3_salt) and len(nsec3_salt) <= 510)): + if not (nsec3_salt == '-' or (re.match(r'^[0-9a-fA-F]+$', nsec3_salt) and len(nsec3_salt) <= 510)): raise InvalidParameterError('Invalid NSEC3 salt (must be a hexadecimal string or "-")') def set_nsec3params(self, nsec3_algorithm, nsec3_iterations, nsec3_salt): diff --git a/dim/dim/models/ip.py b/dim/dim/models/ip.py index 2b586c8b..4d916cf3 100644 --- a/dim/dim/models/ip.py +++ b/dim/dim/models/ip.py @@ -132,7 +132,7 @@ def __str__(self): @validates('name') def validate_name(self, key, name): - if not re.match('^[A-Za-z0-9][-_A-Za-z0-9]*$', name): + if not re.match(r'^[A-Za-z0-9][-_A-Za-z0-9]*$', name): raise ValueError("Invalid pool name: '%s'" % name) return name diff --git a/dim/dim/models/migrate.py b/dim/dim/models/migrate.py index fc53c279..b98c4c8f 100644 --- a/dim/dim/models/migrate.py +++ b/dim/dim/models/migrate.py @@ -39,7 +39,7 @@ def migrate(): def gather_graph(): graph = {} for script in pkg_resources.resource_listdir('dim', 'sql'): - m = re.match('(migrate|rollback)_(.*)_to_(.*).sql', script) + m = re.match(r'(migrate|rollback)_(.*)_to_(.*).sql', script) if m: x, y = m.group(2), m.group(3) graph.setdefault(x, []).append((y, script)) diff --git a/dim/dim/rrtype.py b/dim/dim/rrtype.py index 98a7e374..332eb3a1 100644 --- a/dim/dim/rrtype.py +++ b/dim/dim/rrtype.py @@ -14,7 +14,7 @@ def label_is_valid(label): len(label) > 63 or label.startswith('-') or label.endswith('-') or - not re.match('^[_a-z0-9-/]+$', label)): + not re.match(r'^[_a-z0-9-/]+$', label)): return False return True @@ -98,7 +98,7 @@ def validate_certificate(self, key, value, **kwargs): def validate_hexstring(self, key, value, **kwargs): - if ' ' in value or not re.match('^[0-9a-fA-F]*$', value) or len(value) % 2 != 0: + if ' ' in value or not re.match(r'^[0-9a-fA-F]*$', value) or len(value) % 2 != 0: raise InvalidParameterError("Invalid %s: %s" % (key, value)) return value diff --git a/ndcli/dimcli/__init__.py b/ndcli/dimcli/__init__.py index 002c0d07..07acf911 100644 --- a/ndcli/dimcli/__init__.py +++ b/ndcli/dimcli/__init__.py @@ -526,7 +526,7 @@ def complete_rr_value(token, parser): def _fill_rr_options(options, rr_type, params, args): - if rr_type == 'PTR' and re.match('^(((\d+\.){3}\d+)|(.*:.*))$', args.name): + if rr_type == 'PTR' and re.match(r'^(((\d+\.){3}\d+)|(.*:.*))$', args.name): options['ip'] = args.name else: options['name'] = args.name @@ -705,7 +705,7 @@ def _get_soa_attributes(args): def _parse_attributes(cmd_attrs): attributes = {} for keyval in cmd_attrs: - m = re.match('^(.*?):(.*)$', keyval) + m = re.match(r'^(.*?):(.*)$', keyval) if not m: raise Exception("'%s' must have the form NAME:VALUE" % keyval) else: @@ -736,7 +736,7 @@ def _parse_query(query): return dict(pool='*') elif query.isdigit() and int(query) >= 2 and int(query) <= 4096: return dict(vlan=int(query)) - elif re.match('^.*/\d{1,3}$', query): + elif re.match(r'^.*/\d{1,3}$', query): return dict(cidr=query) else: return dict(pool=query) diff --git a/ndcli/dimcli/cliparse.py b/ndcli/dimcli/cliparse.py index 92e7e575..1742e028 100644 --- a/ndcli/dimcli/cliparse.py +++ b/ndcli/dimcli/cliparse.py @@ -430,7 +430,7 @@ def complete(self, line, point): else: raise tokens = tokens[1:] # skip the program name - if tokens and (line[-1] != ' ' or line[-2:] == '\ '): + if tokens and (line[-1] != ' ' or line[-2:] == r'\ '): complete_token = tokens.pop() else: complete_token = ''