Skip to content

bpo-30103: Allow Uuencode in Python using backtick as zero instead of space#1326

Merged
zhangyangyu merged 10 commits intopython:masterfrom
zhangyangyu:bpo-30103
May 3, 2017
Merged

bpo-30103: Allow Uuencode in Python using backtick as zero instead of space#1326
zhangyangyu merged 10 commits intopython:masterfrom
zhangyangyu:bpo-30103

Conversation

@zhangyangyu
Copy link
Copy Markdown
Member

No description provided.

@mention-bot
Copy link
Copy Markdown

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

Comment thread 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`.)
Copy link
Copy Markdown
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.

Comment thread 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)
Copy link
Copy Markdown
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
Copy Markdown
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.

Comment thread Lib/test/test_uu.py
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
Copy Markdown
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
Copy Markdown
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.

Comment thread Modules/binascii.c Outdated

/* Store the length */
*ascii_data++ = ' ' + (bin_len & 077);
if (backtick)
Copy link
Copy Markdown
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
Copy Markdown
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.

Comment thread 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
Copy link
Copy Markdown
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 (\')

Comment thread Modules/binascii.c
binascii.b2a_uu

data: Py_buffer
/
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

Comment thread Lib/test/test_uu.py Outdated
UUStdIOTest,
UUFileTest,
)
support.run_unittest(UUTest, UUStdIOTest, UUFileTest)
Copy link
Copy Markdown
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?

Comment thread 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.
Copy link
Copy Markdown
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.

Comment thread Doc/library/binascii.rst Outdated


.. function:: b2a_uu(data)
.. function:: b2a_uu(data, \*, backtick=False)
Copy link
Copy Markdown
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.

Comment thread Modules/binascii.c Outdated
if (backtick && !bin_len)
*ascii_data++ = '`';
else
*ascii_data++ = ' ' + (bin_len & 077);
Copy link
Copy Markdown
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
Copy Markdown
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