[couchdb-python] push by djc.ochtman - Rename ResponseBody.__iter__() to iterchunks() (fixes issue 190).... on 2012-09-21 07:52 GMT

9 views
Skip to first unread message

couchdb...@googlecode.com

unread,
Sep 21, 2012, 3:53:46 AM9/21/12
to couchdb...@googlegroups.com
Revision: e260990c44ff
Branch: default
Author: Dirkjan Ochtman <dir...@ochtman.nl>
Date: Fri Sep 21 00:41:23 2012
Log: Rename ResponseBody.__iter__() to iterchunks() (fixes issue 190).

The __iter__ name is misleading because it's different from iterators over
other kinds of file-like objects. iterchunks() should make it clear this is
only intended for chunked encoding and asserts for non-chunked responses.
http://code.google.com/p/couchdb-python/source/detail?r=e260990c44ff

Modified:
/couchdb/client.py
/couchdb/http.py
/couchdb/tests/http.py

=======================================
--- /couchdb/client.py Thu Sep 20 01:01:21 2012
+++ /couchdb/client.py Fri Sep 21 00:41:23 2012
@@ -881,7 +881,7 @@

def _changes(self, **opts):
_, _, data = self.resource.get('_changes', **opts)
- lines = iter(data)
+ lines = data.iterchunks()
for ln in lines:
if not ln: # skip heartbeats
continue
=======================================
--- /couchdb/http.py Thu Sep 20 11:22:48 2012
+++ /couchdb/http.py Fri Sep 21 00:41:23 2012
@@ -187,7 +187,7 @@
self.callback()
self.callback = None

- def __iter__(self):
+ def iterchunks(self):
assert self.resp.msg.get('transfer-encoding') == 'chunked'
while True:
if self.resp.isclosed():
=======================================
--- /couchdb/tests/http.py Thu Sep 20 11:22:48 2012
+++ /couchdb/tests/http.py Fri Sep 21 00:41:23 2012
@@ -63,8 +63,8 @@
data = '\n'.join([hex(len(data))[2:], data])
response = http.ResponseBody(TestHttpResp(StringIO(data)),
lambda *a, **k: None)
- self.assertEqual(list(response), ['foobarbaz'])
- self.assertEqual(list(response), [])
+ self.assertEqual(list(response.iterchunks()), ['foobarbaz'])
+ self.assertEqual(list(response.iterchunks()), [])


class CacheTestCase(testutil.TempDatabaseMixin, unittest.TestCase):
Reply all
Reply to author
Forward
0 new messages