]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
upgdaded the test program
authorGuido van Rossum <guido@python.org>
Thu, 10 Aug 1995 19:26:37 +0000 (19:26 +0000)
committerGuido van Rossum <guido@python.org>
Thu, 10 Aug 1995 19:26:37 +0000 (19:26 +0000)
Lib/base64.py

index 2f9bdc1340e54cbd351a0ee62412238d046c3fdc..55f01ced092cde691ad6fa5bf712b59772361fc2 100755 (executable)
@@ -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"