summaryrefslogtreecommitdiff
path: root/sleekxmpp/plugins/xep_0128
diff options
context:
space:
mode:
authorLance Stout <lancestout@gmail.com>2011-03-22 20:48:09 -0400
committerLance Stout <lancestout@gmail.com>2011-03-22 20:48:09 -0400
commit756c4c032f820285455c7c57e4925887f9c8e213 (patch)
treebc964a6c96cdbf9ccf1c8c82a6e9291b4d5f738a /sleekxmpp/plugins/xep_0128
parente1360ae04946a4b6f9fe7ed19f9349ce24405dd1 (diff)
parent4b1fadde4bd87a8763131165701c08a3035005eb (diff)
downloadslixmpp-756c4c032f820285455c7c57e4925887f9c8e213.tar.gz
slixmpp-756c4c032f820285455c7c57e4925887f9c8e213.tar.bz2
slixmpp-756c4c032f820285455c7c57e4925887f9c8e213.tar.xz
slixmpp-756c4c032f820285455c7c57e4925887f9c8e213.zip
Merge branch 'develop' into roster
Diffstat (limited to 'sleekxmpp/plugins/xep_0128')
-rw-r--r--sleekxmpp/plugins/xep_0128/__init__.py10
-rw-r--r--sleekxmpp/plugins/xep_0128/extended_disco.py101
-rw-r--r--sleekxmpp/plugins/xep_0128/static.py72
3 files changed, 183 insertions, 0 deletions
diff --git a/sleekxmpp/plugins/xep_0128/__init__.py b/sleekxmpp/plugins/xep_0128/__init__.py
new file mode 100644
index 00000000..3c6379a3
--- /dev/null
+++ b/sleekxmpp/plugins/xep_0128/__init__.py
@@ -0,0 +1,10 @@
+"""
+ SleekXMPP: The Sleek XMPP Library
+ Copyright (C) 2010 Nathanael C. Fritz, Lance J.T. Stout
+ This file is part of SleekXMPP.
+
+ See the file LICENSE for copying permission.
+"""
+
+from sleekxmpp.plugins.xep_0128.static import StaticExtendedDisco
+from sleekxmpp.plugins.xep_0128.extended_disco import xep_0128
diff --git a/sleekxmpp/plugins/xep_0128/extended_disco.py b/sleekxmpp/plugins/xep_0128/extended_disco.py
new file mode 100644
index 00000000..63b3cfee
--- /dev/null
+++ b/sleekxmpp/plugins/xep_0128/extended_disco.py
@@ -0,0 +1,101 @@
+"""
+ SleekXMPP: The Sleek XMPP Library
+ Copyright (C) 2010 Nathanael C. Fritz, Lance J.T. Stout
+ This file is part of SleekXMPP.
+
+ See the file LICENSE for copying permission.
+"""
+
+import logging
+
+import sleekxmpp
+from sleekxmpp import Iq
+from sleekxmpp.xmlstream import register_stanza_plugin
+from sleekxmpp.plugins.base import base_plugin
+from sleekxmpp.plugins.xep_0004 import Form
+from sleekxmpp.plugins.xep_0030 import DiscoInfo
+from sleekxmpp.plugins.xep_0128 import StaticExtendedDisco
+
+
+class xep_0128(base_plugin):
+
+ """
+ XEP-0128: Service Discovery Extensions
+
+ Allow the use of data forms to add additional identity
+ information to disco#info results.
+
+ Also see <http://www.xmpp.org/extensions/xep-0128.html>.
+
+ Attributes:
+ disco -- A reference to the XEP-0030 plugin.
+ static -- Object containing the default set of static
+ node handlers.
+ xmpp -- The main SleekXMPP object.
+
+ Methods:
+ set_extended_info -- Set extensions to a disco#info result.
+ add_extended_info -- Add an extension to a disco#info result.
+ del_extended_info -- Remove all extensions from a disco#info result.
+ """
+
+ def plugin_init(self):
+ """Start the XEP-0128 plugin."""
+ self.xep = '0128'
+ self.description = 'Service Discovery Extensions'
+
+ self._disco_ops = ['set_extended_info',
+ 'add_extended_info',
+ 'del_extended_info']
+
+ register_stanza_plugin(DiscoInfo, Form, iterable=True)
+
+ def post_init(self):
+ """Handle cross-plugin dependencies."""
+ base_plugin.post_init(self)
+ self.disco = self.xmpp['xep_0030']
+ self.static = StaticExtendedDisco(self.disco.static)
+
+ self.disco.set_extended_info = self.set_extended_info
+ self.disco.add_extended_info = self.add_extended_info
+ self.disco.del_extended_info = self.del_extended_info
+
+ for op in self._disco_ops:
+ self.disco._add_disco_op(op, getattr(self.static, op))
+
+ def set_extended_info(self, jid=None, node=None, **kwargs):
+ """
+ Set additional, extended identity information to a node.
+
+ Replaces any existing extended information.
+
+ Arguments:
+ jid -- The JID to modify.
+ node -- The node to modify.
+ data -- Either a form, or a list of forms to use
+ as extended information, replacing any
+ existing extensions.
+ """
+ self.disco._run_node_handler('set_extended_info', jid, node, kwargs)
+
+ def add_extended_info(self, jid=None, node=None, **kwargs):
+ """
+ Add additional, extended identity information to a node.
+
+ Arguments:
+ jid -- The JID to modify.
+ node -- The node to modify.
+ data -- Either a form, or a list of forms to add
+ as extended information.
+ """
+ self.disco._run_node_handler('add_extended_info', jid, node, kwargs)
+
+ def del_extended_info(self, jid=None, node=None, **kwargs):
+ """
+ Remove all extended identity information to a node.
+
+ Arguments:
+ jid -- The JID to modify.
+ node -- The node to modify.
+ """
+ self.disco._run_node_handler('del_extended_info', jid, node, kwargs)
diff --git a/sleekxmpp/plugins/xep_0128/static.py b/sleekxmpp/plugins/xep_0128/static.py
new file mode 100644
index 00000000..493d9370
--- /dev/null
+++ b/sleekxmpp/plugins/xep_0128/static.py
@@ -0,0 +1,72 @@
+"""
+ SleekXMPP: The Sleek XMPP Library
+ Copyright (C) 2010 Nathanael C. Fritz, Lance J.T. Stout
+ This file is part of SleekXMPP.
+
+ See the file LICENSE for copying permission.
+"""
+
+import logging
+
+import sleekxmpp
+from sleekxmpp.plugins.xep_0030 import StaticDisco
+
+
+log = logging.getLogger(__name__)
+
+
+class StaticExtendedDisco(object):
+
+ """
+ Extend the default StaticDisco implementation to provide
+ support for extended identity information.
+ """
+
+ def __init__(self, static):
+ """
+ Augment the default XEP-0030 static handler object.
+
+ Arguments:
+ static -- The default static XEP-0030 handler object.
+ """
+ self.static = static
+
+ def set_extended_info(self, jid, node, data):
+ """
+ Replace the extended identity data for a JID/node combination.
+
+ The data parameter may provide:
+ data -- Either a single data form, or a list of data forms.
+ """
+ self.del_extended_info(jid, node, data)
+ self.add_extended_info(jid, node, data)
+
+ def add_extended_info(self, jid, node, data):
+ """
+ Add additional extended identity data for a JID/node combination.
+
+ The data parameter may provide:
+ data -- Either a single data form, or a list of data forms.
+ """
+ self.static.add_node(jid, node)
+
+ forms = data.get('data', [])
+ if not isinstance(forms, list):
+ forms = [forms]
+
+ for form in forms:
+ self.static.nodes[(jid, node)]['info'].append(form)
+
+ def del_extended_info(self, jid, node, data):
+ """
+ Replace the extended identity data for a JID/node combination.
+
+ The data parameter is not used.
+ """
+ if (jid, node) not in self.static.nodes:
+ return
+
+ info = self.static.nodes[(jid, node)]['info']
+
+ for form in info['substanza']:
+ info.xml.remove(form.xml)