make Response.iter_lines yield the pending buffer if its actually a complete line
authorRonny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
Tue, 17 Jan 2012 11:47:22 +0000 (12:47 +0100)
committerRonny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
Tue, 17 Jan 2012 11:47:22 +0000 (12:47 +0100)
requests/models.py

index c45b18a7b306f6d716ae20f29b38606750fd7b9d..c3f1b432fb38ec77524b89837eabc7b6b5d2ff35 100644 (file)
@@ -633,7 +633,7 @@ class Response(object):
         avoids reading the content at once into memory for large
         responses.
         """
-
+        #XXX: why rstrip by default
         pending = None
         for chunk in self.iter_content(chunk_size, decode_unicode=decode_unicode):
             if pending is not None:
@@ -643,6 +643,10 @@ class Response(object):
                 yield line.rstrip()
             # Save the last part of the chunk for next iteration, to keep full line together
             pending = lines[-1]
+            #if pending is a complete line, give it baack
+            if pending[-1] == '\n':
+                yield pending.rstrip()
+                pending = None
 
         # Yield the last line
         if pending is not None: