Skip to content

Commit

Permalink
use [-1] instead of endswith() to work with bytes or string
Browse files Browse the repository at this point in the history
Also add a parametrize on decode_unicode for iter_lines() test
to check with bytestrings and str content
  • Loading branch information
vbarbaresi committed Mar 15, 2017
1 parent 052595f commit d491e9f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion requests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,7 @@ def iter_lines(self, chunk_size=ITER_CHUNK_SIZE, decode_unicode=None, delimiter=
#
# If we're using `splitlines()`, we only do this if the chunk
# ended midway through a line.
incomplete_line = lines[-1] and lines[-1].endswith(chunk[-1])
incomplete_line = lines[-1] and lines[-1][-1] == chunk[-1]
if delimiter or incomplete_line:
pending = lines.pop()

Expand Down
7 changes: 4 additions & 3 deletions tests/test_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1816,11 +1816,12 @@ def test_json_param_post_should_not_override_data_param(self, httpbin):
prep = r.prepare()
assert 'stuff=elixr' == prep.body

def test_response_iter_lines(self, httpbin):
@pytest.mark.parametrize('decode_unicode', (True, False))
def test_response_iter_lines(self, httpbin, decode_unicode):
r = requests.get(httpbin('stream/4'), stream=True)
assert r.status_code == 200

it = r.iter_lines()
r.encoding = 'utf-8'
it = r.iter_lines(decode_unicode=decode_unicode)
next(it)
assert len(list(it)) == 3

Expand Down

0 comments on commit d491e9f

Please sign in to comment.