2727 ]
2828
2929
30- bytes_buffer = (bytes , buffer ) # Types acceptable as binary data
30+ bytes_types = (bytes , bytearray ) # Types acceptable as binary data
3131
3232
3333def _translate (s , altchars ):
34- if not isinstance (s , bytes_buffer ):
34+ if not isinstance (s , bytes_types ):
3535 raise TypeError ("expected bytes, not %s" % s .__class__ .__name__ )
36- translation = buffer (range (256 ))
36+ translation = bytearray (range (256 ))
3737 for k , v in altchars .items ():
3838 translation [ord (k )] = v [0 ]
3939 return s .translate (translation )
@@ -52,12 +52,12 @@ def b64encode(s, altchars=None):
5252
5353 The encoded byte string is returned.
5454 """
55- if not isinstance (s , bytes_buffer ):
55+ if not isinstance (s , bytes_types ):
5656 s = bytes (s , "ascii" )
5757 # Strip off the trailing newline
5858 encoded = binascii .b2a_base64 (s )[:- 1 ]
5959 if altchars is not None :
60- if not isinstance (altchars , bytes_buffer ):
60+ if not isinstance (altchars , bytes_types ):
6161 altchars = bytes (altchars , "ascii" )
6262 assert len (altchars ) == 2 , repr (altchars )
6363 return _translate (encoded , {'+' : altchars [0 :1 ], '/' : altchars [1 :2 ]})
@@ -75,10 +75,10 @@ def b64decode(s, altchars=None):
7575 s were incorrectly padded or if there are non-alphabet characters
7676 present in the string.
7777 """
78- if not isinstance (s , bytes_buffer ):
78+ if not isinstance (s , bytes_types ):
7979 s = bytes (s )
8080 if altchars is not None :
81- if not isinstance (altchars , bytes_buffer ):
81+ if not isinstance (altchars , bytes_types ):
8282 altchars = bytes (altchars , "ascii" )
8383 assert len (altchars ) == 2 , repr (altchars )
8484 s = _translate (s , {chr (altchars [0 ]): b'+' , chr (altchars [1 ]): b'/' })
@@ -147,7 +147,7 @@ def b32encode(s):
147147
148148 s is the byte string to encode. The encoded byte string is returned.
149149 """
150- if not isinstance (s , bytes_buffer ):
150+ if not isinstance (s , bytes_types ):
151151 s = bytes (s )
152152 quanta , leftover = divmod (len (s ), 5 )
153153 # Pad the last quantum with zero bits if necessary
@@ -204,7 +204,7 @@ def b32decode(s, casefold=False, map01=None):
204204 the input is incorrectly padded or if there are non-alphabet
205205 characters present in the input.
206206 """
207- if not isinstance (s , bytes_buffer ):
207+ if not isinstance (s , bytes_types ):
208208 s = bytes (s )
209209 quanta , leftover = divmod (len (s ), 8 )
210210 if leftover :
@@ -213,7 +213,7 @@ def b32decode(s, casefold=False, map01=None):
213213 # False, or the character to map the digit 1 (one) to. It should be
214214 # either L (el) or I (eye).
215215 if map01 :
216- if not isinstance (map01 , bytes_buffer ):
216+ if not isinstance (map01 , bytes_types ):
217217 map01 = bytes (map01 )
218218 assert len (map01 ) == 1 , repr (map01 )
219219 s = _translate (s , {b'0' : b'O' , b'1' : map01 })
@@ -283,7 +283,7 @@ def b16decode(s, casefold=False):
283283 s were incorrectly padded or if there are non-alphabet characters
284284 present in the string.
285285 """
286- if not isinstance (s , bytes_buffer ):
286+ if not isinstance (s , bytes_types ):
287287 s = bytes (s )
288288 if casefold :
289289 s = s .upper ()
@@ -330,7 +330,7 @@ def encodestring(s):
330330
331331 Argument and return value are bytes.
332332 """
333- if not isinstance (s , bytes_buffer ):
333+ if not isinstance (s , bytes_types ):
334334 raise TypeError ("expected bytes, not %s" % s .__class__ .__name__ )
335335 pieces = []
336336 for i in range (0 , len (s ), MAXBINSIZE ):
@@ -344,7 +344,7 @@ def decodestring(s):
344344
345345 Argument and return value are bytes.
346346 """
347- if not isinstance (s , bytes_buffer ):
347+ if not isinstance (s , bytes_types ):
348348 raise TypeError ("expected bytes, not %s" % s .__class__ .__name__ )
349349 return binascii .a2b_base64 (s )
350350
0 commit comments