Fix detecting end of result set paging.

This commit is contained in:
Lance Stout
2012-01-18 19:57:49 -08:00
parent bb3080e829
commit b25668b5b7
2 changed files with 51 additions and 25 deletions
+22 -10
View File
@@ -13,6 +13,7 @@ from sleekxmpp import Iq
from sleekxmpp.plugins.base import base_plugin
from sleekxmpp.xmlstream import register_stanza_plugin
from sleekxmpp.plugins.xep_0059 import Set
from sleekxmpp.exceptions import XMPPError
log = logging.getLogger(__name__)
@@ -70,19 +71,30 @@ class ResultIterator():
elif self.start:
self.query[self.interface]['rsm']['after'] = self.start
r = self.query.send(block=True)
try:
r = self.query.send(block=True)
if not r or not r[self.interface]['rsm']['first'] and \
not r[self.interface]['rsm']['last']:
if not r[self.interface]['rsm']['first'] and \
not r[self.interface]['rsm']['last']:
raise StopIteration
if r[self.interface]['rsm']['count'] and \
r[self.interface]['rsm']['first_index']:
count = int(r[self.interface]['rsm']['count'])
first = int(r[self.interface]['rsm']['first_index'])
num_items = len(r[self.interface]['substanzas'])
if first + num_items == count:
raise StopIteration
if self.reverse:
self.start = r[self.interface]['rsm']['first']
else:
self.start = r[self.interface]['rsm']['last']
return r
except XMPPError:
raise StopIteration
if self.reverse:
self.start = r[self.interface]['rsm']['first']
else:
self.start = r[self.interface]['rsm']['last']
return r
class xep_0059(base_plugin):