Skip to content
Myr

adding in slice_length fix and test for chunk_size=None (#3370)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Nate Prewitt · committed by Ian Cordasco · parent bd9e8f2 · Browse files · 2 files+10 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+10 added−2 removed

  • tests:+8 added−2 removed
  • other:+2 added−0 removed

2 files+10 added−2 removed

modified:requests/utils.py+2 added
382 unmodified lines
383384def iter_slices(string, slice_length):385 """Iterate over slices of a string."""386 pos = 0387 if slice_length is None or slice_length <= 0: 388 slice_length = len(string)389 while pos < len(string):390 yield string[pos:pos + slice_length]391 pos += slice_length392
376 unmodified lines
modified:tests/test_utils.py+8 added-2 removed
376 unmodified lines
377 'value, length', (378 ('', 0),379 ('T', 1),380 ('Test', 4),381 ('Cont', 0),382 ('Other', -5),383 ('Content', None),384 ))385def test_iter_slices(value, length):386 if length is None or (length <= 0 and len(value) > 0):387 # Reads all content at once388 assert len(list(iter_slices(value, length))) == 1389 else:383 assert len(list(iter_slices(value, 1))) == length390 assert len(list(iter_slices(value, 1))) == length391385392@pytest.mark.parametrize(393 'value, expected', (394 (395 '<http:/.../front.jpeg>; rel=front; type="image/jpeg"',
72 unmodified lines