summaryrefslogtreecommitdiff
path: root/sleekxmpp/plugins/xep_0059
diff options
context:
space:
mode:
Diffstat (limited to 'sleekxmpp/plugins/xep_0059')
-rw-r--r--sleekxmpp/plugins/xep_0059/rsm.py34
1 files changed, 23 insertions, 11 deletions
diff --git a/sleekxmpp/plugins/xep_0059/rsm.py b/sleekxmpp/plugins/xep_0059/rsm.py
index 35908473..0e62bdde 100644
--- a/sleekxmpp/plugins/xep_0059/rsm.py
+++ b/sleekxmpp/plugins/xep_0059/rsm.py
@@ -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)
-
- if not r or not r[self.interface]['rsm']['first'] and \
- not r[self.interface]['rsm']['last']:
+ try:
+ r = self.query.send(block=True)
+
+ 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):