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

Skip to content

Commit 254348e

Browse files
committed
Rename buffer -> bytearray.
1 parent 905a904 commit 254348e

31 files changed

Lines changed: 290 additions & 290 deletions

Lib/base64.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@
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

3333
def _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

Lib/dumbdbm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def __setitem__(self, key, val):
163163
if not isinstance(key, bytes):
164164
raise TypeError("keys must be bytes")
165165
key = key.decode("latin-1") # hashable bytes
166-
if not isinstance(val, (buffer, bytes)):
166+
if not isinstance(val, (bytes, bytearray)):
167167
raise TypeError("values must be byte strings")
168168
if key not in self._index:
169169
self._addkey(key, self._addval(val))

Lib/encodings/idna.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def encode(self, input, errors='strict'):
153153
if not input:
154154
return b'', 0
155155

156-
result = buffer()
156+
result = bytearray()
157157
labels = dots.split(input)
158158
if labels and not labels[-1]:
159159
trailing_dot = b'.'
@@ -216,7 +216,7 @@ def _buffer_encode(self, input, errors, final):
216216
if labels:
217217
trailing_dot = b'.'
218218

219-
result = buffer()
219+
result = bytearray()
220220
size = 0
221221
for label in labels:
222222
if size:

Lib/encodings/punycode.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
def segregate(str):
1212
"""3.1 Basic code point segregation"""
13-
base = buffer()
13+
base = bytearray()
1414
extended = set()
1515
for c in str:
1616
if ord(c) < 128:
@@ -78,7 +78,7 @@ def T(j, bias):
7878
digits = b"abcdefghijklmnopqrstuvwxyz0123456789"
7979
def generate_generalized_integer(N, bias):
8080
"""3.3 Generalized variable-length integers"""
81-
result = buffer()
81+
result = bytearray()
8282
j = 0
8383
while 1:
8484
t = T(j, bias)
@@ -107,7 +107,7 @@ def adapt(delta, first, numchars):
107107
def generate_integers(baselen, deltas):
108108
"""3.4 Bias adaptation"""
109109
# Punycode parameters: initial bias = 72, damp = 700, skew = 38
110-
result = buffer()
110+
result = bytearray()
111111
bias = 72
112112
for points, delta in enumerate(deltas):
113113
s = generate_generalized_integer(delta, bias)

Lib/io.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ def nreadahead():
391391
return 1
392392
if limit is None:
393393
limit = -1
394-
res = buffer()
394+
res = bytearray()
395395
while limit < 0 or len(res) < limit:
396396
b = self.read(nreadahead())
397397
if not b:
@@ -454,14 +454,14 @@ def read(self, n: int = -1) -> bytes:
454454
n = -1
455455
if n < 0:
456456
return self.readall()
457-
b = buffer(n.__index__())
457+
b = bytearray(n.__index__())
458458
n = self.readinto(b)
459459
del b[n:]
460460
return bytes(b)
461461

462462
def readall(self):
463463
"""readall() -> bytes. Read until EOF, using multiple read() call."""
464-
res = buffer()
464+
res = bytearray()
465465
while True:
466466
data = self.read(DEFAULT_BUFFER_SIZE)
467467
if not data:
@@ -655,7 +655,7 @@ class BytesIO(BufferedIOBase):
655655
# XXX More docs
656656

657657
def __init__(self, initial_bytes=None):
658-
buf = buffer()
658+
buf = bytearray()
659659
if initial_bytes is not None:
660660
buf += initial_bytes
661661
self._buffer = buf
@@ -823,7 +823,7 @@ def __init__(self, raw,
823823
self.max_buffer_size = (2*buffer_size
824824
if max_buffer_size is None
825825
else max_buffer_size)
826-
self._write_buf = buffer()
826+
self._write_buf = bytearray()
827827

828828
def write(self, b):
829829
if self.closed:
@@ -1276,7 +1276,7 @@ def tell(self):
12761276
try:
12771277
decoder.setstate((b"", decoder_state))
12781278
n = 0
1279-
bb = buffer(1)
1279+
bb = bytearray(1)
12801280
for i, bb[0] in enumerate(readahead):
12811281
n += len(decoder.decode(bb))
12821282
if n >= needed:

Lib/pickle.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"Unpickler", "dump", "dumps", "load", "loads"]
4040

4141
# Shortcut for use in isinstance testing
42-
bytes_types = (bytes, buffer, memoryview)
42+
bytes_types = (bytes, bytearray, memoryview)
4343

4444
# These are purely informational; no code uses these.
4545
format_version = "2.0" # File format version we write

Lib/plat-mac/aepack.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def pack(x, forcetype = None):
9898
return AE.AECreateDesc(b'long', struct.pack('l', x))
9999
if isinstance(x, float):
100100
return AE.AECreateDesc(b'doub', struct.pack('d', x))
101-
if isinstance(x, (bytes, buffer)):
101+
if isinstance(x, (bytes, bytearray)):
102102
return AE.AECreateDesc(b'TEXT', x)
103103
if isinstance(x, str):
104104
# See http://developer.apple.com/documentation/Carbon/Reference/Apple_Event_Manager/Reference/reference.html#//apple_ref/doc/constant_group/typeUnicodeText

Lib/plat-mac/aetypes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def _four_char_code(four_chars):
2222
four_chars must contain only ASCII characters.
2323
2424
"""
25-
if isinstance(four_chars, (bytes, buffer)):
25+
if isinstance(four_chars, (bytes, bytearray)):
2626
b = bytes(four_chars[:4])
2727
n = len(b)
2828
if n < 4:

Lib/string.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def maketrans(frm: bytes, to: bytes) -> bytes:
5353
raise ValueError("maketrans arguments must have same length")
5454
if not (isinstance(frm, bytes) and isinstance(to, bytes)):
5555
raise TypeError("maketrans arguments must be bytes objects")
56-
L = buffer(range(256))
56+
L = bytearray(range(256))
5757
for i, c in enumerate(frm):
5858
L[c] = to[i]
5959
return bytes(L)

Lib/tarfile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ def itn(n, digits=8, format=DEFAULT_FORMAT):
222222
# this could raise OverflowError.
223223
n = struct.unpack("L", struct.pack("l", n))[0]
224224

225-
s = buffer()
225+
s = bytearray()
226226
for i in range(digits - 1):
227227
s.insert(0, n & 0o377)
228228
n >>= 8

0 commit comments

Comments
 (0)