diff options
author | Guido van Rossum <guido@python.org> | 2000-02-02 15:10:15 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2000-02-02 15:10:15 (GMT) |
commit | 4acc25bd392216c4f867a10ca8081e7c8a739676 (patch) | |
tree | db4976fa172404339b31aa7485a5316634e4c699 /Lib/base64.py | |
parent | 113e70efa2b932a3ad2662875114133a1edb600c (diff) | |
download | cpython-4acc25bd392216c4f867a10ca8081e7c8a739676.zip cpython-4acc25bd392216c4f867a10ca8081e7c8a739676.tar.gz cpython-4acc25bd392216c4f867a10ca8081e7c8a739676.tar.bz2 |
Mass patch by Ka-Ping Yee:
1. Comments at the beginning of the module, before
functions, and before classes have been turned
into docstrings.
2. Tabs are normalized to four spaces.
Also, removed the "remove" function from dircmp.py, which reimplements
list.remove() (it must have been very old).
Diffstat (limited to 'Lib/base64.py')
-rwxr-xr-x | Lib/base64.py | 112 |
1 files changed, 57 insertions, 55 deletions
diff --git a/Lib/base64.py b/Lib/base64.py index 2c72214..5ef2081 100755 --- a/Lib/base64.py +++ b/Lib/base64.py @@ -1,7 +1,7 @@ #! /usr/bin/env python -# Conversions to/from base64 transport encoding as per RFC-1521. -# +"""Conversions to/from base64 transport encoding as per RFC-1521.""" + # Modified 04-Oct-95 by Jack to use binascii module import binascii @@ -9,69 +9,71 @@ import binascii MAXLINESIZE = 76 # Excluding the CRLF MAXBINSIZE = (MAXLINESIZE/4)*3 -# Encode a file. def encode(input, output): - while 1: - s = input.read(MAXBINSIZE) - if not s: break - while len(s) < MAXBINSIZE: - ns = input.read(MAXBINSIZE-len(s)) - if not ns: break - s = s + ns - line = binascii.b2a_base64(s) - output.write(line) + """Encode a file.""" + while 1: + s = input.read(MAXBINSIZE) + if not s: break + while len(s) < MAXBINSIZE: + ns = input.read(MAXBINSIZE-len(s)) + if not ns: break + s = s + ns + line = binascii.b2a_base64(s) + output.write(line) -# Decode a file. def decode(input, output): - while 1: - line = input.readline() - if not line: break - s = binascii.a2b_base64(line) - output.write(s) + """Decode a file.""" + while 1: + line = input.readline() + if not line: break + s = binascii.a2b_base64(line) + output.write(s) def encodestring(s): - import StringIO - f = StringIO.StringIO(s) - g = StringIO.StringIO() - encode(f, g) - return g.getvalue() + """Encode a string.""" + import StringIO + f = StringIO.StringIO(s) + g = StringIO.StringIO() + encode(f, g) + return g.getvalue() def decodestring(s): - import StringIO - f = StringIO.StringIO(s) - g = StringIO.StringIO() - decode(f, g) - return g.getvalue() + """Decode a string.""" + import StringIO + f = StringIO.StringIO(s) + g = StringIO.StringIO() + decode(f, g) + return g.getvalue() -# Small test program def test(): - import sys, getopt - try: - opts, args = getopt.getopt(sys.argv[1:], 'deut') - except getopt.error, msg: - sys.stdout = sys.stderr - print msg - print """usage: basd64 [-d] [-e] [-u] [-t] [file|-] - -d, -u: decode - -e: encode (default) - -t: decode string 'Aladdin:open sesame'""" - sys.exit(2) - 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], 'rb'), sys.stdout) - else: - func(sys.stdin, sys.stdout) + """Small test program""" + import sys, getopt + try: + opts, args = getopt.getopt(sys.argv[1:], 'deut') + except getopt.error, msg: + sys.stdout = sys.stderr + print msg + print """usage: basd64 [-d] [-e] [-u] [-t] [file|-] + -d, -u: decode + -e: encode (default) + -t: decode string 'Aladdin:open sesame'""" + sys.exit(2) + 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], 'rb'), sys.stdout) + else: + func(sys.stdin, sys.stdout) def test1(): - s0 = "Aladdin:open sesame" - s1 = encodestring(s0) - s2 = decodestring(s1) - print s0, `s1`, s2 + s0 = "Aladdin:open sesame" + s1 = encodestring(s0) + s2 = decodestring(s1) + print s0, `s1`, s2 if __name__ == '__main__': - test() + test() |