Update XEP-0030 and XEP-0059 to new system.
This commit is contained in:
parent
1a153487c3
commit
8b06d10415
@ -11,17 +11,18 @@ import logging
|
|||||||
import sleekxmpp
|
import sleekxmpp
|
||||||
from sleekxmpp import Iq
|
from sleekxmpp import Iq
|
||||||
from sleekxmpp.exceptions import XMPPError, IqError, IqTimeout
|
from sleekxmpp.exceptions import XMPPError, IqError, IqTimeout
|
||||||
from sleekxmpp.plugins.base import base_plugin
|
from sleekxmpp.plugins import BasePlugin, register_plugin
|
||||||
from sleekxmpp.xmlstream.handler import Callback
|
from sleekxmpp.xmlstream.handler import Callback
|
||||||
from sleekxmpp.xmlstream.matcher import StanzaPath
|
from sleekxmpp.xmlstream.matcher import StanzaPath
|
||||||
from sleekxmpp.xmlstream import register_stanza_plugin, ElementBase, ET, JID
|
from sleekxmpp.xmlstream import register_stanza_plugin, ElementBase, ET, JID
|
||||||
from sleekxmpp.plugins.xep_0030 import DiscoInfo, DiscoItems, StaticDisco
|
from sleekxmpp.plugins.xep_0030 import stanza, DiscoInfo, DiscoItems
|
||||||
|
from sleekxmpp.plugins.xep_0030 import StaticDisco
|
||||||
|
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class xep_0030(base_plugin):
|
class XEP_0030(BasePlugin):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
XEP-0030: Service Discovery
|
XEP-0030: Service Discovery
|
||||||
@ -85,14 +86,15 @@ class xep_0030(base_plugin):
|
|||||||
add_item --
|
add_item --
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
name = 'xep_0030'
|
||||||
|
description = 'XEP-0030: Service Discovery'
|
||||||
|
dependencies = set()
|
||||||
|
stanza = stanza
|
||||||
|
|
||||||
def plugin_init(self):
|
def plugin_init(self):
|
||||||
"""
|
"""
|
||||||
Start the XEP-0030 plugin.
|
Start the XEP-0030 plugin.
|
||||||
"""
|
"""
|
||||||
self.xep = '0030'
|
|
||||||
self.description = 'Service Discovery'
|
|
||||||
self.stanza = sleekxmpp.plugins.xep_0030.stanza
|
|
||||||
|
|
||||||
self.xmpp.register_handler(
|
self.xmpp.register_handler(
|
||||||
Callback('Disco Info',
|
Callback('Disco Info',
|
||||||
StanzaPath('iq/disco_info'),
|
StanzaPath('iq/disco_info'),
|
||||||
@ -123,13 +125,6 @@ class xep_0030(base_plugin):
|
|||||||
for op in self._disco_ops:
|
for op in self._disco_ops:
|
||||||
self._add_disco_op(op, getattr(self.static, op))
|
self._add_disco_op(op, getattr(self.static, op))
|
||||||
|
|
||||||
def post_init(self):
|
|
||||||
"""Handle cross-plugin dependencies."""
|
|
||||||
base_plugin.post_init(self)
|
|
||||||
if 'xep_0059' in self.xmpp.plugin:
|
|
||||||
register_stanza_plugin(DiscoItems,
|
|
||||||
self.xmpp['xep_0059'].stanza.Set)
|
|
||||||
|
|
||||||
def _add_disco_op(self, op, default_handler):
|
def _add_disco_op(self, op, default_handler):
|
||||||
self.default_handlers[op] = default_handler
|
self.default_handlers[op] = default_handler
|
||||||
self._handlers[op] = {'global': default_handler,
|
self._handlers[op] = {'global': default_handler,
|
||||||
@ -794,7 +789,10 @@ class xep_0030(base_plugin):
|
|||||||
return payload
|
return payload
|
||||||
|
|
||||||
|
|
||||||
|
register_plugin(XEP_0030)
|
||||||
|
|
||||||
# Retain some backwards compatibility
|
# Retain some backwards compatibility
|
||||||
xep_0030.getInfo = xep_0030.get_info
|
xep_0030 = XEP_0030
|
||||||
xep_0030.getItems = xep_0030.get_items
|
XEP_0030.getInfo = XEP_0030.get_info
|
||||||
xep_0030.make_static = xep_0030.restore_defaults
|
XEP_0030.getItems = XEP_0030.get_items
|
||||||
|
XEP_0030.make_static = XEP_0030.restore_defaults
|
||||||
|
@ -147,4 +147,3 @@ class DiscoItem(ElementBase):
|
|||||||
|
|
||||||
|
|
||||||
register_stanza_plugin(DiscoItems, DiscoItem, iterable=True)
|
register_stanza_plugin(DiscoItems, DiscoItem, iterable=True)
|
||||||
|
|
||||||
|
@ -12,7 +12,6 @@ import threading
|
|||||||
import sleekxmpp
|
import sleekxmpp
|
||||||
from sleekxmpp import Iq
|
from sleekxmpp import Iq
|
||||||
from sleekxmpp.exceptions import XMPPError, IqError, IqTimeout
|
from sleekxmpp.exceptions import XMPPError, IqError, IqTimeout
|
||||||
from sleekxmpp.plugins.base import base_plugin
|
|
||||||
from sleekxmpp.xmlstream.handler import Callback
|
from sleekxmpp.xmlstream.handler import Callback
|
||||||
from sleekxmpp.xmlstream.matcher import StanzaPath
|
from sleekxmpp.xmlstream.matcher import StanzaPath
|
||||||
from sleekxmpp.xmlstream import register_stanza_plugin, ElementBase, ET, JID
|
from sleekxmpp.xmlstream import register_stanza_plugin, ElementBase, ET, JID
|
||||||
@ -202,7 +201,6 @@ class StaticDisco(object):
|
|||||||
except IqTimeout:
|
except IqTimeout:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def get_info(self, jid, node, ifrom, data):
|
def get_info(self, jid, node, ifrom, data):
|
||||||
"""
|
"""
|
||||||
Return the stored info data for the requested JID/node combination.
|
Return the stored info data for the requested JID/node combination.
|
||||||
@ -343,7 +341,8 @@ class StaticDisco(object):
|
|||||||
"""
|
"""
|
||||||
with self.lock:
|
with self.lock:
|
||||||
self.add_node(jid, node)
|
self.add_node(jid, node)
|
||||||
self.get_node(jid, node)['info'].add_feature(data.get('feature', ''))
|
self.get_node(jid, node)['info'].add_feature(
|
||||||
|
data.get('feature', ''))
|
||||||
|
|
||||||
def set_features(self, jid, node, ifrom, data):
|
def set_features(self, jid, node, ifrom, data):
|
||||||
"""
|
"""
|
||||||
@ -366,7 +365,8 @@ class StaticDisco(object):
|
|||||||
"""
|
"""
|
||||||
with self.lock:
|
with self.lock:
|
||||||
if self.node_exists(jid, node):
|
if self.node_exists(jid, node):
|
||||||
self.get_node(jid, node)['info'].del_feature(data.get('feature', ''))
|
self.get_node(jid, node)['info'].del_feature(
|
||||||
|
data.get('feature', ''))
|
||||||
|
|
||||||
def del_features(self, jid, node, ifrom, data):
|
def del_features(self, jid, node, ifrom, data):
|
||||||
"""
|
"""
|
||||||
|
@ -10,9 +10,9 @@ import logging
|
|||||||
|
|
||||||
import sleekxmpp
|
import sleekxmpp
|
||||||
from sleekxmpp import Iq
|
from sleekxmpp import Iq
|
||||||
from sleekxmpp.plugins.base import base_plugin
|
from sleekxmpp.plugins import BasePlugin, register_plugin
|
||||||
from sleekxmpp.xmlstream import register_stanza_plugin
|
from sleekxmpp.xmlstream import register_stanza_plugin
|
||||||
from sleekxmpp.plugins.xep_0059 import Set
|
from sleekxmpp.plugins.xep_0059 import stanza, Set
|
||||||
from sleekxmpp.exceptions import XMPPError
|
from sleekxmpp.exceptions import XMPPError
|
||||||
|
|
||||||
|
|
||||||
@ -96,24 +96,24 @@ class ResultIterator():
|
|||||||
raise StopIteration
|
raise StopIteration
|
||||||
|
|
||||||
|
|
||||||
class xep_0059(base_plugin):
|
class XEP_0059(BasePlugin):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
XEP-0050: Result Set Management
|
XEP-0050: Result Set Management
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
name = 'xep_0059'
|
||||||
|
description = 'XEP-0059: Result Set Management'
|
||||||
|
dependencies = set(['xep_0030'])
|
||||||
|
stanza = stanza
|
||||||
|
|
||||||
def plugin_init(self):
|
def plugin_init(self):
|
||||||
"""
|
"""
|
||||||
Start the XEP-0059 plugin.
|
Start the XEP-0059 plugin.
|
||||||
"""
|
"""
|
||||||
self.xep = '0059'
|
|
||||||
self.description = 'Result Set Management'
|
|
||||||
self.stanza = sleekxmpp.plugins.xep_0059.stanza
|
|
||||||
|
|
||||||
def post_init(self):
|
|
||||||
"""Handle inter-plugin dependencies."""
|
|
||||||
base_plugin.post_init(self)
|
|
||||||
self.xmpp['xep_0030'].add_feature(Set.namespace)
|
self.xmpp['xep_0030'].add_feature(Set.namespace)
|
||||||
|
register_stanza_plugin(self.xmpp['xep_0030'].stanza.DiscoItems,
|
||||||
|
self.stanza.Set)
|
||||||
|
|
||||||
def iterate(self, stanza, interface):
|
def iterate(self, stanza, interface):
|
||||||
"""
|
"""
|
||||||
@ -129,3 +129,8 @@ class xep_0059(base_plugin):
|
|||||||
the interface 'disco_items' should be used.
|
the interface 'disco_items' should be used.
|
||||||
"""
|
"""
|
||||||
return ResultIterator(stanza, interface)
|
return ResultIterator(stanza, interface)
|
||||||
|
|
||||||
|
|
||||||
|
register_plugin(XEP_0059)
|
||||||
|
|
||||||
|
xep_0059 = XEP_0059
|
||||||
|
Loading…
Reference in New Issue
Block a user