Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fbb2b4c

Browse files
author
Peter Schneider-Kamp
committed
check in for patch #430846
use faster code for base64.encodestring (courtesy of Mr. Tim Peters) and for base64.decodestring (courtesy of Anthony Baxter)
1 parent a4debff commit fbb2b4c

1 file changed

Lines changed: 6 additions & 10 deletions

File tree

Lib/base64.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,15 @@ def decode(input, output):
3333

3434
def encodestring(s):
3535
"""Encode a string."""
36-
import StringIO
37-
f = StringIO.StringIO(s)
38-
g = StringIO.StringIO()
39-
encode(f, g)
40-
return g.getvalue()
36+
pieces = []
37+
for i in range(0, len(s), MAXBINSIZE):
38+
chunk = s[i : i + MAXBINSIZE]
39+
pieces.append(binascii.b2a_base64(chunk))
40+
return "".join(pieces)
4141

4242
def decodestring(s):
4343
"""Decode a string."""
44-
import StringIO
45-
f = StringIO.StringIO(s)
46-
g = StringIO.StringIO()
47-
decode(f, g)
48-
return g.getvalue()
44+
return binascii.a2b_base64(s)
4945

5046
def test():
5147
"""Small test program"""

0 commit comments

Comments
 (0)