diff options
author | Lance Stout <lancestout@gmail.com> | 2012-01-18 19:57:49 -0800 |
---|---|---|
committer | Lance Stout <lancestout@gmail.com> | 2012-01-18 19:57:49 -0800 |
commit | b25668b5b7264bafeeeaeeb0efd6e911036d2d30 (patch) | |
tree | f5909f3c4366c46f320e87f6b47cd63678f47570 /sleekxmpp/plugins/xep_0059 | |
parent | bb3080e829df126466c44cb2f89a0307e5c4146a (diff) | |
download | slixmpp-b25668b5b7264bafeeeaeeb0efd6e911036d2d30.tar.gz slixmpp-b25668b5b7264bafeeeaeeb0efd6e911036d2d30.tar.bz2 slixmpp-b25668b5b7264bafeeeaeeb0efd6e911036d2d30.tar.xz slixmpp-b25668b5b7264bafeeeaeeb0efd6e911036d2d30.zip |
Fix detecting end of result set paging.
Diffstat (limited to 'sleekxmpp/plugins/xep_0059')
-rw-r--r-- | sleekxmpp/plugins/xep_0059/rsm.py | 34 |
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): |