Make the new XEP-30 plugin retain older API signatures.

This commit is contained in:
Lance Stout 2010-12-28 15:37:02 -05:00
parent b3353183f3
commit 8749f5e09b
2 changed files with 33 additions and 19 deletions

View file

@ -90,6 +90,10 @@ class xep_0030(base_plugin):
self.description = 'Service Discovery' self.description = 'Service Discovery'
self.stanza = sleekxmpp.plugins.xep_0030.stanza self.stanza = sleekxmpp.plugins.xep_0030.stanza
# Retain some backwards compatibility
self.getInfo = self.get_info
self.getItems = self.get_items
self.xmpp.register_handler( self.xmpp.register_handler(
Callback('Disco Info', Callback('Disco Info',
StanzaPath('iq/disco_info'), StanzaPath('iq/disco_info'),
@ -248,7 +252,8 @@ class xep_0030(base_plugin):
return self._fix_default_info(info) return self._fix_default_info(info)
iq = self.xmpp.Iq() iq = self.xmpp.Iq()
iq['from'] = kwargs.get('ifrom', '') # Check dfrom parameter for backwards compatibility
iq['from'] = kwargs.get('ifrom', kwargs.get('dfrom', ''))
iq['to'] = jid iq['to'] = jid
iq['type'] = 'get' iq['type'] = 'get'
iq['disco_info']['node'] = node if node else '' iq['disco_info']['node'] = node if node else ''
@ -285,7 +290,8 @@ class xep_0030(base_plugin):
return self._run_node_handler('get_items', jid, node, kwargs) return self._run_node_handler('get_items', jid, node, kwargs)
iq = self.xmpp.Iq() iq = self.xmpp.Iq()
iq['from'] = kwargs.get('ifrom', '') # Check dfrom parameter for backwards compatibility
iq['from'] = kwargs.get('ifrom', kwargs.get('dfrom', ''))
iq['to'] = jid iq['to'] = jid
iq['type'] = 'get' iq['type'] = 'get'
iq['disco_items']['node'] = node if node else '' iq['disco_items']['node'] = node if node else ''
@ -317,7 +323,7 @@ class xep_0030(base_plugin):
""" """
self._run_node_handler('del_items', jid, node, kwargs) self._run_node_handler('del_items', jid, node, kwargs)
def add_item(self, jid=None, node=None, **kwargs): def add_item(self, jid=None, name='', node=None, subnode='', ijid=None):
""" """
Add a new item element to the given JID/node combination. Add a new item element to the given JID/node combination.
@ -325,12 +331,15 @@ class xep_0030(base_plugin):
a node value to reference non-addressable entities. a node value to reference non-addressable entities.
Arguments: Arguments:
jid -- The JID to modify. jid -- The JID for the item.
node -- The node to modify.
ijid -- The JID for the item.
inode -- Optional node for the item.
name -- Optional name for the item. name -- Optional name for the item.
node -- The node to modify.
subnode -- Optional node for the item.
ijid -- The JID to modify.
""" """
kwargs = {'ijid': jid,
'name': name,
'inode': subnode}
self._run_node_handler('add_item', jid, node, kwargs) self._run_node_handler('add_item', jid, node, kwargs)
def del_item(self, jid=None, node=None, **kwargs): def del_item(self, jid=None, node=None, **kwargs):
@ -345,7 +354,7 @@ class xep_0030(base_plugin):
""" """
self._run_node_handler('del_item', jid, node, kwargs) self._run_node_handler('del_item', jid, node, kwargs)
def add_identity(self, jid=None, node=None, **kwargs): def add_identity(self, category='', itype='', name='', node=None, jid=None, lang=None):
""" """
Add a new identity to the given JID/node combination. Add a new identity to the given JID/node combination.
@ -358,24 +367,29 @@ class xep_0030(base_plugin):
names are different. A category and type is always required. names are different. A category and type is always required.
Arguments: Arguments:
jid -- The JID to modify.
node -- The node to modify.
category -- The identity's category. category -- The identity's category.
itype -- The identity's type. itype -- The identity's type.
name -- Optional name for the identity. name -- Optional name for the identity.
lang -- Optional two-letter language code. lang -- Optional two-letter language code.
node -- The node to modify.
jid -- The JID to modify.
""" """
kwargs = {'category': category,
'itype': itype,
'name': name,
'lang': lang}
self._run_node_handler('add_identity', jid, node, kwargs) self._run_node_handler('add_identity', jid, node, kwargs)
def add_feature(self, jid=None, node=None, **kwargs): def add_feature(self, feature, node=None, jid=None):
""" """
Add a feature to a JID/node combination. Add a feature to a JID/node combination.
Arguments: Arguments:
jid -- The JID to modify.
node -- The node to modify.
feature -- The namespace of the supported feature. feature -- The namespace of the supported feature.
node -- The node to modify.
jid -- The JID to modify.
""" """
kwargs = {'feature': feature}
self._run_node_handler('add_feature', jid, node, kwargs) self._run_node_handler('add_feature', jid, node, kwargs)
def del_identity(self, jid=None, node=None, **kwargs): def del_identity(self, jid=None, node=None, **kwargs):

View file

@ -406,10 +406,10 @@ class TestStreamDisco(SleekTest):
self.xmpp['xep_0030'].make_static(jid='tester@localhost', self.xmpp['xep_0030'].make_static(jid='tester@localhost',
node='testing') node='testing')
self.xmpp['xep_0030'].add_item(jid='tester@localhost', self.xmpp['xep_0030'].add_item(ijid='tester@localhost',
node='testing', node='testing',
ijid='tester@localhost', jid='tester@localhost',
inode='foo', subnode='foo',
name='Test') name='Test')
self.recv(""" self.recv("""
@ -446,10 +446,10 @@ class TestStreamDisco(SleekTest):
self.xmpp['xep_0030'].make_static(jid='user@tester.localhost', self.xmpp['xep_0030'].make_static(jid='user@tester.localhost',
node='testing') node='testing')
self.xmpp['xep_0030'].add_item(jid='user@tester.localhost', self.xmpp['xep_0030'].add_item(ijid='user@tester.localhost',
node='testing', node='testing',
ijid='user@tester.localhost', jid='user@tester.localhost',
inode='foo', subnode='foo',
name='Test') name='Test')
self.recv(""" self.recv("""