diff -r d083b6ead156 Lib/base64.py --- a/Lib/base64.py Mon Mar 10 11:05:07 2014 +0100 +++ b/Lib/base64.py Mon Mar 10 13:24:31 2014 +0200 @@ -139,7 +139,7 @@ # Base32 encoding/decoding must be done in Python _b32alphabet = b'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567' _b32tab = [bytes([i]) for i in _b32alphabet] -_b32tab2 = [a + b for a in _b32tab for b in _b32tab] +_b32tab2 = None _b32rev = {v: k for k, v in enumerate(_b32alphabet)} def b32encode(s): @@ -155,6 +155,9 @@ s = s + bytes(5 - leftover) # Don't use += ! encoded = bytearray() from_bytes = int.from_bytes + global _b32tab2 + if _b32tab2 is None: + _b32tab2 = [a + b for a in _b32tab for b in _b32tab] b32tab2 = _b32tab2 for i in range(0, len(s), 5): c = from_bytes(s[i: i + 5], 'big') @@ -284,8 +287,6 @@ b = b + b'\0' * padding words = struct.Struct('!%dI' % (len(b) // 4)).unpack(b) - a85chars2 = _a85chars2 - a85chars = _a85chars chunks = [b'z' if foldnuls and not word else b'y' if foldspaces and word == 0x20202020 else (chars2[word // 614125] + @@ -303,7 +304,7 @@ _A85START = b"<~" _A85END = b"~>" _a85chars = [bytes([i]) for i in range(33, 118)] -_a85chars2 = [(a + b) for a in _a85chars for b in _a85chars] +_a85chars2 = None def a85encode(b, *, foldspaces=False, wrapcol=0, pad=False, adobe=False): """Encode a byte string using Ascii85. @@ -324,6 +325,9 @@ adobe controls whether the encoded byte sequence is framed with <~ and ~>, which is used by the Adobe implementation. """ + global _a85chars2 + if _a85chars2 is None: + _a85chars2 = [a + b for a in _a85chars for b in _a85chars] result = _85encode(b, _a85chars, _a85chars2, pad, True, foldspaces) if adobe: @@ -411,7 +415,7 @@ _b85chars = b"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" \ b"abcdefghijklmnopqrstuvwxyz!#$%&()*+-;<=>?@^_`{|}~" _b85chars = [bytes([i]) for i in _b85chars] -_b85chars2 = [(a + b) for a in _b85chars for b in _b85chars] +_b85chars2 = None _b85dec = None def b85encode(b, pad=False): @@ -420,6 +424,9 @@ If pad is true, the input is padded with "\0" so its length is a multiple of 4 characters before encoding. """ + global _b85chars2 + if _b85chars2 is None: + _b85chars2 = [a + b for a in _b85chars for b in _b85chars] return _85encode(b, _b85chars, _b85chars2, pad) def b85decode(b):