Skip to content

Commit 8019cd2

Browse files
committed
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.
1 parent d4accf7 commit 8019cd2

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

couchdb/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,7 @@ def update_doc(self, name, docid=None, **options):
881881

882882
def _changes(self, **opts):
883883
_, _, data = self.resource.get('_changes', **opts)
884-
lines = iter(data)
884+
lines = data.iterchunks()
885885
for ln in lines:
886886
if not ln: # skip heartbeats
887887
continue

couchdb/http.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ def close(self):
187187
self.callback()
188188
self.callback = None
189189

190-
def __iter__(self):
190+
def iterchunks(self):
191191
assert self.resp.msg.get('transfer-encoding') == 'chunked'
192192
while True:
193193
if self.resp.isclosed():

couchdb/tests/http.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ def isclosed(self):
6363
data = '\n'.join([hex(len(data))[2:], data])
6464
response = http.ResponseBody(TestHttpResp(StringIO(data)),
6565
lambda *a, **k: None)
66-
self.assertEqual(list(response), ['foobarbaz'])
67-
self.assertEqual(list(response), [])
66+
self.assertEqual(list(response.iterchunks()), ['foobarbaz'])
67+
self.assertEqual(list(response.iterchunks()), [])
6868

6969

7070
class CacheTestCase(testutil.TempDatabaseMixin, unittest.TestCase):

0 commit comments

Comments
 (0)