File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -109,11 +109,25 @@ def decodestring(s):
109109# Small test program, reads stdin, writes stdout.
110110# no arg: encode, any arg: decode.
111111def test ():
112- import sys
113- if sys .argv [1 :]:
114- decode (sys .stdin , sys .stdout )
112+ import sys , getopt
113+ try :
114+ opts , args = getopt .getopt (sys .argv [1 :], 'deut' )
115+ except getopt .error , msg :
116+ print msg
117+ print """usage: basd64 [-d] [-e] [-u] [-t] [file|-]
118+ -d, -u: decode
119+ -e: encode (default)
120+ -t: decode string 'Aladdin:open sesame'"""
121+ func = encode
122+ for o , a in opts :
123+ if o == '-e' : func = encode
124+ if o == '-d' : func = decode
125+ if o == '-u' : func = decode
126+ if o == '-t' : test1 (); return
127+ if args and args [0 ] != '-' :
128+ func (open (args [0 ]), sys .stdout )
115129 else :
116- encode (sys .stdin , sys .stdout )
130+ func (sys .stdin , sys .stdout )
117131
118132def test1 ():
119133 s0 = "Aladdin:open sesame"
You can’t perform that action at this time.
0 commit comments