Add ability to get global/node default subscription options.

This commit is contained in:
Lance Stout 2011-09-01 13:25:35 -07:00
parent 8471a485d1
commit d7fc2aaa9c
3 changed files with 49 additions and 16 deletions

View file

@ -183,11 +183,14 @@ class xep_0060(base_plugin):
iq['pubsub']['affiliations']['node'] = node iq['pubsub']['affiliations']['node'] = node
return iq.send(block=block, callback=callback, timeout=timeout) return iq.send(block=block, callback=callback, timeout=timeout)
def get_subscription_options(self, jid, node, user_jid, ifrom=None, def get_subscription_options(self, jid, node=None, user_jid=None, ifrom=None,
block=True, callback=None, timeout=None): block=True, callback=None, timeout=None):
iq = self.xmpp.Iq(sto=jid, sfrom=ifrom, stype='get') iq = self.xmpp.Iq(sto=jid, sfrom=ifrom, stype='get')
iq['pubsub']['options']['node'] = node if user_jid is None:
iq['pubsub']['options']['jid'] = user_jid iq['pubsub']['default']['node'] = node
else:
iq['pubsub']['options']['node'] = node
iq['pubsub']['options']['jid'] = user_jid
return iq.send(block=block, callback=callback, timeout=timeout) return iq.send(block=block, callback=callback, timeout=timeout)
def set_subscription_options(self, jid, node, user_jid, options, def set_subscription_options(self, jid, node, user_jid, options,

View file

@ -85,6 +85,7 @@ class Item(ElementBase):
for child in self.xml.getchildren(): for child in self.xml.getchildren():
self.xml.remove(child) self.xml.remove(child)
class Items(ElementBase): class Items(ElementBase):
namespace = 'http://jabber.org/protocol/pubsub' namespace = 'http://jabber.org/protocol/pubsub'
name = 'items' name = 'items'
@ -102,18 +103,18 @@ class Create(ElementBase):
interfaces = set(('node',)) interfaces = set(('node',))
#class Default(ElementBase): class Default(ElementBase):
# namespace = 'http://jabber.org/protocol/pubsub' namespace = 'http://jabber.org/protocol/pubsub'
# name = 'default' name = 'default'
# plugin_attrib = name plugin_attrib = name
# interfaces = set(('node', 'type')) interfaces = set(('node', 'type'))
#
# def getType(self): def get_type(self):
# t = self._get_attr('type') t = self._get_attr('type')
# if not t: t == 'leaf' if not t:
# return t return 'leaf'
# return t
#register_stanza_plugin(Pubsub, Default)
class Publish(ElementBase): class Publish(ElementBase):
namespace = 'http://jabber.org/protocol/pubsub' namespace = 'http://jabber.org/protocol/pubsub'
@ -163,7 +164,8 @@ class Configure(ElementBase):
def getType(self): def getType(self):
t = self._get_attr('type') t = self._get_attr('type')
if not t: t == 'leaf' if not t:
t == 'leaf'
return t return t
@ -254,6 +256,7 @@ register_stanza_plugin(Iq, Pubsub)
register_stanza_plugin(Pubsub, Affiliations) register_stanza_plugin(Pubsub, Affiliations)
register_stanza_plugin(Pubsub, Configure) register_stanza_plugin(Pubsub, Configure)
register_stanza_plugin(Pubsub, Create) register_stanza_plugin(Pubsub, Create)
register_stanza_plugin(Pubsub, Default)
register_stanza_plugin(Pubsub, Items) register_stanza_plugin(Pubsub, Items)
register_stanza_plugin(Pubsub, Options) register_stanza_plugin(Pubsub, Options)
register_stanza_plugin(Pubsub, Publish) register_stanza_plugin(Pubsub, Publish)

View file

@ -574,6 +574,33 @@ class TestStreamPubsub(SleekTest):
</iq> </iq>
""") """)
def testGetSubscriptionGlobalDefaultOptions(self):
"""Test getting the subscription options for a node/JID."""
self.xmpp['xep_0060'].get_subscription_options(
'pubsub.example.com',
block=False)
self.send("""
<iq type="get" id="1" to="pubsub.example.com">
<pubsub xmlns="http://jabber.org/protocol/pubsub">
<default />
</pubsub>
</iq>
""", use_values=False)
def testGetSubscriptionNodeDefaultOptions(self):
"""Test getting the subscription options for a node/JID."""
self.xmpp['xep_0060'].get_subscription_options(
'pubsub.example.com',
node='somenode',
block=False)
self.send("""
<iq type="get" id="1" to="pubsub.example.com">
<pubsub xmlns="http://jabber.org/protocol/pubsub">
<default node="somenode" />
</pubsub>
</iq>
""", use_values=False)
def testGetSubscriptionOptions(self): def testGetSubscriptionOptions(self):
"""Test getting the subscription options for a node/JID.""" """Test getting the subscription options for a node/JID."""
self.xmpp['xep_0060'].get_subscription_options( self.xmpp['xep_0060'].get_subscription_options(