summaryrefslogtreecommitdiff
path: root/sleekxmpp/plugins/xep_0030/stanza
diff options
context:
space:
mode:
authorLance Stout <lancestout@gmail.com>2012-01-18 19:57:49 -0800
committerLance Stout <lancestout@gmail.com>2012-01-18 19:57:49 -0800
commitb25668b5b7264bafeeeaeeb0efd6e911036d2d30 (patch)
treef5909f3c4366c46f320e87f6b47cd63678f47570 /sleekxmpp/plugins/xep_0030/stanza
parentbb3080e829df126466c44cb2f89a0307e5c4146a (diff)
downloadslixmpp-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_0030/stanza')
-rw-r--r--sleekxmpp/plugins/xep_0030/stanza/items.py44
1 files changed, 29 insertions, 15 deletions
diff --git a/sleekxmpp/plugins/xep_0030/stanza/items.py b/sleekxmpp/plugins/xep_0030/stanza/items.py
index a1fb819c..f642a5b8 100644
--- a/sleekxmpp/plugins/xep_0030/stanza/items.py
+++ b/sleekxmpp/plugins/xep_0030/stanza/items.py
@@ -6,7 +6,7 @@
See the file LICENSE for copying permission.
"""
-from sleekxmpp.xmlstream import ElementBase, ET
+from sleekxmpp.xmlstream import ElementBase, ET, register_stanza_plugin
class DiscoItems(ElementBase):
@@ -78,13 +78,11 @@ class DiscoItems(ElementBase):
"""
if (jid, node) not in self._items:
self._items.add((jid, node))
- item_xml = ET.Element('{%s}item' % self.namespace)
- item_xml.attrib['jid'] = jid
- if name:
- item_xml.attrib['name'] = name
- if node:
- item_xml.attrib['node'] = node
- self.xml.append(item_xml)
+ item = DiscoItem(parent=self)
+ item['jid'] = jid
+ item['node'] = node
+ item['name'] = name
+ self.iterables.append(item)
return True
return False
@@ -108,11 +106,9 @@ class DiscoItems(ElementBase):
def get_items(self):
"""Return all items."""
items = set()
- for item_xml in self.findall('{%s}item' % self.namespace):
- item = (item_xml.attrib['jid'],
- item_xml.attrib.get('node'),
- item_xml.attrib.get('name'))
- items.add(item)
+ for item in self['substanzas']:
+ if isinstance(item, DiscoItem):
+ items.add((item['jid'], item['node'], item['name']))
return items
def set_items(self, items):
@@ -132,5 +128,23 @@ class DiscoItems(ElementBase):
def del_items(self):
"""Remove all items."""
self._items = set()
- for item_xml in self.findall('{%s}item' % self.namespace):
- self.xml.remove(item_xml)
+ for item in self['substanzas']:
+ if isinstance(item, DiscoItem):
+ self.xml.remove(item.xml)
+
+
+class DiscoItem(ElementBase):
+ name = 'item'
+ namespace = 'http://jabber.org/protocol/disco#items'
+ plugin_attrib = name
+ interfaces = set(('jid', 'node', 'name'))
+
+ def get_node(self):
+ return self._get_attr('node', None)
+
+ def get_name(self):
+ return self._get_attr('name', None)
+
+
+register_stanza_plugin(DiscoItems, DiscoItem, iterable=True)
+