mirror of
https://github.com/kennethreitz/requests.git
synced 2026-06-05 14:50:16 +00:00
adding in slice_length fix and test for chunk_size=None (#3370)
This commit is contained in:
committed by
Ian Cordasco
parent
bd9e8f2271
commit
71050e9ab9
@@ -384,6 +384,8 @@ def stream_decode_response_unicode(iterator, r):
|
||||
def iter_slices(string, slice_length):
|
||||
"""Iterate over slices of a string."""
|
||||
pos = 0
|
||||
if slice_length is None or slice_length <= 0:
|
||||
slice_length = len(string)
|
||||
while pos < len(string):
|
||||
yield string[pos:pos + slice_length]
|
||||
pos += slice_length
|
||||
|
||||
+8
-2
@@ -378,10 +378,16 @@ def test_get_encoding_from_headers(value, expected):
|
||||
('', 0),
|
||||
('T', 1),
|
||||
('Test', 4),
|
||||
('Cont', 0),
|
||||
('Other', -5),
|
||||
('Content', None),
|
||||
))
|
||||
def test_iter_slices(value, length):
|
||||
assert len(list(iter_slices(value, 1))) == length
|
||||
|
||||
if length is None or (length <= 0 and len(value) > 0):
|
||||
# Reads all content at once
|
||||
assert len(list(iter_slices(value, length))) == 1
|
||||
else:
|
||||
assert len(list(iter_slices(value, 1))) == length
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'value, expected', (
|
||||
|
||||
Reference in New Issue
Block a user