diff options
author | Guido van Rossum <guido@python.org> | 2007-11-21 19:29:53 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2007-11-21 19:29:53 (GMT) |
commit | 254348e201647ad9d264de2cc0fde031e8214719 (patch) | |
tree | f5e6c42989ce114d4a9385404a6b23b2b1ff12af /Lib/base64.py | |
parent | 905a904723abadc627be60bf944e2ca76329b06e (diff) | |
download | cpython-254348e201647ad9d264de2cc0fde031e8214719.zip cpython-254348e201647ad9d264de2cc0fde031e8214719.tar.gz cpython-254348e201647ad9d264de2cc0fde031e8214719.tar.bz2 |
Rename buffer -> bytearray.
Diffstat (limited to 'Lib/base64.py')
-rwxr-xr-x | Lib/base64.py | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/Lib/base64.py b/Lib/base64.py index 18beffc..fc05ea9 100755 --- a/Lib/base64.py +++ b/Lib/base64.py @@ -27,13 +27,13 @@ __all__ = [ ] -bytes_buffer = (bytes, buffer) # Types acceptable as binary data +bytes_types = (bytes, bytearray) # Types acceptable as binary data def _translate(s, altchars): - if not isinstance(s, bytes_buffer): + if not isinstance(s, bytes_types): raise TypeError("expected bytes, not %s" % s.__class__.__name__) - translation = buffer(range(256)) + translation = bytearray(range(256)) for k, v in altchars.items(): translation[ord(k)] = v[0] return s.translate(translation) @@ -52,12 +52,12 @@ def b64encode(s, altchars=None): The encoded byte string is returned. """ - if not isinstance(s, bytes_buffer): + if not isinstance(s, bytes_types): s = bytes(s, "ascii") # Strip off the trailing newline encoded = binascii.b2a_base64(s)[:-1] if altchars is not None: - if not isinstance(altchars, bytes_buffer): + if not isinstance(altchars, bytes_types): altchars = bytes(altchars, "ascii") assert len(altchars) == 2, repr(altchars) return _translate(encoded, {'+': altchars[0:1], '/': altchars[1:2]}) @@ -75,10 +75,10 @@ def b64decode(s, altchars=None): s were incorrectly padded or if there are non-alphabet characters present in the string. """ - if not isinstance(s, bytes_buffer): + if not isinstance(s, bytes_types): s = bytes(s) if altchars is not None: - if not isinstance(altchars, bytes_buffer): + if not isinstance(altchars, bytes_types): altchars = bytes(altchars, "ascii") assert len(altchars) == 2, repr(altchars) s = _translate(s, {chr(altchars[0]): b'+', chr(altchars[1]): b'/'}) @@ -147,7 +147,7 @@ def b32encode(s): s is the byte string to encode. The encoded byte string is returned. """ - if not isinstance(s, bytes_buffer): + if not isinstance(s, bytes_types): s = bytes(s) quanta, leftover = divmod(len(s), 5) # Pad the last quantum with zero bits if necessary @@ -204,7 +204,7 @@ def b32decode(s, casefold=False, map01=None): the input is incorrectly padded or if there are non-alphabet characters present in the input. """ - if not isinstance(s, bytes_buffer): + if not isinstance(s, bytes_types): s = bytes(s) quanta, leftover = divmod(len(s), 8) if leftover: @@ -213,7 +213,7 @@ def b32decode(s, casefold=False, map01=None): # False, or the character to map the digit 1 (one) to. It should be # either L (el) or I (eye). if map01: - if not isinstance(map01, bytes_buffer): + if not isinstance(map01, bytes_types): map01 = bytes(map01) assert len(map01) == 1, repr(map01) s = _translate(s, {b'0': b'O', b'1': map01}) @@ -283,7 +283,7 @@ def b16decode(s, casefold=False): s were incorrectly padded or if there are non-alphabet characters present in the string. """ - if not isinstance(s, bytes_buffer): + if not isinstance(s, bytes_types): s = bytes(s) if casefold: s = s.upper() @@ -330,7 +330,7 @@ def encodestring(s): Argument and return value are bytes. """ - if not isinstance(s, bytes_buffer): + if not isinstance(s, bytes_types): raise TypeError("expected bytes, not %s" % s.__class__.__name__) pieces = [] for i in range(0, len(s), MAXBINSIZE): @@ -344,7 +344,7 @@ def decodestring(s): Argument and return value are bytes. """ - if not isinstance(s, bytes_buffer): + if not isinstance(s, bytes_types): raise TypeError("expected bytes, not %s" % s.__class__.__name__) return binascii.a2b_base64(s) |