From f5ff05be1ed04bcc50e33af28fb54382466a32e8 Mon Sep 17 00:00:00 2001 From: Val Tenyotkin Date: Tue, 21 Oct 2014 18:03:11 -0700 Subject: [PATCH] Adding a custom line delimiter to iter_lines() --- requests/models.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/requests/models.py b/requests/models.py index 17e5598..6689ef7 100644 --- a/requests/models.py +++ b/requests/models.py @@ -682,7 +682,7 @@ class Response(object): return chunks - def iter_lines(self, chunk_size=ITER_CHUNK_SIZE, decode_unicode=None): + def iter_lines(self, chunk_size=ITER_CHUNK_SIZE, decode_unicode=None, newline=None): """Iterates over the response data, one line at a time. When stream=True is set on the request, this avoids reading the content at once into memory for large responses. @@ -694,7 +694,11 @@ class Response(object): if pending is not None: chunk = pending + chunk - lines = chunk.splitlines() + + if newline: + lines = chunk.split(newline) + else: + lines = chunk.splitlines() if lines and lines[-1] and chunk and lines[-1][-1] == chunk[-1]: pending = lines.pop() -- 2.34.1