Skip to content

Commit

Permalink
Merge pull request #281 from zakriya057/ITOUDP-5778
Browse files Browse the repository at this point in the history
Convert all the strings passed to Re.match to raw string notation
  • Loading branch information
miesi-ionos authored Aug 2, 2024
2 parents b9c6a40 + 503f526 commit 7d8a219
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion dim-testsuite/tests/pdns_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
6 changes: 3 additions & 3 deletions dim/dim/dns.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion dim/dim/models/dns.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion dim/dim/models/ip.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion dim/dim/models/migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions dim/dim/rrtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions ndcli/dimcli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion ndcli/dimcli/cliparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ''
Expand Down

0 comments on commit 7d8a219

Please sign in to comment.