Skip to content
Snippets Groups Projects
Unverified Commit 5b223318 authored by Dan Michael O. Heggø's avatar Dan Michael O. Heggø
Browse files

Handle empty intermediate responses (#194)

parent b813debd
No related branches found
No related tags found
No related merge requests found
...@@ -46,13 +46,19 @@ class List(object): ...@@ -46,13 +46,19 @@ class List(object):
if self.max_items is not None: if self.max_items is not None:
if self.count >= self.max_items: if self.count >= self.max_items:
raise StopIteration raise StopIteration
try:
item = six.next(self._iter) # For filered lists, we might have to do several requests
except StopIteration: # to get the next element due to miser mode.
if self.last: # See: https://github.com/mwclient/mwclient/issues/194
raise while True:
self.load_chunk() try:
item = six.next(self._iter) item = six.next(self._iter)
if item is not None:
break
except StopIteration:
if self.last:
raise
self.load_chunk()
self.count += 1 self.count += 1
if 'timestamp' in item: if 'timestamp' in item:
...@@ -93,7 +99,11 @@ class List(object): ...@@ -93,7 +99,11 @@ class List(object):
if not data: if not data:
# Non existent page # Non existent page
raise StopIteration raise StopIteration
self.set_iter(data)
# Process response if not empty.
# See: https://github.com/mwclient/mwclient/issues/194
if 'query' in data:
self.set_iter(data)
if data.get('continue'): if data.get('continue'):
# New style continuation, added in MediaWiki 1.21 # New style continuation, added in MediaWiki 1.21
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment