-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
bpo-30103: Allow Uuencode in Python using backtick as zero instead of space #1326
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
Conversation
@zhangyangyu, thanks for your PR! By analyzing the history of the files in this pull request, we identified @doerwalter, @serhiy-storchaka and @warsaw to be potential reviewers. |
Doc/whatsnew/3.7.rst
Outdated
|
||
The :func:`~binascii.b2a_uu` function now accepts an optional *backtick* | ||
keyword argument. When it's true, zeros are represented by backticks | ||
instead of spaces. (Contributed by Xiang Zhang in :issue:`30103`.) |
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.
Double space after a period.
Lib/test/test_binascii.py
Outdated
b'$`$-A=```\n') | ||
self.assertEqual(binascii.a2b_uu(b'$`$-A=```\n'), | ||
binascii.a2b_uu(b'$ $-A= \n')) | ||
self.assertRaises(TypeError, binascii.b2a_uu, b'', b'`\n', True) |
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.
What does this test mean?
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.
backtick is expected to be keyword-only. But sorry I make some mistake here.
def encodedtextwrapped(mode, filename, backtick=False): | ||
if backtick: | ||
res = (bytes("begin %03o %s\n" % (mode, filename), "ascii") + | ||
encodedtext.replace(b' ', b'`') + b"\n`\nend\n") |
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.
Seems the only space in encodedtext is the padding space. It would be worth to change examples so that they include inner spaces.
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.
Good catch. I found it when write the test too but didn't change it.
Modules/binascii.c
Outdated
@@ -367,7 +368,10 @@ binascii_b2a_uu_impl(PyObject *module, Py_buffer *data) | |||
return NULL; | |||
|
|||
/* Store the length */ | |||
*ascii_data++ = ' ' + (bin_len & 077); | |||
if (backtick) |
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.
May be
if (backtick && !bin_len)
*ascii_data++ = '`';
else
*ascii_data++ = ' ' + (bin_len & 077);
?
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.
It's good. The code seems more clear telling the logic that only zero needs to be specially treated.
Lib/test/test_uu.py
Outdated
|
||
encodedtext = b"""\ | ||
M5&AE('-M;V]T:\"US8V%L960@<'ET:&]N(&-R97!T(&]V97(@=&AE('-L965P | ||
(:6YG(&1O9PH """ | ||
M5&AE(\'-Y;6)O;\',@;VX@=&]P(&]F(\'EO=7(@:V5Y8F]A<F0@87)E("% (R0E |
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.
I don’t think you need to escape the quotes (\'
)
Modules/binascii.c
Outdated
@@ -334,14 +334,15 @@ binascii_a2b_uu_impl(PyObject *module, Py_buffer *data) | |||
binascii.b2a_uu | |||
|
|||
data: Py_buffer | |||
/ |
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.
Was this intended? If so, it needs documenting and testing, but it would be good to avoid if possible. Can’t you put a slash and asterisk after each other to have positional-only and then keyword-only parameters?
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.
AC currently seems doesn't support combining positional-only parameters with keyword-only parameters. So it's not intended but a side effect.
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.
It does, I just checked this.
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.
Ohh, nice.
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.
While I support keeping data positional-only, but in bpo-25357 b2a_base64
was changed and as a side effect data is able to accept a keyword argument. The consistency that functions in module binascii all support a positional-only data was broken. What's your mind @serhiy-storchaka and @vadmium ? We keep data positional-only or just make it like b2a_base64
or make b2a_base64
data back?
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.
It looks to me that change in bpo-25357 was not intentional. Perhaps we can revert it. Open a new issue for this.
Lib/test/test_uu.py
Outdated
UUStdIOTest, | ||
UUFileTest, | ||
) | ||
support.run_unittest(UUTest, UUStdIOTest, UUFileTest) |
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.
This seems like an insignificant change. Wouldn’t it be simple to use “unittest.main” instead?
Doc/library/binascii.rst
Outdated
|
||
Convert binary data to a line of ASCII characters, the return value is the | ||
converted line, including a newline char. The length of *data* should be at most | ||
45. | ||
45. If *backtick* is true, zeros are represented by backticks instead of spaces. |
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.
Show the backtick character explicitly, as
``"`"``
And in all other cases where it is mentioned.
Doc/library/binascii.rst
Outdated
@@ -40,11 +40,14 @@ The :mod:`binascii` module defines the following functions: | |||
data may be followed by whitespace. | |||
|
|||
|
|||
.. function:: b2a_uu(data) | |||
.. function:: b2a_uu(data, \*, backtick=False) |
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.
AFAIK the backslash is not needed here.
Modules/binascii.c
Outdated
if (backtick && !bin_len) | ||
*ascii_data++ = '`'; | ||
else | ||
*ascii_data++ = ' ' + (bin_len & 077); |
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.
Actually & 077
is not needed. bin_len is not larger than 45.
Thanks @serhiy-storchaka and @vadmium ! |
No description provided.