Skip to content

Commit 6997a06

Browse files
committed
Fix regex warnings by removing extra escapes '\' not needed
On Ubuntu 24.04 with Python 3.12 two regexes showed the warning about invalid escape sequences: ``` aptly/publisher/__init__.py:179: SyntaxWarning: invalid escape sequence '\}' nodes_raw = re.findall('[ \t]+"([^"]+)".*label="{(Repo|Snapshot|Published) ([^|]+)[^\}"]+}"', dot_data) aptly/publisher/__init__.py:591: SyntaxWarning: invalid escape sequence '\ ' parsed = re.match('(.*)\ (.*)\ (.*)\ (.*)', ref) ``` Fix those regexes by removing the not needed escapes `\`. - the `}` inside the `[]` grouping doesn't need to be escaped - from: https://docs.python.org/3/howto/regex.html#matching-characters - Metacharacters (except `\`) are not active inside classes. For example, `[akm$]` will match any of the characters 'a', 'k', 'm', or '$'; '$' is usually a metacharacter, but inside a character class it’s stripped of its special nature. - the space character ` ` doesn't need to be escaped Tested on Ubuntu 18.04, 20.04, 22.04 and 24.04 with the `cleanup` command (which uses the first regex) and the `dump` command (which uses the second regex) ```sh python3 -m aptly.publisher -v --url http://example.com/aptly cleanup python3 -m aptly.publisher -v --url http://example.com/aptly dump --publish "all" ``` Fixes: tcpcloud#33
1 parent d9f07ca commit 6997a06

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

aptly/publisher/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def cleanup_snapshots(self):
176176
# extract nodes from dot-data
177177
# list of tuples with (node_id, node_type, node_name)
178178
# node_type is one of 'Repo'|'Snapshot'|'Publish'
179-
nodes_raw = re.findall('[ \t]+"([^"]+)".*label="{(Repo|Snapshot|Published) ([^|]+)[^\}"]+}"', dot_data)
179+
nodes_raw = re.findall('[ \t]+"([^"]+)".*label="{(Repo|Snapshot|Published) ([^|]+)[^}"]+}"', dot_data)
180180

181181
# convert nodes_raw into nodes
182182
# nodes = dict of node_id to node
@@ -588,7 +588,7 @@ def parse_package_ref(self, ref):
588588
"""
589589
if not ref:
590590
return None
591-
parsed = re.match('(.*)\ (.*)\ (.*)\ (.*)', ref)
591+
parsed = re.match('(.*) (.*) (.*) (.*)', ref)
592592
return parsed.groups()
593593

594594
def add(self, snapshot, component='main'):

0 commit comments

Comments
 (0)