def generate():
chunk = []
- while 1:
+ while True:
c = self.raw.read(1)
if not c:
break
else:
chunk.append(c)
+ # Yield the remainder, in case the response
+ # did not terminate with a newline
+ if chunk:
+ yield ''.join(chunk)
+
self._content_consumed = True
gen = generate()
from __future__ import with_statement
+import StringIO
import time
import os
import unittest
self.assertEqual(i, len_lines)
+ # Test 'dangling' fragment in responses that do not terminate in
+ # a newline.
+ quote = (
+ '''Why will he not upon our fair request\n'''
+ '''Untent his person and share the air with us?'''
+ )
+
+ # Make a request and monkey-patch its contents
+ r = requests.get(httpbin('get'))
+ r.raw = StringIO.StringIO(quote)
+
+ # Make sure iter_lines doesn't chop the trailing bit
+ lines = '\n'.join(r.iter_lines())
+ self.assertEqual(lines, quote)
+
+
if __name__ == '__main__':
unittest.main()