From: Anthony Baxter Date: Wed, 5 Dec 2001 04:34:13 +0000 (+0000) Subject: backport of 1.12 X-Git-Tag: v2.1.2c1~70 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=77aee7e57d54ca1276a7f9cd7196cd6331382e1f;p=thirdparty%2FPython%2Fcpython.git backport of 1.12 check in for patch #430846 use faster code for base64.encodestring (courtesy of Mr. Tim Peters) and for base64.decodestring (courtesy of Anthony Baxter) --- diff --git a/Lib/base64.py b/Lib/base64.py index 290fa83a047a..44cd03a20fcd 100755 --- a/Lib/base64.py +++ b/Lib/base64.py @@ -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"""