From a45a02b6fdf73f219f3d897a6ea7be184be14129 Mon Sep 17 00:00:00 2001 From: Xiang Zhang Date: Thu, 27 Apr 2017 19:15:19 +0800 Subject: [PATCH 1/7] allow Uuencode using backticks instead of spaces to represent zeros --- Doc/library/binascii.rst | 7 +++- Doc/library/uu.rst | 8 +++- Doc/whatsnew/3.7.rst | 14 +++++++ Lib/test/test_binascii.py | 35 ++++++++++++------ Lib/test/test_uu.py | 73 ++++++++++++++++++++++--------------- Lib/uu.py | 13 ++++--- Misc/NEWS | 3 ++ Modules/binascii.c | 17 ++++++--- Modules/clinic/binascii.c.h | 18 +++++---- 9 files changed, 126 insertions(+), 62 deletions(-) diff --git a/Doc/library/binascii.rst b/Doc/library/binascii.rst index 0476f507717cda..f4a7aae636d62f 100644 --- a/Doc/library/binascii.rst +++ b/Doc/library/binascii.rst @@ -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) 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. + + .. versionchanged:: 3.7 + Added the *backtick* parameter. .. function:: a2b_base64(string) diff --git a/Doc/library/uu.rst b/Doc/library/uu.rst index 33fb36d0b8cea5..dce6588ff6f656 100644 --- a/Doc/library/uu.rst +++ b/Doc/library/uu.rst @@ -28,12 +28,16 @@ This code was contributed by Lance Ellinghouse, and modified by Jack Jansen. The :mod:`uu` module defines the following functions: -.. function:: encode(in_file, out_file, name=None, mode=None) +.. function:: encode(in_file, out_file, name=None, mode=None, \*, backtick=False) Uuencode file *in_file* into file *out_file*. The uuencoded file will have the header specifying *name* and *mode* as the defaults for the results of decoding the file. The default defaults are taken from *in_file*, or ``'-'`` - and ``0o666`` respectively. + and ``0o666`` respectively. If *backtick* is true, zeros are represented by + backticks instead of spaces. + + .. versionchanged:: 3.7 + Added the *backtick* parameter. .. function:: decode(in_file, out_file=None, mode=None, quiet=False) diff --git a/Doc/whatsnew/3.7.rst b/Doc/whatsnew/3.7.rst index 875fc556912cae..69a715b3b44084 100644 --- a/Doc/whatsnew/3.7.rst +++ b/Doc/whatsnew/3.7.rst @@ -95,6 +95,13 @@ New Modules Improved Modules ================ +binascii +-------- + +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`.) + distutils --------- @@ -153,6 +160,13 @@ urllib.parse adding `~` to the set of characters that is never quoted by default. (Contributed by Christian Theune and Ratnadeep Debnath in :issue:`16285`.) +uu +-- + +Function :func:`~uu.encode` 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`.) + Optimizations ============= diff --git a/Lib/test/test_binascii.py b/Lib/test/test_binascii.py index 6b3e437f4366ef..3569c4cf23fa15 100644 --- a/Lib/test/test_binascii.py +++ b/Lib/test/test_binascii.py @@ -112,29 +112,40 @@ def addnoise(line): def test_uu(self): MAX_UU = 45 - lines = [] - for i in range(0, len(self.data), MAX_UU): - b = self.type2test(self.rawdata[i:i+MAX_UU]) - a = binascii.b2a_uu(b) - lines.append(a) - res = bytes() - for line in lines: - a = self.type2test(line) - b = binascii.a2b_uu(a) - res += b - self.assertEqual(res, self.rawdata) + for backtick in (True, False): + lines = [] + for i in range(0, len(self.data), MAX_UU): + b = self.type2test(self.rawdata[i:i+MAX_UU]) + a = binascii.b2a_uu(b, backtick=backtick) + lines.append(a) + res = bytes() + for line in lines: + a = self.type2test(line) + b = binascii.a2b_uu(a) + res += b + self.assertEqual(res, self.rawdata) self.assertEqual(binascii.a2b_uu(b"\x7f"), b"\x00"*31) self.assertEqual(binascii.a2b_uu(b"\x80"), b"\x00"*32) self.assertEqual(binascii.a2b_uu(b"\xff"), b"\x00"*31) self.assertRaises(binascii.Error, binascii.a2b_uu, b"\xff\x00") self.assertRaises(binascii.Error, binascii.a2b_uu, b"!!!!") - self.assertRaises(binascii.Error, binascii.b2a_uu, 46*b"!") # Issue #7701 (crash on a pydebug build) self.assertEqual(binascii.b2a_uu(b'x'), b'!> \n') + self.assertEqual(binascii.b2a_uu(b''), b' \n') + self.assertEqual(binascii.b2a_uu(b'', backtick=True), b'`\n') + self.assertEqual(binascii.a2b_uu(b' \n'), b'') + self.assertEqual(binascii.a2b_uu(b'`\n'), b'') + self.assertEqual(binascii.b2a_uu(b'\x00Cat'), b'$ $-A= \n') + self.assertEqual(binascii.b2a_uu(b'\x00Cat', backtick=True), + 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) + def test_crc_hqx(self): crc = binascii.crc_hqx(self.type2test(b"Test the CRC-32 of"), 0) crc = binascii.crc_hqx(self.type2test(b" this string."), crc) diff --git a/Lib/test/test_uu.py b/Lib/test/test_uu.py index ad2f2c59c1089b..ae18ec76a4dbe1 100644 --- a/Lib/test/test_uu.py +++ b/Lib/test/test_uu.py @@ -44,9 +44,14 @@ def getvalue(self): return self.buffer.getvalue().decode(self._encoding, self._errors) -def encodedtextwrapped(mode, filename): - return (bytes("begin %03o %s\n" % (mode, filename), "ascii") + - encodedtext + b"\n \nend\n") +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") + else: + res = (bytes("begin %03o %s\n" % (mode, filename), "ascii") + + encodedtext + b"\n \nend\n") + return res class UUTest(unittest.TestCase): @@ -59,20 +64,25 @@ def test_encode(self): out = io.BytesIO() uu.encode(inp, out, "t1", 0o644) self.assertEqual(out.getvalue(), encodedtextwrapped(0o644, "t1")) + inp = io.BytesIO(plaintext) + out = io.BytesIO() + uu.encode(inp, out, "t1", backtick=True) + self.assertEqual(out.getvalue(), encodedtextwrapped(0o666, "t1", True)) def test_decode(self): - inp = io.BytesIO(encodedtextwrapped(0o666, "t1")) - out = io.BytesIO() - uu.decode(inp, out) - self.assertEqual(out.getvalue(), plaintext) - inp = io.BytesIO( - b"UUencoded files may contain many lines,\n" + - b"even some that have 'begin' in them.\n" + - encodedtextwrapped(0o666, "t1") - ) - out = io.BytesIO() - uu.decode(inp, out) - self.assertEqual(out.getvalue(), plaintext) + for backtick in True, False: + inp = io.BytesIO(encodedtextwrapped(0o666, "t1", backtick=backtick)) + out = io.BytesIO() + uu.decode(inp, out) + self.assertEqual(out.getvalue(), plaintext) + inp = io.BytesIO( + b"UUencoded files may contain many lines,\n" + + b"even some that have 'begin' in them.\n" + + encodedtextwrapped(0o666, "t1", backtick=backtick) + ) + out = io.BytesIO() + uu.decode(inp, out) + self.assertEqual(out.getvalue(), plaintext) def test_truncatedinput(self): inp = io.BytesIO(b"begin 644 t1\n" + encodedtext) @@ -94,25 +104,33 @@ def test_missingbegin(self): def test_garbage_padding(self): # Issue #22406 - encodedtext = ( + encodedtext1 = ( b"begin 644 file\n" # length 1; bits 001100 111111 111111 111111 b"\x21\x2C\x5F\x5F\x5F\n" b"\x20\n" b"end\n" ) + encodedtext2 = ( + b"begin 644 file\n" + # length 1; bits 001100 111111 111111 111111 + b"\x21\x2C\x5F\x5F\x5F\n" + b"\x60\n" + b"end\n" + ) plaintext = b"\x33" # 00110011 - with self.subTest("uu.decode()"): - inp = io.BytesIO(encodedtext) - out = io.BytesIO() - uu.decode(inp, out, quiet=True) - self.assertEqual(out.getvalue(), plaintext) + for encodedtext in encodedtext1, encodedtext2: + with self.subTest("uu.decode()"): + inp = io.BytesIO(encodedtext) + out = io.BytesIO() + uu.decode(inp, out, quiet=True) + self.assertEqual(out.getvalue(), plaintext) - with self.subTest("uu_codec"): - import codecs - decoded = codecs.decode(encodedtext, "uu_codec") - self.assertEqual(decoded, plaintext) + with self.subTest("uu_codec"): + import codecs + decoded = codecs.decode(encodedtext, "uu_codec") + self.assertEqual(decoded, plaintext) class UUStdIOTest(unittest.TestCase): @@ -251,10 +269,7 @@ def test_decodetwice(self): self._kill(f) def test_main(): - support.run_unittest(UUTest, - UUStdIOTest, - UUFileTest, - ) + support.run_unittest(UUTest, UUStdIOTest, UUFileTest) if __name__=="__main__": test_main() diff --git a/Lib/uu.py b/Lib/uu.py index d68d29374a8bbf..8333e864d8f95d 100755 --- a/Lib/uu.py +++ b/Lib/uu.py @@ -26,8 +26,8 @@ """Implementation of the UUencode and UUdecode functions. -encode(in_file, out_file [,name, mode]) -decode(in_file [, out_file, mode]) +encode(in_file, out_file [,name, mode], *, backtick=False) +decode(in_file [, out_file, mode, quiet]) """ import binascii @@ -39,7 +39,7 @@ class Error(Exception): pass -def encode(in_file, out_file, name=None, mode=None): +def encode(in_file, out_file, name=None, mode=None, *, backtick=False): """Uuencode file""" # # If in_file is a pathname open it and change defaults @@ -79,9 +79,12 @@ def encode(in_file, out_file, name=None, mode=None): out_file.write(('begin %o %s\n' % ((mode & 0o777), name)).encode("ascii")) data = in_file.read(45) while len(data) > 0: - out_file.write(binascii.b2a_uu(data)) + out_file.write(binascii.b2a_uu(data, backtick=backtick)) data = in_file.read(45) - out_file.write(b' \nend\n') + if backtick: + out_file.write(b'`\nend\n') + else: + out_file.write(b' \nend\n') finally: for f in opened_files: f.close() diff --git a/Misc/NEWS b/Misc/NEWS index 71db0ee46b0dc4..4526b06e0aa737 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -317,6 +317,9 @@ Extension Modules Library ------- +- bpo-30103: binascii.b2a_uu() and uu.encode() now support using backtick + as zero instead of space. + - bpo-30101: Add support for curses.A_ITALIC. - bpo-29822: inspect.isabstract() now works during __init_subclass__. Patch diff --git a/Modules/binascii.c b/Modules/binascii.c index bf6ce86f445d96..0bc6f9d4fce4e4 100644 --- a/Modules/binascii.c +++ b/Modules/binascii.c @@ -334,14 +334,15 @@ binascii_a2b_uu_impl(PyObject *module, Py_buffer *data) binascii.b2a_uu data: Py_buffer - / + * + backtick: bool(accept={int}) = False Uuencode line of data. [clinic start generated code]*/ static PyObject * -binascii_b2a_uu_impl(PyObject *module, Py_buffer *data) -/*[clinic end generated code: output=0070670e52e4aa6b input=00fdf458ce8b465b]*/ +binascii_b2a_uu_impl(PyObject *module, Py_buffer *data, int backtick) +/*[clinic end generated code: output=b1b99de62d9bbeb8 input=141f61b6ceb56af6]*/ { unsigned char *ascii_data; const unsigned char *bin_data; @@ -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) + *ascii_data++ = bin_len ? ' ' + (bin_len & 077) : '`'; + else + *ascii_data++ = ' ' + (bin_len & 077); for( ; bin_len > 0 || leftbits != 0 ; bin_len--, bin_data++ ) { /* Shift the data (or padding) into our buffer */ @@ -381,7 +385,10 @@ binascii_b2a_uu_impl(PyObject *module, Py_buffer *data) while ( leftbits >= 6 ) { this_ch = (leftchar >> (leftbits-6)) & 0x3f; leftbits -= 6; - *ascii_data++ = this_ch + ' '; + if (backtick) + *ascii_data++ = this_ch ? this_ch + ' ' : '`'; + else + *ascii_data++ = this_ch + ' '; } } *ascii_data++ = '\n'; /* Append a courtesy newline */ diff --git a/Modules/clinic/binascii.c.h b/Modules/clinic/binascii.c.h index 093d32bb234d3f..387f2a6a2a925c 100644 --- a/Modules/clinic/binascii.c.h +++ b/Modules/clinic/binascii.c.h @@ -34,27 +34,31 @@ binascii_a2b_uu(PyObject *module, PyObject *arg) } PyDoc_STRVAR(binascii_b2a_uu__doc__, -"b2a_uu($module, data, /)\n" +"b2a_uu($module, /, data, *, backtick=False)\n" "--\n" "\n" "Uuencode line of data."); #define BINASCII_B2A_UU_METHODDEF \ - {"b2a_uu", (PyCFunction)binascii_b2a_uu, METH_O, binascii_b2a_uu__doc__}, + {"b2a_uu", (PyCFunction)binascii_b2a_uu, METH_FASTCALL, binascii_b2a_uu__doc__}, static PyObject * -binascii_b2a_uu_impl(PyObject *module, Py_buffer *data); +binascii_b2a_uu_impl(PyObject *module, Py_buffer *data, int backtick); static PyObject * -binascii_b2a_uu(PyObject *module, PyObject *arg) +binascii_b2a_uu(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; + static const char * const _keywords[] = {"data", "backtick", NULL}; + static _PyArg_Parser _parser = {"y*|$i:b2a_uu", _keywords, 0}; Py_buffer data = {NULL, NULL}; + int backtick = 0; - if (!PyArg_Parse(arg, "y*:b2a_uu", &data)) { + if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, + &data, &backtick)) { goto exit; } - return_value = binascii_b2a_uu_impl(module, &data); + return_value = binascii_b2a_uu_impl(module, &data, backtick); exit: /* Cleanup for data */ @@ -558,4 +562,4 @@ binascii_b2a_qp(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *k return return_value; } -/*[clinic end generated code: output=4a418f883ccc79fe input=a9049054013a1b77]*/ +/*[clinic end generated code: output=25820051c57501c7 input=a9049054013a1b77]*/ From 7f39aee8c953f5cbd5ce8045b95e93556ae8e66f Mon Sep 17 00:00:00 2001 From: Xiang Zhang Date: Fri, 28 Apr 2017 17:33:17 +0800 Subject: [PATCH 2/7] address Serhiy's comments --- Doc/whatsnew/3.7.rst | 4 ++-- Lib/test/test_binascii.py | 3 ++- Lib/test/test_uu.py | 8 +++++--- Modules/binascii.c | 8 ++++---- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/Doc/whatsnew/3.7.rst b/Doc/whatsnew/3.7.rst index 69a715b3b44084..646d00403f6f86 100644 --- a/Doc/whatsnew/3.7.rst +++ b/Doc/whatsnew/3.7.rst @@ -100,7 +100,7 @@ binascii 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`.) +instead of spaces. (Contributed by Xiang Zhang in :issue:`30103`.) distutils --------- @@ -165,7 +165,7 @@ uu Function :func:`~uu.encode` 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`.) +instead of spaces. (Contributed by Xiang Zhang in :issue:`30103`.) Optimizations diff --git a/Lib/test/test_binascii.py b/Lib/test/test_binascii.py index 3569c4cf23fa15..8fa57cdf1b0be3 100644 --- a/Lib/test/test_binascii.py +++ b/Lib/test/test_binascii.py @@ -144,7 +144,8 @@ def test_uu(self): 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) + with self.assertRaises(TypeError): + binascii.b2a_uu(b"", True) def test_crc_hqx(self): crc = binascii.crc_hqx(self.type2test(b"Test the CRC-32 of"), 0) diff --git a/Lib/test/test_uu.py b/Lib/test/test_uu.py index ae18ec76a4dbe1..cd8e34e304a9f1 100644 --- a/Lib/test/test_uu.py +++ b/Lib/test/test_uu.py @@ -10,11 +10,11 @@ import uu import io -plaintext = b"The smooth-scaled python crept over the sleeping dog\n" +plaintext = b"The symbols on top of your keyboard are !@#$%^&*()_+|~\n" 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= 6 ) { this_ch = (leftchar >> (leftbits-6)) & 0x3f; leftbits -= 6; - if (backtick) - *ascii_data++ = this_ch ? this_ch + ' ' : '`'; + if (backtick && !this_ch) + *ascii_data++ = '`'; else *ascii_data++ = this_ch + ' '; } From 9cf21f614836fc1f3843defb17b6840d17bf0228 Mon Sep 17 00:00:00 2001 From: Xiang Zhang Date: Sat, 29 Apr 2017 15:00:42 +0800 Subject: [PATCH 3/7] address Martin's comments --- Lib/test/test_uu.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Lib/test/test_uu.py b/Lib/test/test_uu.py index cd8e34e304a9f1..11bd08c80edd98 100644 --- a/Lib/test/test_uu.py +++ b/Lib/test/test_uu.py @@ -13,7 +13,7 @@ plaintext = b"The symbols on top of your keyboard are !@#$%^&*()_+|~\n" encodedtext = b"""\ -M5&AE(\'-Y;6)O;\',@;VX@=&]P(&]F(\'EO=7(@:V5Y8F]A Date: Sat, 29 Apr 2017 16:13:51 +0800 Subject: [PATCH 4/7] restore data to positional-only --- Lib/test/test_binascii.py | 2 ++ Modules/binascii.c | 3 ++- Modules/clinic/binascii.c.h | 6 +++--- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Lib/test/test_binascii.py b/Lib/test/test_binascii.py index 8fa57cdf1b0be3..a23b1956c2c49a 100644 --- a/Lib/test/test_binascii.py +++ b/Lib/test/test_binascii.py @@ -144,6 +144,8 @@ def test_uu(self): b'$`$-A=```\n') self.assertEqual(binascii.a2b_uu(b'$`$-A=```\n'), binascii.a2b_uu(b'$ $-A= \n')) + with self.assertRaises(TypeError): + binascii.b2a_uu(data=b"") with self.assertRaises(TypeError): binascii.b2a_uu(b"", True) diff --git a/Modules/binascii.c b/Modules/binascii.c index 5f3618ccf167c2..4b89e863c06ef9 100644 --- a/Modules/binascii.c +++ b/Modules/binascii.c @@ -334,6 +334,7 @@ binascii_a2b_uu_impl(PyObject *module, Py_buffer *data) binascii.b2a_uu data: Py_buffer + / * backtick: bool(accept={int}) = False @@ -342,7 +343,7 @@ Uuencode line of data. static PyObject * binascii_b2a_uu_impl(PyObject *module, Py_buffer *data, int backtick) -/*[clinic end generated code: output=b1b99de62d9bbeb8 input=141f61b6ceb56af6]*/ +/*[clinic end generated code: output=b1b99de62d9bbeb8 input=b26bc8d32b6ed2f6]*/ { unsigned char *ascii_data; const unsigned char *bin_data; diff --git a/Modules/clinic/binascii.c.h b/Modules/clinic/binascii.c.h index 387f2a6a2a925c..837c6262630d6e 100644 --- a/Modules/clinic/binascii.c.h +++ b/Modules/clinic/binascii.c.h @@ -34,7 +34,7 @@ binascii_a2b_uu(PyObject *module, PyObject *arg) } PyDoc_STRVAR(binascii_b2a_uu__doc__, -"b2a_uu($module, /, data, *, backtick=False)\n" +"b2a_uu($module, data, /, *, backtick=False)\n" "--\n" "\n" "Uuencode line of data."); @@ -49,7 +49,7 @@ static PyObject * binascii_b2a_uu(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; - static const char * const _keywords[] = {"data", "backtick", NULL}; + static const char * const _keywords[] = {"", "backtick", NULL}; static _PyArg_Parser _parser = {"y*|$i:b2a_uu", _keywords, 0}; Py_buffer data = {NULL, NULL}; int backtick = 0; @@ -562,4 +562,4 @@ binascii_b2a_qp(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *k return return_value; } -/*[clinic end generated code: output=25820051c57501c7 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=45a2defa52613bad input=a9049054013a1b77]*/ From 8be2e95fe3597de7899467b6b02ee27901df3e56 Mon Sep 17 00:00:00 2001 From: Xiang Zhang Date: Sat, 29 Apr 2017 17:16:08 +0800 Subject: [PATCH 5/7] address Serhiy's comments --- Doc/library/binascii.rst | 6 +++--- Doc/library/uu.rst | 2 +- Doc/tools/susp-ignored.csv | 4 ++++ Doc/whatsnew/3.7.rst | 4 ++-- Misc/NEWS | 4 ++-- Modules/binascii.c | 2 +- 6 files changed, 13 insertions(+), 9 deletions(-) diff --git a/Doc/library/binascii.rst b/Doc/library/binascii.rst index f4a7aae636d62f..4d3d0e07f1861d 100644 --- a/Doc/library/binascii.rst +++ b/Doc/library/binascii.rst @@ -40,11 +40,11 @@ The :mod:`binascii` module defines the following functions: data may be followed by whitespace. -.. function:: b2a_uu(data, \*, backtick=False) +.. function:: b2a_uu(data, *, backtick=False) 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. If *backtick* is true, zeros are represented by backticks instead of spaces. + 45. If *backtick* is true, zeros are represented by ``'`'`` instead of spaces. .. versionchanged:: 3.7 Added the *backtick* parameter. @@ -56,7 +56,7 @@ The :mod:`binascii` module defines the following functions: than one line may be passed at a time. -.. function:: b2a_base64(data, \*, newline=True) +.. function:: b2a_base64(data, *, newline=True) Convert binary data to a line of ASCII characters in base64 coding. The return value is the converted line, including a newline char if *newline* is diff --git a/Doc/library/uu.rst b/Doc/library/uu.rst index dce6588ff6f656..e1e25cb077b691 100644 --- a/Doc/library/uu.rst +++ b/Doc/library/uu.rst @@ -34,7 +34,7 @@ The :mod:`uu` module defines the following functions: the header specifying *name* and *mode* as the defaults for the results of decoding the file. The default defaults are taken from *in_file*, or ``'-'`` and ``0o666`` respectively. If *backtick* is true, zeros are represented by - backticks instead of spaces. + ``'`'`` instead of spaces. .. versionchanged:: 3.7 Added the *backtick* parameter. diff --git a/Doc/tools/susp-ignored.csv b/Doc/tools/susp-ignored.csv index 01b1d98c149efc..ef11b685018b8c 100644 --- a/Doc/tools/susp-ignored.csv +++ b/Doc/tools/susp-ignored.csv @@ -328,3 +328,7 @@ whatsnew/3.5,,:exception,ERROR:root:exception whatsnew/changelog,,:version,import sys; I = version[:version.index(' ')] whatsnew/changelog,,`,"for readability (was ""`"")." whatsnew/changelog,,:end,str[start:end] +library/binascii,,`,'`' +library/uu,,`,'`' +whatsnew/3.7,,`,'`' +whatsnew/changelog,,`,'`' diff --git a/Doc/whatsnew/3.7.rst b/Doc/whatsnew/3.7.rst index 646d00403f6f86..77cc3f7e6cecd2 100644 --- a/Doc/whatsnew/3.7.rst +++ b/Doc/whatsnew/3.7.rst @@ -99,7 +99,7 @@ binascii -------- The :func:`~binascii.b2a_uu` function now accepts an optional *backtick* -keyword argument. When it's true, zeros are represented by backticks +keyword argument. When it's true, zeros are represented by ``'`'`` instead of spaces. (Contributed by Xiang Zhang in :issue:`30103`.) distutils @@ -164,7 +164,7 @@ uu -- Function :func:`~uu.encode` now accepts an optional *backtick* -keyword argument. When it's true, zeros are represented by backticks +keyword argument. When it's true, zeros are represented by ``'`'`` instead of spaces. (Contributed by Xiang Zhang in :issue:`30103`.) diff --git a/Misc/NEWS b/Misc/NEWS index 4526b06e0aa737..2089714ddb8ba1 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,7 +10,7 @@ What's New in Python 3.7.0 alpha 1? Core and Builtins ----------------- -- bpo-12414: sys.getsizeof() on a code object now returns the sizes +- bpo-12414: sys.getsizeof() on a code object now returns the sizes which includes the code struct and sizes of objects which it references. Patch by Dong-hee Na. @@ -317,7 +317,7 @@ Extension Modules Library ------- -- bpo-30103: binascii.b2a_uu() and uu.encode() now support using backtick +- bpo-30103: binascii.b2a_uu() and uu.encode() now support using ``'`'`` as zero instead of space. - bpo-30101: Add support for curses.A_ITALIC. diff --git a/Modules/binascii.c b/Modules/binascii.c index 4b89e863c06ef9..4dc4c78451417a 100644 --- a/Modules/binascii.c +++ b/Modules/binascii.c @@ -372,7 +372,7 @@ binascii_b2a_uu_impl(PyObject *module, Py_buffer *data, int backtick) if (backtick && !bin_len) *ascii_data++ = '`'; else - *ascii_data++ = ' ' + (bin_len & 077); + *ascii_data++ = ' ' + bin_len; for( ; bin_len > 0 || leftbits != 0 ; bin_len--, bin_data++ ) { /* Shift the data (or padding) into our buffer */ From 7c4f0e66d3d6f23408e6ee9f4cb84650d828e405 Mon Sep 17 00:00:00 2001 From: Xiang Zhang Date: Sat, 29 Apr 2017 17:28:06 +0800 Subject: [PATCH 6/7] remove unnecessary backslash --- Doc/library/uu.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/uu.rst b/Doc/library/uu.rst index e1e25cb077b691..0bc8021e1bdfc7 100644 --- a/Doc/library/uu.rst +++ b/Doc/library/uu.rst @@ -28,7 +28,7 @@ This code was contributed by Lance Ellinghouse, and modified by Jack Jansen. The :mod:`uu` module defines the following functions: -.. function:: encode(in_file, out_file, name=None, mode=None, \*, backtick=False) +.. function:: encode(in_file, out_file, name=None, mode=None, *, backtick=False) Uuencode file *in_file* into file *out_file*. The uuencoded file will have the header specifying *name* and *mode* as the defaults for the results of From 4b387f292e02329f058855c15cc6ee20146f6672 Mon Sep 17 00:00:00 2001 From: Xiang Zhang Date: Mon, 1 May 2017 13:01:40 +0800 Subject: [PATCH 7/7] remove positional-only test --- Lib/test/test_binascii.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/Lib/test/test_binascii.py b/Lib/test/test_binascii.py index a23b1956c2c49a..8fa57cdf1b0be3 100644 --- a/Lib/test/test_binascii.py +++ b/Lib/test/test_binascii.py @@ -144,8 +144,6 @@ def test_uu(self): b'$`$-A=```\n') self.assertEqual(binascii.a2b_uu(b'$`$-A=```\n'), binascii.a2b_uu(b'$ $-A= \n')) - with self.assertRaises(TypeError): - binascii.b2a_uu(data=b"") with self.assertRaises(TypeError): binascii.b2a_uu(b"", True)