Make Response objects iterable.

This commit is contained in:
Cory Benfield
2013-01-26 15:19:01 +00:00
parent 231e343a3b
commit 2ac3913733
2 changed files with 10 additions and 0 deletions
+4
View File
@@ -486,6 +486,10 @@ class Response(object):
"""Returns true if :attr:`status_code` is 'OK'."""
return self.ok
def __iter__(self):
"""Returns the current object."""
return self.iter_content(128)
@property
def ok(self):
try:
+6
View File
@@ -325,6 +325,12 @@ class RequestsTestCase(unittest.TestCase):
r = requests.get(httpbin('get'))
self.assertTrue(r.elapsed.total_seconds() > 0.0)
def test_response_is_iterable(self):
r = requests.Response()
io = StringIO.StringIO('abc')
r.raw = io
self.assertTrue(iter(r).next())
io.close()
if __name__ == '__main__':
unittest.main()