From 5ab77c745270d7d5c016c1dc7ef2a82533a4b16e Mon Sep 17 00:00:00 2001 From: Florent Le Coz Date: Thu, 17 Jul 2014 14:19:04 +0200 Subject: Rename to slixmpp --- slixmpp/plugins/xep_0128/__init__.py | 19 ++++++ slixmpp/plugins/xep_0128/extended_disco.py | 99 ++++++++++++++++++++++++++++++ slixmpp/plugins/xep_0128/static.py | 73 ++++++++++++++++++++++ 3 files changed, 191 insertions(+) create mode 100644 slixmpp/plugins/xep_0128/__init__.py create mode 100644 slixmpp/plugins/xep_0128/extended_disco.py create mode 100644 slixmpp/plugins/xep_0128/static.py (limited to 'slixmpp/plugins/xep_0128') diff --git a/slixmpp/plugins/xep_0128/__init__.py b/slixmpp/plugins/xep_0128/__init__.py new file mode 100644 index 00000000..fb6dbf7c --- /dev/null +++ b/slixmpp/plugins/xep_0128/__init__.py @@ -0,0 +1,19 @@ +""" + Slixmpp: The Slick XMPP Library + Copyright (C) 2010 Nathanael C. Fritz, Lance J.T. Stout + This file is part of Slixmpp. + + See the file LICENSE for copying permission. +""" + +from slixmpp.plugins.base import register_plugin + +from slixmpp.plugins.xep_0128.static import StaticExtendedDisco +from slixmpp.plugins.xep_0128.extended_disco import XEP_0128 + + +register_plugin(XEP_0128) + + +# Retain some backwards compatibility +xep_0128 = XEP_0128 diff --git a/slixmpp/plugins/xep_0128/extended_disco.py b/slixmpp/plugins/xep_0128/extended_disco.py new file mode 100644 index 00000000..5cc1d35a --- /dev/null +++ b/slixmpp/plugins/xep_0128/extended_disco.py @@ -0,0 +1,99 @@ +""" + Slixmpp: The Slick XMPP Library + Copyright (C) 2010 Nathanael C. Fritz, Lance J.T. Stout + This file is part of Slixmpp. + + See the file LICENSE for copying permission. +""" + +import logging + +import slixmpp +from slixmpp import Iq +from slixmpp.xmlstream import register_stanza_plugin +from slixmpp.plugins import BasePlugin +from slixmpp.plugins.xep_0004 import Form +from slixmpp.plugins.xep_0030 import DiscoInfo +from slixmpp.plugins.xep_0128 import StaticExtendedDisco + + +class XEP_0128(BasePlugin): + + """ + XEP-0128: Service Discovery Extensions + + Allow the use of data forms to add additional identity + information to disco#info results. + + Also see . + + Attributes: + disco -- A reference to the XEP-0030 plugin. + static -- Object containing the default set of static + node handlers. + xmpp -- The main Slixmpp 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. + """ + + name = 'xep_0128' + description = 'XEP-0128: Service Discovery Extensions' + dependencies = set(['xep_0030', 'xep_0004']) + + def plugin_init(self): + """Start the XEP-0128 plugin.""" + self._disco_ops = ['set_extended_info', + 'add_extended_info', + 'del_extended_info'] + + register_stanza_plugin(DiscoInfo, Form, iterable=True) + + 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.api.register(getattr(self.static, op), op, default=True) + + 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.api['set_extended_info'](jid, node, None, 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.api['add_extended_info'](jid, node, None, 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.api['del_extended_info'](jid, node, None, kwargs) diff --git a/slixmpp/plugins/xep_0128/static.py b/slixmpp/plugins/xep_0128/static.py new file mode 100644 index 00000000..ab1ea590 --- /dev/null +++ b/slixmpp/plugins/xep_0128/static.py @@ -0,0 +1,73 @@ +""" + Slixmpp: The Slick XMPP Library + Copyright (C) 2010 Nathanael C. Fritz, Lance J.T. Stout + This file is part of Slixmpp. + + See the file LICENSE for copying permission. +""" + +import logging + +import slixmpp +from slixmpp.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, ifrom, 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. + """ + with self.static.lock: + self.del_extended_info(jid, node, ifrom, data) + self.add_extended_info(jid, node, ifrom, data) + + def add_extended_info(self, jid, node, ifrom, 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. + """ + with self.static.lock: + self.static.add_node(jid, node) + + forms = data.get('data', []) + if not isinstance(forms, list): + forms = [forms] + + info = self.static.get_node(jid, node)['info'] + for form in forms: + info.append(form) + + def del_extended_info(self, jid, node, ifrom, data): + """ + Replace the extended identity data for a JID/node combination. + + The data parameter is not used. + """ + with self.static.lock: + if self.static.node_exists(jid, node): + info = self.static.get_node(jid, node)['info'] + for form in info['substanza']: + info.xml.remove(form.xml) -- cgit v1.2.3