summaryrefslogtreecommitdiff
path: root/sleekxmpp/plugins/xep_0128
diff options
context:
space:
mode:
Diffstat (limited to 'sleekxmpp/plugins/xep_0128')
-rw-r--r--sleekxmpp/plugins/xep_0128/__init__.py11
-rw-r--r--sleekxmpp/plugins/xep_0128/extended_disco.py18
-rw-r--r--sleekxmpp/plugins/xep_0128/static.py37
3 files changed, 38 insertions, 28 deletions
diff --git a/sleekxmpp/plugins/xep_0128/__init__.py b/sleekxmpp/plugins/xep_0128/__init__.py
index 3c6379a3..27c2cc33 100644
--- a/sleekxmpp/plugins/xep_0128/__init__.py
+++ b/sleekxmpp/plugins/xep_0128/__init__.py
@@ -6,5 +6,14 @@
See the file LICENSE for copying permission.
"""
+from sleekxmpp.plugins.base import register_plugin
+
from sleekxmpp.plugins.xep_0128.static import StaticExtendedDisco
-from sleekxmpp.plugins.xep_0128.extended_disco import xep_0128
+from sleekxmpp.plugins.xep_0128.extended_disco import XEP_0128
+
+
+register_plugin(XEP_0128)
+
+
+# Retain some backwards compatibility
+xep_0128 = XEP_0128
diff --git a/sleekxmpp/plugins/xep_0128/extended_disco.py b/sleekxmpp/plugins/xep_0128/extended_disco.py
index 63b3cfee..d49741de 100644
--- a/sleekxmpp/plugins/xep_0128/extended_disco.py
+++ b/sleekxmpp/plugins/xep_0128/extended_disco.py
@@ -11,13 +11,13 @@ 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 import BasePlugin
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):
+class XEP_0128(BasePlugin):
"""
XEP-0128: Service Discovery Extensions
@@ -39,11 +39,12 @@ class xep_0128(base_plugin):
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.xep = '0128'
- self.description = 'Service Discovery Extensions'
-
self._disco_ops = ['set_extended_info',
'add_extended_info',
'del_extended_info']
@@ -52,7 +53,6 @@ class xep_0128(base_plugin):
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)
@@ -76,7 +76,7 @@ class xep_0128(base_plugin):
as extended information, replacing any
existing extensions.
"""
- self.disco._run_node_handler('set_extended_info', jid, node, kwargs)
+ self.disco._run_node_handler('set_extended_info', jid, node, None, kwargs)
def add_extended_info(self, jid=None, node=None, **kwargs):
"""
@@ -88,7 +88,7 @@ class xep_0128(base_plugin):
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)
+ self.disco._run_node_handler('add_extended_info', jid, node, None, kwargs)
def del_extended_info(self, jid=None, node=None, **kwargs):
"""
@@ -98,4 +98,4 @@ class xep_0128(base_plugin):
jid -- The JID to modify.
node -- The node to modify.
"""
- self.disco._run_node_handler('del_extended_info', jid, node, kwargs)
+ self.disco._run_node_handler('del_extended_info', jid, node, None, kwargs)
diff --git a/sleekxmpp/plugins/xep_0128/static.py b/sleekxmpp/plugins/xep_0128/static.py
index 493d9370..427011c0 100644
--- a/sleekxmpp/plugins/xep_0128/static.py
+++ b/sleekxmpp/plugins/xep_0128/static.py
@@ -31,42 +31,43 @@ class StaticExtendedDisco(object):
"""
self.static = static
- def set_extended_info(self, jid, node, data):
+ 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.
"""
- self.del_extended_info(jid, node, data)
- self.add_extended_info(jid, node, data)
+ 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, 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.
"""
- self.static.add_node(jid, node)
+ with self.static.lock:
+ self.static.add_node(jid, node)
- forms = data.get('data', [])
- if not isinstance(forms, list):
- forms = [forms]
+ forms = data.get('data', [])
+ if not isinstance(forms, list):
+ forms = [forms]
- for form in forms:
- self.static.nodes[(jid, node)]['info'].append(form)
+ info = self.static.get_node(jid, node)['info']
+ for form in forms:
+ info.append(form)
- def del_extended_info(self, jid, node, data):
+ 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.
"""
- 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)
+ 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)