Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix regex warnings by removing extra escapes '\' not needed #35

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

NeroBurner
Copy link
Contributor

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
  • 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)

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: #33

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ubuntu 24.04 noble warns about invalid escape sequence
1 participant