@@ -508,25 +508,16 @@ def b85decode(b):
508508
509509def encode (input , output ):
510510 """Encode a file; input and output are binary files."""
511- while True :
512- s = input .read (MAXBINSIZE )
513- if not s :
514- break
515- while len (s ) < MAXBINSIZE :
516- ns = input .read (MAXBINSIZE - len (s ))
517- if not ns :
518- break
511+ while s := input .read (MAXBINSIZE ):
512+ while len (s ) < MAXBINSIZE and (ns := input .read (MAXBINSIZE - len (s ))):
519513 s += ns
520514 line = binascii .b2a_base64 (s )
521515 output .write (line )
522516
523517
524518def decode (input , output ):
525519 """Decode a file; input and output are binary files."""
526- while True :
527- line = input .readline ()
528- if not line :
529- break
520+ while line := input .readline ():
530521 s = binascii .a2b_base64 (line )
531522 output .write (s )
532523
@@ -567,13 +558,12 @@ def decodebytes(s):
567558def main ():
568559 """Small main program"""
569560 import sys , getopt
570- usage = """usage: %s [-h|-d|-e|-u|-t ] [file|-]
561+ usage = f """usage: { sys . argv [ 0 ] } [-h|-d|-e|-u] [file|-]
571562 -h: print this help message and exit
572563 -d, -u: decode
573- -e: encode (default)
574- -t: encode and decode string 'Aladdin:open sesame'""" % sys .argv [0 ]
564+ -e: encode (default)"""
575565 try :
576- opts , args = getopt .getopt (sys .argv [1 :], 'hdeut ' )
566+ opts , args = getopt .getopt (sys .argv [1 :], 'hdeu ' )
577567 except getopt .error as msg :
578568 sys .stdout = sys .stderr
579569 print (msg )
@@ -584,7 +574,6 @@ def main():
584574 if o == '-e' : func = encode
585575 if o == '-d' : func = decode
586576 if o == '-u' : func = decode
587- if o == '-t' : test (); return
588577 if o == '-h' : print (usage ); return
589578 if args and args [0 ] != '-' :
590579 with open (args [0 ], 'rb' ) as f :
@@ -593,15 +582,5 @@ def main():
593582 func (sys .stdin .buffer , sys .stdout .buffer )
594583
595584
596- def test ():
597- s0 = b"Aladdin:open sesame"
598- print (repr (s0 ))
599- s1 = encodebytes (s0 )
600- print (repr (s1 ))
601- s2 = decodebytes (s1 )
602- print (repr (s2 ))
603- assert s0 == s2
604-
605-
606585if __name__ == '__main__' :
607586 main ()
0 commit comments