-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
bpo-25567: Add the support of bytes in quotes. #10871
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
bpo-25567: Add the support of bytes in quotes. #10871
Conversation
Hello, and thanks for your contribution! I'm a bot set up to make sure that the project can legally accept your contribution by verifying you have signed the PSF contributor agreement (CLA). Unfortunately we couldn't find an account corresponding to your GitHub username on bugs.python.org (b.p.o) to verify you have signed the CLA (this might be simply due to a missing "GitHub Name" entry in your b.p.o account settings). This is necessary for legal reasons before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue. You can check yourself to see if the CLA has been received. Thanks again for your contribution, we look forward to reviewing it! |
0e210a3
to
0235ef5
Compare
0235ef5
to
e82a4c0
Compare
cases where you cannot use a list. | ||
Return a shell-escaped version of the string *s* or the bytes object. The | ||
returned value is a string literal or bytes that can safely be used as one | ||
token in a shell command line, for cases where you cannot use a list. | ||
|
||
This idiom would be unsafe: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should add ".. versionchanged:: 3.8" markup and describe the new feature.
Lib/shlex.py
Outdated
@@ -306,17 +306,24 @@ def split(s, comments=False, posix=True): | |||
|
|||
|
|||
_find_unsafe = re.compile(r'[^\w@%+=:,./-]', re.ASCII).search | |||
_find_unsafe_bytes = re.compile(b'[^\w@%+=:,./-]', re.ASCII).search |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
re.ASCII is useless here, no?
Lib/shlex.py
Outdated
|
||
# use single quotes, and put single quotes into double quotes | ||
# the string $'b is then quoted as '$'"'"'b' | ||
return "'" + s.replace("'", "'\"'\"'") + "'" | ||
return b"'" + s.replace(b"'", b"'\"'\"'") + b"'" \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move the code inside previous if/else.
@@ -0,0 +1 @@ | |||
Added the support of bytes in quote method from shlex module. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the support of bytes in quote method from shlex module. | |
Add the bytes support to the :func:`shlex.quote` function. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might amend the commit message (and use git push --force) to use "Co-Authored-By:" instead of "Co-authored-by:". I don't know if tools checking for "Co-Authored-By:" are case sensitive?
Add the support of bytes in quotes method in shlex module. Co-authored-by: Nan Wu <nanbytesflow@gmail.com>
e82a4c0
to
448bde6
Compare
Closing and reopening to trigger CI builds. |
@@ -306,17 +306,23 @@ def split(s, comments=False, posix=True): | |||
|
|||
|
|||
_find_unsafe = re.compile(r'[^\w@%+=:,./-]', re.ASCII).search | |||
_find_unsafe_bytes = re.compile(b'[^\w@%+=:,./-]').search |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_find_unsafe_bytes = re.compile(b'[^\w@%+=:,./-]').search | |
_find_unsafe_bytes = re.compile(br'[^\w@%+=:,./-]').search |
This line generates a SyntaxWarning
that causes test failure in CI where assert_python_ok
asserts for no output in stderr that has this SyntaxWarning
. Perhaps use a raw string ?
/Users/karthikeyansingaravelan/stuff/python/cpython/Lib/shlex.py:309: SyntaxWarning: invalid escape sequence \w
_find_unsafe_bytes = re.compile(b'[^\w@%+=:,./-]').search
@hobbestigrou, please address the code review comments. Thank you! |
Closing due to inactivity. This issue is now available for someone else to work on it. If this PR is used in a new PR, please remember to credit to original author. Thanks! |
Add the support of bytes in quotes method.
Co-authored-by: Nan Wu nanbytesflow@gmail.com
https://bugs.python.org/issue25567