Skip to content

Commit 64e983f

Browse files
Ethankxepal
authored andcommitted
Properly parse sync_gateway query response
This closes #11
1 parent 94efad6 commit 64e983f

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

aiocouchdb/feeds.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,18 @@ def next(self):
140140
if chunk is None:
141141
return chunk
142142
chunk = chunk.decode(self._encoding).strip('\r\n,')
143-
if chunk.startswith('{"total_rows"'):
144-
chunk += ']}'
143+
if "total_rows" in chunk:
144+
# couchdb 1.x (and 2.x?)
145+
if chunk.startswith('{'):
146+
chunk += ']}'
147+
# couchbase sync gateway 1.x
148+
elif chunk.endswith('}'):
149+
chunk = '{' + chunk
145150
event = json.loads(chunk)
146151
self._total_rows = event['total_rows']
147152
self._offset = event.get('offset')
148153
return (yield from self.next())
149-
elif chunk.startswith(('{"rows"', ']}')):
154+
elif chunk.startswith(('{"rows"', ']')):
150155
return (yield from self.next())
151156
elif not chunk:
152157
return (yield from self.next())

0 commit comments

Comments
 (0)