check in for patch #430846

use faster code for base64.encodestring (courtesy of Mr. Tim Peters)
and for base64.decodestring (courtesy of Anthony Baxter)
This commit is contained in:
Peter Schneider-Kamp 2001-06-07 18:56:13 +00:00
parent a4debfffc9
commit fbb2b4c4a5
1 changed files with 6 additions and 10 deletions

View File

@ -33,19 +33,15 @@ def decode(input, output):
def encodestring(s):
"""Encode a string."""
import StringIO
f = StringIO.StringIO(s)
g = StringIO.StringIO()
encode(f, g)
return g.getvalue()
pieces = []
for i in range(0, len(s), MAXBINSIZE):
chunk = s[i : i + MAXBINSIZE]
pieces.append(binascii.b2a_base64(chunk))
return "".join(pieces)
def decodestring(s):
"""Decode a string."""
import StringIO
f = StringIO.StringIO(s)
g = StringIO.StringIO()
decode(f, g)
return g.getvalue()
return binascii.a2b_base64(s)
def test():
"""Small test program"""