s3cmd icon indicating copy to clipboard operation
s3cmd copied to clipboard

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

Open jessie-murray opened this issue 1 year ago • 1 comments

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: https://github.com/s3tools/s3cmd/blob/dbdee8fa850b8c41249c22dc44b1bd6d3116a06d/S3/S3Uri.py#L122-L123

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: https://github.com/s3tools/s3cmd/blob/dbdee8fa850b8c41249c22dc44b1bd6d3116a06d/S3/S3Uri.py#L170

And the third one from here: https://github.com/s3tools/s3cmd/blob/dbdee8fa850b8c41249c22dc44b1bd6d3116a06d/S3/FileLists.py#L525

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

jessie-murray avatar Apr 06 '24 19:04 jessie-murray

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?

LenzGr avatar Jun 21 '24 13:06 LenzGr

@lavigne958 can we please get this merged?

urjitbhatia avatar Sep 10 '24 17:09 urjitbhatia

@lavigne958 can we please get this merged?

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

lavigne958 avatar Sep 10 '24 19:09 lavigne958

@fviard nudge nudge :)

urjitbhatia avatar Sep 10 '24 19:09 urjitbhatia

Merged, thank you very much!

fviard avatar Sep 10 '24 23:09 fviard