Skip to content

Commit 7bdb1fa

Browse files
authored
Fix regex SyntaxWarnings (#610)
* Support negative-valued action parameters by converting them in the Python helper code into a positive value whose bit pattern is the 2's complement representation of the negative value. * Prevent SyntaxWarning occurrences when compiling several regex strings
1 parent ae9eb52 commit 7bdb1fa

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

utils/p4runtime_lib/convert.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
- Ethernet address strings
2424
'''
2525

26-
mac_pattern = re.compile('^([\da-fA-F]{2}:){5}([\da-fA-F]{2})$')
26+
mac_pattern = re.compile(r'^([\da-fA-F]{2}:){5}([\da-fA-F]{2})$')
2727
def matchesMac(mac_addr_string):
2828
return mac_pattern.match(mac_addr_string) is not None
2929

@@ -33,7 +33,7 @@ def encodeMac(mac_addr_string):
3333
def decodeMac(encoded_mac_addr):
3434
return ':'.join(s.hex() for s in encoded_mac_addr)
3535

36-
ip_pattern = re.compile('^(\d{1,3}\.){3}(\d{1,3})$')
36+
ip_pattern = re.compile(r'^(\d{1,3}\.){3}(\d{1,3})$')
3737
def matchesIPv4(ip_addr_string):
3838
return ip_pattern.match(ip_addr_string) is not None
3939

utils/p4runtime_lib/helper.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@ def get_alias(self, entity_type, id):
5959
def __getattr__(self, attr):
6060
# Synthesize convenience functions for name to id lookups for top-level entities
6161
# e.g. get_tables_id(name_string) or get_actions_id(name_string)
62-
m = re.search("^get_(\w+)_id$", attr)
62+
m = re.search(r"^get_(\w+)_id$", attr)
6363
if m:
6464
primitive = m.group(1)
6565
return lambda name: self.get_id(primitive, name)
6666

6767
# Synthesize convenience functions for id to name lookups
6868
# e.g. get_tables_name(id) or get_actions_name(id)
69-
m = re.search("^get_(\w+)_name$", attr)
69+
m = re.search(r"^get_(\w+)_name$", attr)
7070
if m:
7171
primitive = m.group(1)
7272
return lambda id: self.get_name(primitive, id)

0 commit comments

Comments
 (0)