diff options
| author | Ammar Askar <ammar@ammaraskar.com> | 2021-10-07 01:38:43 (GMT) |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-10-07 01:38:43 (GMT) |
| commit | 5baec4aea6821256f5d1785a6bd596fab069f1b6 (patch) | |
| tree | 73c4f399fe7e55a6936b7d485b7b987023c4dadc /Lib/base64.py | |
| parent | e6ff4eba6da9b64aed235ba8d730b5645f71955c (diff) | |
| download | cpython-5baec4aea6821256f5d1785a6bd596fab069f1b6.zip cpython-5baec4aea6821256f5d1785a6bd596fab069f1b6.tar.gz cpython-5baec4aea6821256f5d1785a6bd596fab069f1b6.tar.bz2 | |
bpo-35970: Add help flag to base64 module (GH-28774)
This continues off rkuska's work from https://github.com/python/cpython/pull/11789 seeing as the patch wasn't updated to add tests.
Diffstat (limited to 'Lib/base64.py')
| -rwxr-xr-x | Lib/base64.py | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/Lib/base64.py b/Lib/base64.py index b25156d..7e9c2a2 100755 --- a/Lib/base64.py +++ b/Lib/base64.py @@ -567,15 +567,17 @@ def decodebytes(s): def main(): """Small main program""" import sys, getopt + 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] try: - opts, args = getopt.getopt(sys.argv[1:], 'deut') + opts, args = getopt.getopt(sys.argv[1:], 'hdeut') except getopt.error as msg: sys.stdout = sys.stderr print(msg) - print("""usage: %s [-d|-e|-u|-t] [file|-] - -d, -u: decode - -e: encode (default) - -t: encode and decode string 'Aladdin:open sesame'"""%sys.argv[0]) + print(usage) sys.exit(2) func = encode for o, a in opts: @@ -583,6 +585,7 @@ def main(): 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: func(f, sys.stdout.buffer) |
