Skip to content

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

Merged
merged 10 commits into from
May 3, 2017

Conversation

zhangyangyu
Copy link
Member

No description provided.

@mention-bot
Copy link

@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.


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`.)
Copy link
Member

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.

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)
Copy link
Member

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?

Copy link
Member Author

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")
Copy link
Member

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.

Copy link
Member Author

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.

@@ -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)
Copy link
Member

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);

?

Copy link
Member Author

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.


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
Copy link
Member

@vadmium vadmium Apr 29, 2017

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 (\')

@@ -334,14 +334,15 @@ binascii_a2b_uu_impl(PyObject *module, Py_buffer *data)
binascii.b2a_uu

data: Py_buffer
/
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ohh, nice.

Copy link
Member Author

@zhangyangyu zhangyangyu Apr 29, 2017

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?

Copy link
Member

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.

UUStdIOTest,
UUFileTest,
)
support.run_unittest(UUTest, UUStdIOTest, UUFileTest)
Copy link
Member

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?


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.
Copy link
Member

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.

@@ -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)
Copy link
Member

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.

if (backtick && !bin_len)
*ascii_data++ = '`';
else
*ascii_data++ = ' ' + (bin_len & 077);
Copy link
Member

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.

@zhangyangyu zhangyangyu merged commit 13f1f42 into python:master May 3, 2017
@zhangyangyu zhangyangyu deleted the bpo-30103 branch May 3, 2017 03:16
@zhangyangyu
Copy link
Member Author

Thanks @serhiy-storchaka and @vadmium !

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.

5 participants