[Python-checkins] gh-93096: Remove `python -m base64 -t` (gh-94230)
corona10
webhook-mailer at python.org
Sat Jul 2 02:53:54 EDT 2022
https://github.com/python/cpython/commit/7db1d2eaf367a1073191c80c7baeee41ae1f2f21
commit: 7db1d2eaf367a1073191c80c7baeee41ae1f2f21
branch: main
author: Oleg Iarygin <oleg at arhadthedev.net>
committer: corona10 <donghee.na92 at gmail.com>
date: 2022年07月02日T15:53:43+09:00
summary:
gh-93096: Remove `python -m base64 -t` (gh-94230)
files:
A Misc/NEWS.d/next/Library/2022-06-24-19-16-09.gh-issue-93096.r1_oIc.rst
M Lib/base64.py
M Lib/test/test_base64.py
diff --git a/Lib/base64.py b/Lib/base64.py
index 7e9c2a2ca477f..30796a6fd6d05 100755
--- a/Lib/base64.py
+++ b/Lib/base64.py
@@ -567,11 +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)
- -t: encode and decode string 'Aladdin:open sesame'"""%sys.argv[0]
+ -e: encode (default)"""
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/Lib/test/test_base64.py b/Lib/test/test_base64.py
index 217f294546884..fa03fa1d61cea 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.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')
@@ -762,14 +766,6 @@ def tearDown(self):
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')
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 0000000000000..536a9d7cab1b8
--- /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 undocumented ``-t`` argument of ``python -m base64``. Use
+``python -m unittest test.test_base64.LegacyBase64TestCase.test_encodebytes``
+instead.
More information about the Python-checkins
mailing list