summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1995-08-10 19:26:37 (GMT)
committerGuido van Rossum <guido@python.org>1995-08-10 19:26:37 (GMT)
commit3b8e1604e8dd4c871e5e8a22d6c738c7f2d39f3a (patch)
tree663aa5133f46c3f16c895eb99e4933c34c5da43b /Lib
parent4ac00503048942340dddb4b9194494716a9ae1fb (diff)
downloadcpython-3b8e1604e8dd4c871e5e8a22d6c738c7f2d39f3a.zip
cpython-3b8e1604e8dd4c871e5e8a22d6c738c7f2d39f3a.tar.gz
cpython-3b8e1604e8dd4c871e5e8a22d6c738c7f2d39f3a.tar.bz2
upgdaded the test program
Diffstat (limited to 'Lib')
-rwxr-xr-xLib/base64.py22
1 files changed, 18 insertions, 4 deletions
diff --git a/Lib/base64.py b/Lib/base64.py
index 2f9bdc1..55f01ce 100755
--- a/Lib/base64.py
+++ b/Lib/base64.py
@@ -109,11 +109,25 @@ def decodestring(s):
# Small test program, reads stdin, writes stdout.
# no arg: encode, any arg: decode.
def test():
- import sys
- if sys.argv[1:]:
- decode(sys.stdin, sys.stdout)
+ import sys, getopt
+ try:
+ opts, args = getopt.getopt(sys.argv[1:], 'deut')
+ except getopt.error, msg:
+ print msg
+ print """usage: basd64 [-d] [-e] [-u] [-t] [file|-]
+ -d, -u: decode
+ -e: encode (default)
+ -t: decode string 'Aladdin:open sesame'"""
+ func = encode
+ for o, a in opts:
+ if o == '-e': func = encode
+ if o == '-d': func = decode
+ if o == '-u': func = decode
+ if o == '-t': test1(); return
+ if args and args[0] != '-':
+ func(open(args[0]), sys.stdout)
else:
- encode(sys.stdin, sys.stdout)
+ func(sys.stdin, sys.stdout)
def test1():
s0 = "Aladdin:open sesame"