From 1fbaa63201534e3d07c9d9e8bfbf1800ef8086b1 Mon Sep 17 00:00:00 2001 From: Oleg Iarygin Date: Fri, 24 Jun 2022 19:20:18 +0300 Subject: [PATCH 1/7] Remove `python -m base64 -t` --- Lib/base64.py | 14 +------------- .../2022-06-24-19-16-09.gh-issue-93096.r1_oIc.rst | 3 +++ 2 files changed, 4 insertions(+), 13 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2022-06-24-19-16-09.gh-issue-93096.r1_oIc.rst diff --git a/Lib/base64.py b/Lib/base64.py index 7e9c2a2ca477ff..ca57484143965d 100755 --- a/Lib/base64.py +++ b/Lib/base64.py @@ -570,8 +570,7 @@ def main(): usage = """usage: %s [-h|-d|-e|-u|-t] [file|-] -h: print this help message and exit -d, -u: decode - -e: encode (default) - -t: encode and decode string 'Aladdin:open sesame'"""%sys.argv[0] + -e: encode (default)"""%sys.argv[0] try: opts, args = getopt.getopt(sys.argv[1:], 'hdeut') except getopt.error as msg: @@ -584,7 +583,6 @@ def main(): if o == '-e': func = encode if o == '-d': func = decode if o == '-u': func = decode - if o == '-t': test(); return if o == '-h': print(usage); return if args and args[0] != '-': with open(args[0], 'rb') as f: @@ -593,15 +591,5 @@ def main(): func(sys.stdin.buffer, sys.stdout.buffer) -def test(): - s0 = b"Aladdin:open sesame" - print(repr(s0)) - s1 = encodebytes(s0) - print(repr(s1)) - s2 = decodebytes(s1) - print(repr(s2)) - assert s0 == s2 - - if __name__ == '__main__': main() diff --git a/Misc/NEWS.d/next/Library/2022-06-24-19-16-09.gh-issue-93096.r1_oIc.rst b/Misc/NEWS.d/next/Library/2022-06-24-19-16-09.gh-issue-93096.r1_oIc.rst new file mode 100644 index 00000000000000..c62b70aeabd197 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2022-06-24-19-16-09.gh-issue-93096.r1_oIc.rst @@ -0,0 +1,3 @@ +Removed the ``-t`` argument from undocumented ``python -m base64``. This +argument performed an encode/decode test that lost any value after +``test.test_base64.LegacyBase64TestCase.test_encodebytes`` was introduced. From 5c6ff7c30829f1baafaf99ab7b9bbab67a7063b7 Mon Sep 17 00:00:00 2001 From: Oleg Iarygin Date: Fri, 24 Jun 2022 19:45:36 +0300 Subject: [PATCH 2/7] Make a changelog entry stronger. --- .../Library/2022-06-24-19-16-09.gh-issue-93096.r1_oIc.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Misc/NEWS.d/next/Library/2022-06-24-19-16-09.gh-issue-93096.r1_oIc.rst b/Misc/NEWS.d/next/Library/2022-06-24-19-16-09.gh-issue-93096.r1_oIc.rst index c62b70aeabd197..536a9d7cab1b81 100644 --- a/Misc/NEWS.d/next/Library/2022-06-24-19-16-09.gh-issue-93096.r1_oIc.rst +++ b/Misc/NEWS.d/next/Library/2022-06-24-19-16-09.gh-issue-93096.r1_oIc.rst @@ -1,3 +1,3 @@ -Removed the ``-t`` argument from undocumented ``python -m base64``. This -argument performed an encode/decode test that lost any value after -``test.test_base64.LegacyBase64TestCase.test_encodebytes`` was introduced. +Removed undocumented ``-t`` argument of ``python -m base64``. Use +``python -m unittest test.test_base64.LegacyBase64TestCase.test_encodebytes`` +instead. From cc58d751b7704c5a39967a648db3b8a635c2d5ae Mon Sep 17 00:00:00 2001 From: Oleg Iarygin Date: Fri, 24 Jun 2022 19:51:06 +0300 Subject: [PATCH 3/7] Remove an associated test --- Lib/test/test_base64.py | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/Lib/test/test_base64.py b/Lib/test/test_base64.py index 217f2945468844..80417d1cf6bd12 100644 --- a/Lib/test/test_base64.py +++ b/Lib/test/test_base64.py @@ -759,17 +759,6 @@ def tearDown(self): if os.path.exists(os_helper.TESTFN): os.unlink(os_helper.TESTFN) - def get_output(self, *args): - return script_helper.assert_python_ok('-m', 'base64', *args).out - - def test_encode_decode(self): - output = self.get_output('-t') - self.assertSequenceEqual(output.splitlines(), ( - b"b'Aladdin:open sesame'", - br"b'QWxhZGRpbjpvcGVuIHNlc2FtZQ==\n'", - b"b'Aladdin:open sesame'", - )) - def test_encode_file(self): with open(os_helper.TESTFN, 'wb') as fp: fp.write(b'a\xffb\n') From 16d3dcc82fb6ae7fb67308d2889abac52852a091 Mon Sep 17 00:00:00 2001 From: Oleg Iarygin Date: Fri, 24 Jun 2022 20:42:29 +0300 Subject: [PATCH 4/7] Return get_output back --- Lib/test/test_base64.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Lib/test/test_base64.py b/Lib/test/test_base64.py index 80417d1cf6bd12..00f91b993cd66e 100644 --- a/Lib/test/test_base64.py +++ b/Lib/test/test_base64.py @@ -759,6 +759,9 @@ def tearDown(self): if os.path.exists(os_helper.TESTFN): os.unlink(os_helper.TESTFN) + def get_output(self, *args): + return script_helper.assert_python_ok('-m', 'base64', *args).out + def test_encode_file(self): with open(os_helper.TESTFN, 'wb') as fp: fp.write(b'a\xffb\n') From 28eb67803509837fa6dacc9a6413fe602935be9d Mon Sep 17 00:00:00 2001 From: Oleg Iarygin Date: Sat, 2 Jul 2022 09:13:27 +0300 Subject: [PATCH 5/7] Move the removed demo string into tests --- Lib/test/test_base64.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Lib/test/test_base64.py b/Lib/test/test_base64.py index 00f91b993cd66e..e023e655d8d7c2 100644 --- a/Lib/test/test_base64.py +++ b/Lib/test/test_base64.py @@ -31,6 +31,8 @@ def test_encodebytes(self): b"YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNE" b"RUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0\nNT" b"Y3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ==\n") + eq(base64.encodebytes(b"Aladdin:open sesame", + b"QWxhZGRpbjpvcGVuIHNlc2FtZQ==\n")) # Non-bytes eq(base64.encodebytes(bytearray(b'abc')), b'YWJj\n') eq(base64.encodebytes(memoryview(b'abc')), b'YWJj\n') @@ -50,6 +52,8 @@ def test_decodebytes(self): b"ABCDEFGHIJKLMNOPQRSTUVWXYZ" b"0123456789!@#0^&*();:<>,. []{}") eq(base64.decodebytes(b''), b'') + eq(base64.encodebytes(b"QWxhZGRpbjpvcGVuIHNlc2FtZQ==\n", + b"Aladdin:open sesame")) # Non-bytes eq(base64.decodebytes(bytearray(b'YWJj\n')), b'abc') eq(base64.decodebytes(memoryview(b'YWJj\n')), b'abc') From 63ad2a786dd5c62e47a8f803b593191b7eee011a Mon Sep 17 00:00:00 2001 From: Oleg Iarygin Date: Sat, 2 Jul 2022 09:18:46 +0300 Subject: [PATCH 6/7] Extra fixes --- Lib/test/test_base64.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Lib/test/test_base64.py b/Lib/test/test_base64.py index e023e655d8d7c2..fa03fa1d61ceab 100644 --- a/Lib/test/test_base64.py +++ b/Lib/test/test_base64.py @@ -31,8 +31,8 @@ def test_encodebytes(self): b"YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNE" b"RUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0\nNT" b"Y3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ==\n") - eq(base64.encodebytes(b"Aladdin:open sesame", - b"QWxhZGRpbjpvcGVuIHNlc2FtZQ==\n")) + eq(base64.encodebytes(b"Aladdin:open sesame"), + b"QWxhZGRpbjpvcGVuIHNlc2FtZQ==\n") # Non-bytes eq(base64.encodebytes(bytearray(b'abc')), b'YWJj\n') eq(base64.encodebytes(memoryview(b'abc')), b'YWJj\n') @@ -52,8 +52,8 @@ def test_decodebytes(self): b"ABCDEFGHIJKLMNOPQRSTUVWXYZ" b"0123456789!@#0^&*();:<>,. []{}") eq(base64.decodebytes(b''), b'') - eq(base64.encodebytes(b"QWxhZGRpbjpvcGVuIHNlc2FtZQ==\n", - b"Aladdin:open sesame")) + eq(base64.decodebytes(b"QWxhZGRpbjpvcGVuIHNlc2FtZQ==\n"), + b"Aladdin:open sesame") # Non-bytes eq(base64.decodebytes(bytearray(b'YWJj\n')), b'abc') eq(base64.decodebytes(memoryview(b'YWJj\n')), b'abc') From 43a4474f4527a67ce39488e07b177a11b4841cc1 Mon Sep 17 00:00:00 2001 From: Oleg Iarygin Date: Sat, 2 Jul 2022 09:21:14 +0300 Subject: [PATCH 7/7] Convert a usage string into an f-string --- Lib/base64.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/base64.py b/Lib/base64.py index ca57484143965d..30796a6fd6d05a 100755 --- a/Lib/base64.py +++ b/Lib/base64.py @@ -567,10 +567,10 @@ def decodebytes(s): def main(): """Small main program""" import sys, getopt - usage = """usage: %s [-h|-d|-e|-u|-t] [file|-] + usage = f"""usage: {sys.argv[0]} [-h|-d|-e|-u|-t] [file|-] -h: print this help message and exit -d, -u: decode - -e: encode (default)"""%sys.argv[0] + -e: encode (default)""" try: opts, args = getopt.getopt(sys.argv[1:], 'hdeut') except getopt.error as msg: