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

Skip to content

Commit 74a49ac

Browse files
Issue #23681: Fixed Python 2 to 3 poring bugs.
Indexing bytes retiurns an integer, not bytes.
1 parent d83b7c2 commit 74a49ac

5 files changed

Lines changed: 12 additions & 14 deletions

File tree

Lib/poplib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def _getline(self):
136136
# so only possibilities are ...LF, ...CRLF, CR...LF
137137
if line[-2:] == CRLF:
138138
return line[:-2], octets
139-
if line[0] == CR:
139+
if line[:1] == CR:
140140
return line[1:-1], octets
141141
return line[:-1], octets
142142

Lib/quopri.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def decode(input, output, header=False):
145145
new = new + c; i = i+1
146146
elif i+1 == n and not partial:
147147
partial = 1; break
148-
elif i+1 < n and line[i+1] == ESCAPE:
148+
elif i+1 < n and line[i+1:i+2] == ESCAPE:
149149
new = new + ESCAPE; i = i+2
150150
elif i+2 < n and ishex(line[i+1:i+2]) and ishex(line[i+2:i+3]):
151151
new = new + bytes((unhex(line[i+1:i+3]),)); i = i+3

Lib/sunau.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,12 +210,9 @@ def initfp(self, file):
210210
self._framesize = self._framesize * self._nchannels
211211
if self._hdr_size > 24:
212212
self._info = file.read(self._hdr_size - 24)
213-
for i in range(len(self._info)):
214-
if self._info[i] == b'\0':
215-
self._info = self._info[:i]
216-
break
213+
self._info, _, _ = self._info.partition(b'\0')
217214
else:
218-
self._info = ''
215+
self._info = b''
219216
try:
220217
self._data_pos = file.tell()
221218
except (AttributeError, OSError):

Lib/test/test_buffer.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,15 +149,15 @@ def randrange_fmt(mode, char, obj):
149149
format character."""
150150
x = randrange(*fmtdict[mode][char])
151151
if char == 'c':
152-
x = bytes(chr(x), 'latin1')
152+
x = bytes([x])
153+
if obj == 'numpy' and x == b'\x00':
154+
# http://projects.scipy.org/numpy/ticket/1925
155+
x = b'\x01'
153156
if char == '?':
154157
x = bool(x)
155158
if char == 'f' or char == 'd':
156159
x = struct.pack(char, x)
157160
x = struct.unpack(char, x)[0]
158-
if obj == 'numpy' and x == b'\x00':
159-
# http://projects.scipy.org/numpy/ticket/1925
160-
x = b'\x01'
161161
return x
162162

163163
def gen_item(fmt, obj):

Lib/test/test_tokenize.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,7 +1066,7 @@ def test_tokenize(self):
10661066
encoding = object()
10671067
encoding_used = None
10681068
def mock_detect_encoding(readline):
1069-
return encoding, ['first', 'second']
1069+
return encoding, [b'first', b'second']
10701070

10711071
def mock__tokenize(readline, encoding):
10721072
nonlocal encoding_used
@@ -1085,15 +1085,16 @@ def mock_readline():
10851085
counter += 1
10861086
if counter == 5:
10871087
return b''
1088-
return counter
1088+
return str(counter).encode()
10891089

10901090
orig_detect_encoding = tokenize_module.detect_encoding
10911091
orig__tokenize = tokenize_module._tokenize
10921092
tokenize_module.detect_encoding = mock_detect_encoding
10931093
tokenize_module._tokenize = mock__tokenize
10941094
try:
10951095
results = tokenize(mock_readline)
1096-
self.assertEqual(list(results), ['first', 'second', 1, 2, 3, 4])
1096+
self.assertEqual(list(results),
1097+
[b'first', b'second', b'1', b'2', b'3', b'4'])
10971098
finally:
10981099
tokenize_module.detect_encoding = orig_detect_encoding
10991100
tokenize_module._tokenize = orig__tokenize

0 commit comments

Comments
 (0)