From: Val Tenyotkin Date: Wed, 22 Oct 2014 01:03:11 +0000 (-0700) Subject: Adding a custom line delimiter to iter_lines() X-Git-Tag: v2.5.0~16^2~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f5ff05be1ed04bcc50e33af28fb54382466a32e8;p=services%2Fpython-requests.git Adding a custom line delimiter to iter_lines() --- 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()