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

cleanup: fixes regex escape warnings in S3Uri.py, FileLists.py #1370

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

Conversation

jessie-murray
Copy link

Hi,

Similar to the regex escaping issues reported in #1351, it looks like there are still a few invalid escape sequences in S3Uri.py and FileLists.py in s3cmd version 2.4.0.

I saw these warnings while uploading a file:

/usr/local/Cellar/s3cmd/2.4.0_1/libexec/lib/python3.12/site-packages/S3/S3Uri.py:122: SyntaxWarning: invalid escape sequence '\.'
  m = re.match("(.*\.)?s3(?:\-[^\.]*)?(?:\.dualstack)?(?:\.[^\.]*)?\.amazonaws\.com(?:\.cn)?$",
/usr/local/Cellar/s3cmd/2.4.0_1/libexec/lib/python3.12/site-packages/S3/S3Uri.py:173: SyntaxWarning: invalid escape sequence '\w'
  _re = re.compile("^(\w+://)?(.*)", re.UNICODE)
/usr/local/Cellar/s3cmd/2.4.0_1/libexec/lib/python3.12/site-packages/S3/FileLists.py:525: SyntaxWarning: invalid escape sequence '\*'
  wildcard_split_result = re.split("\*|\?", uri_str, maxsplit=1)

The first is from this line:

s3cmd/S3/S3Uri.py

Lines 122 to 123 in dbdee8f

m = re.match("(.*\.)?s3(?:\-[^\.]*)?(?:\.dualstack)?(?:\.[^\.]*)?\.amazonaws\.com(?:\.cn)?$",
hostname, re.IGNORECASE | re.UNICODE)

The \ characters are interpreted as escaping characters in the Python string itself.

The second warning is about the same issue for a different line, where only one \ needs to be escaped or at least interpreted differently, the one in \w:

_re = re.compile("^(\w+://)?(.*)", re.UNICODE)

And the third one from here:

wildcard_split_result = re.split("\*|\?", uri_str, maxsplit=1)

There are many different ways to fix this problem, but I saw that commit 7ebafbe was linked from #1351 so I used the same technique here, I hope this works for you.

Mark two strings in S3Uri.py and one string in FileLists.py as
literal regex strings to address "invalid escape sequence" syntax
warnings.
Copy link
Contributor

@lavigne958 lavigne958 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me, I tried it and it works (for the URI match where the bucket website name is extracted.

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.

None yet

2 participants