Commit 40adbd9d authored by Joshua Roesslein's avatar Joshua Roesslein
Browse files

Fix a few bugs with the new ID cursors.

 - stop once end of collection reached (empty result).
 - don't raise ValueError if ResultSet is empty when
   trying to get max/min ID of the set (max() and min() don't
   accept empty lists)
parent edfde16c
......@@ -91,6 +91,8 @@ class IdIterator(BaseIterator):
# to avoid requesting duplicate items.
max_id = self.since_id - 1 if self.max_id else None
data = self.method(max_id = max_id, *self.args, **self.kargs)
if len(data) == 0:
raise StopIteration
self.max_id = data.max_id
self.since_id = data.since_id
return data
......@@ -99,6 +101,8 @@ class IdIterator(BaseIterator):
"""Fetch a set of items with IDs greater than current set."""
since_id = self.max_id
data = self.method(since_id = since_id, *self.args, **self.kargs)
if len(data) == 0:
raise StopIteration
self.max_id = data.max_id
self.since_id = data.since_id
return data
......
......@@ -16,11 +16,17 @@ class ResultSet(list):
@property
def max_id(self):
return self._max_id or max(self.ids())
if self._max_id:
return self._max_id
ids = self.ids()
return max(ids) if ids else None
@property
def since_id(self):
return self._since_id or min(self.ids())
if self._since_id:
return self._since_id
ids = self.ids()
return min(ids) if ids else None
def ids(self):
return [item.id for item in self if hasattr(item, 'id')]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment