mirror of
https://github.com/correl/SleekXMPP.git
synced 2024-11-30 11:09:56 +00:00
Add support for XEP-0059 to XEP-0030 plugin.
This commit is contained in:
parent
a8e3657487
commit
7c7fa0f008
2 changed files with 62 additions and 3 deletions
|
@ -120,6 +120,11 @@ class xep_0030(base_plugin):
|
|||
'jid': {},
|
||||
'node': {}}
|
||||
|
||||
def post_init(self):
|
||||
"""Handle cross-plugin dependencies."""
|
||||
if self.xmpp['xep_0059']:
|
||||
register_stanza_plugin(DiscoItems, self.xmpp['xep_0059'].stanza.Set)
|
||||
|
||||
def set_node_handler(self, htype, jid=None, node=None, handler=None):
|
||||
"""
|
||||
Add a node handler for the given hierarchy level and
|
||||
|
@ -292,6 +297,9 @@ class xep_0030(base_plugin):
|
|||
callback -- Optional callback to execute when a reply is
|
||||
received instead of blocking and waiting for
|
||||
the reply.
|
||||
iterator -- If True, return a result set iterator using
|
||||
the XEP-0059 plugin, if the plugin is loaded.
|
||||
Otherwise the parameter is ignored.
|
||||
"""
|
||||
if local or jid is None:
|
||||
return self._run_node_handler('get_items', jid, node, kwargs)
|
||||
|
@ -302,6 +310,9 @@ class xep_0030(base_plugin):
|
|||
iq['to'] = jid
|
||||
iq['type'] = 'get'
|
||||
iq['disco_items']['node'] = node if node else ''
|
||||
if kwargs.get('iterator', False) and self.xmpp['xep_0059']:
|
||||
return self.xmpp['xep_0059'].iterate(iq, 'disco_items')
|
||||
else:
|
||||
return iq.send(timeout=kwargs.get('timeout', None),
|
||||
block=kwargs.get('block', None),
|
||||
callback=kwargs.get('callback', None))
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import sys
|
||||
import time
|
||||
import threading
|
||||
|
||||
|
@ -11,6 +12,7 @@ class TestStreamDisco(SleekTest):
|
|||
"""
|
||||
|
||||
def tearDown(self):
|
||||
sys.excepthook = sys.__excepthook__
|
||||
self.stream_close()
|
||||
|
||||
def testInfoEmptyDefaultNode(self):
|
||||
|
@ -524,5 +526,51 @@ class TestStreamDisco(SleekTest):
|
|||
self.assertEqual(results, items,
|
||||
"Unexpected items: %s" % results)
|
||||
|
||||
def testGetItemsIterator(self):
|
||||
"""Test interaction between XEP-0030 and XEP-0059 plugins."""
|
||||
|
||||
raised_exceptions = []
|
||||
|
||||
def catch_exception(*args, **kwargs):
|
||||
raised_exceptions.append(True)
|
||||
|
||||
sys.excepthook = catch_exception
|
||||
|
||||
self.stream_start(mode='client',
|
||||
plugins=['xep_0030', 'xep_0059'])
|
||||
|
||||
results = self.xmpp['xep_0030'].get_items(jid='foo@localhost',
|
||||
node='bar',
|
||||
iterator=True)
|
||||
results.amount = 10
|
||||
|
||||
t = threading.Thread(name="get_items_iterator",
|
||||
target=results.next)
|
||||
t.start()
|
||||
|
||||
self.send("""
|
||||
<iq id="2" type="get" to="foo@localhost">
|
||||
<query xmlns="http://jabber.org/protocol/disco#items"
|
||||
node="bar">
|
||||
<set xmlns="http://jabber.org/protocol/rsm">
|
||||
<max>10</max>
|
||||
</set>
|
||||
</query>
|
||||
</iq>
|
||||
""")
|
||||
self.recv("""
|
||||
<iq id="2" type="result" to="tester@localhost">
|
||||
<query xmlns="http://jabber.org/protocol/disco#items">
|
||||
<set xmlns="http://jabber.org/protocol/rsm">
|
||||
</set>
|
||||
</query>
|
||||
</iq>
|
||||
""")
|
||||
|
||||
t.join()
|
||||
|
||||
self.assertEqual(raised_exceptions, [True],
|
||||
"StopIteration was not raised: %s" % raised_exceptions)
|
||||
|
||||
|
||||
suite = unittest.TestLoader().loadTestsFromTestCase(TestStreamDisco)
|
||||
|
|
Loading…
Reference in a new issue