Commit fbb2b4c4 authored by Peter Schneider-Kamp's avatar Peter Schneider-Kamp

check in for patch #430846

use faster code for base64.encodestring (courtesy of Mr. Tim Peters)
and for base64.decodestring (courtesy of Anthony Baxter)
parent a4debfff
...@@ -33,19 +33,15 @@ def decode(input, output): ...@@ -33,19 +33,15 @@ def decode(input, output):
def encodestring(s): def encodestring(s):
"""Encode a string.""" """Encode a string."""
import StringIO pieces = []
f = StringIO.StringIO(s) for i in range(0, len(s), MAXBINSIZE):
g = StringIO.StringIO() chunk = s[i : i + MAXBINSIZE]
encode(f, g) pieces.append(binascii.b2a_base64(chunk))
return g.getvalue() return "".join(pieces)
def decodestring(s): def decodestring(s):
"""Decode a string.""" """Decode a string."""
import StringIO return binascii.a2b_base64(s)
f = StringIO.StringIO(s)
g = StringIO.StringIO()
decode(f, g)
return g.getvalue()
def test(): def test():
"""Small test program""" """Small test program"""
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment