summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Schneider-Kamp <nowonder@nowonder.de>2001-06-07 18:56:13 (GMT)
committerPeter Schneider-Kamp <nowonder@nowonder.de>2001-06-07 18:56:13 (GMT)
commitfbb2b4c4a5f38f8337f637b31300eb218608d050 (patch)
tree5499c27e11fb05dbcd2889254ad7f1434772f05b
parenta4debfffc98f05bff35bb1abc08a749e1753b983 (diff)
downloadcpython-fbb2b4c4a5f38f8337f637b31300eb218608d050.zip
cpython-fbb2b4c4a5f38f8337f637b31300eb218608d050.tar.gz
cpython-fbb2b4c4a5f38f8337f637b31300eb218608d050.tar.bz2
check in for patch #430846
use faster code for base64.encodestring (courtesy of Mr. Tim Peters) and for base64.decodestring (courtesy of Anthony Baxter)
-rwxr-xr-xLib/base64.py16
1 files changed, 6 insertions, 10 deletions
diff --git a/Lib/base64.py b/Lib/base64.py
index 290fa83..44cd03a 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"""