Skip to content

Commit 2675e03

Browse files
committed
PY3 fix ChunkedTransferMiddleware
1 parent a38a99e commit 2675e03

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

scrapy/downloadermiddlewares/chunked.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class ChunkedTransferMiddleware(object):
77
"""
88

99
def process_response(self, request, response, spider):
10-
if response.headers.get('Transfer-Encoding') == 'chunked':
10+
if response.headers.get(b'Transfer-Encoding') == b'chunked':
1111
body = decode_chunked_transfer(response.body)
1212
return response.replace(body=body)
1313
return response

scrapy/utils/http.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ def decode_chunked_transfer(chunked_body):
1414
http://en.wikipedia.org/wiki/Chunked_transfer_encoding
1515
1616
"""
17-
body, h, t = '', '', chunked_body
17+
body, h, t = b'', b'', chunked_body
1818
while t:
19-
h, t = t.split('\r\n', 1)
20-
if h == '0':
19+
h, t = t.split(b'\r\n', 1)
20+
if h == b'0':
2121
break
2222
size = int(h, 16)
2323
body += t[:size]

tests/test_utils_http.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ class ChunkedTest(unittest.TestCase):
66

77
def test_decode_chunked_transfer(self):
88
"""Example taken from: http://en.wikipedia.org/wiki/Chunked_transfer_encoding"""
9-
chunked_body = "25\r\n" + "This is the data in the first chunk\r\n\r\n"
10-
chunked_body += "1C\r\n" + "and this is the second one\r\n\r\n"
11-
chunked_body += "3\r\n" + "con\r\n"
12-
chunked_body += "8\r\n" + "sequence\r\n"
13-
chunked_body += "0\r\n\r\n"
9+
chunked_body = b"25\r\n" + b"This is the data in the first chunk\r\n\r\n"
10+
chunked_body += b"1C\r\n" + b"and this is the second one\r\n\r\n"
11+
chunked_body += b"3\r\n" + b"con\r\n"
12+
chunked_body += b"8\r\n" + b"sequence\r\n"
13+
chunked_body += b"0\r\n\r\n"
1414
body = decode_chunked_transfer(chunked_body)
15-
self.assertEqual(body, \
16-
"This is the data in the first chunk\r\n" +
17-
"and this is the second one\r\n" +
18-
"consequence")
15+
self.assertEqual(body,
16+
b"This is the data in the first chunk\r\n"
17+
b"and this is the second one\r\n"
18+
b"consequence")
1919

2020

0 commit comments

Comments
 (0)