Adding a custom line delimiter to iter_lines()
authorVal Tenyotkin <val@tenyotk.in>
Wed, 22 Oct 2014 01:03:11 +0000 (18:03 -0700)
committerVal Tenyotkin <val@tenyotk.in>
Wed, 22 Oct 2014 01:03:11 +0000 (18:03 -0700)
requests/models.py

index 17e5598848d65f0907502e01828d2f9d46839932..6689ef7f161c80531c7c8dd89968b1a908a693fc 100644 (file)
@@ -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()