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

Merged
merged 1 commit into from
Sep 10, 2024

Conversation

jessie-murray
Copy link
Contributor

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.

@LenzGr
Copy link

LenzGr commented Jun 21, 2024

Came across this PR while googling for the error. This was observed on Mac OS (installed via Homebrew):

$ s3cmd --version
/opt/homebrew/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)?$",
/opt/homebrew/Cellar/s3cmd/2.4.0_1/libexec/lib/python3.12/site-packages/S3/S3Uri.py:170: SyntaxWarning: invalid escape sequence '\w'
  _re = re.compile("^(\w+://)?(.*)", re.UNICODE)
/opt/homebrew/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)
s3cmd version 2.4.0

Applying this patch removes the warnings. Is there anything missing to get this PR merged?

@urjitbhatia
Copy link

@lavigne958 can we please get this merged?

@lavigne958
Copy link
Contributor

@lavigne958 can we please get this merged?

Hi, I wish I could. This is not my repository 😅

@urjitbhatia
Copy link

@fviard nudge nudge :)

@fviard fviard merged commit 7369a19 into s3tools:master Sep 10, 2024
@fviard
Copy link
Contributor

fviard commented Sep 10, 2024

Merged, thank you very much!

@fviard fviard linked an issue Sep 10, 2024 that may be closed by this pull request
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.

SyntaxWarnings "invalid escape sequence" in S3Uri.py and FileLists.py
5 participants