Update XEP-0030 and XEP-0059 to new system.

This commit is contained in:
Lance Stout 2012-03-11 18:30:47 -07:00
parent 1a153487c3
commit 8b06d10415
4 changed files with 50 additions and 48 deletions

View File

@ -11,17 +11,18 @@ import logging
import sleekxmpp
from sleekxmpp import Iq
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.matcher import StanzaPath
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__)
class xep_0030(base_plugin):
class XEP_0030(BasePlugin):
"""
XEP-0030: Service Discovery
@ -85,14 +86,15 @@ class xep_0030(base_plugin):
add_item --
"""
name = 'xep_0030'
description = 'XEP-0030: Service Discovery'
dependencies = set()
stanza = stanza
def plugin_init(self):
"""
Start the XEP-0030 plugin.
"""
self.xep = '0030'
self.description = 'Service Discovery'
self.stanza = sleekxmpp.plugins.xep_0030.stanza
self.xmpp.register_handler(
Callback('Disco Info',
StanzaPath('iq/disco_info'),
@ -123,13 +125,6 @@ class xep_0030(base_plugin):
for op in self._disco_ops:
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):
self.default_handlers[op] = default_handler
self._handlers[op] = {'global': default_handler,
@ -794,7 +789,10 @@ class xep_0030(base_plugin):
return payload
register_plugin(XEP_0030)
# Retain some backwards compatibility
xep_0030.getInfo = xep_0030.get_info
xep_0030.getItems = xep_0030.get_items
xep_0030.make_static = xep_0030.restore_defaults
xep_0030 = XEP_0030
XEP_0030.getInfo = XEP_0030.get_info
XEP_0030.getItems = XEP_0030.get_items
XEP_0030.make_static = XEP_0030.restore_defaults

View File

@ -147,4 +147,3 @@ class DiscoItem(ElementBase):
register_stanza_plugin(DiscoItems, DiscoItem, iterable=True)

View File

@ -12,7 +12,6 @@ import threading
import sleekxmpp
from sleekxmpp import Iq
from sleekxmpp.exceptions import XMPPError, IqError, IqTimeout
from sleekxmpp.plugins.base import base_plugin
from sleekxmpp.xmlstream.handler import Callback
from sleekxmpp.xmlstream.matcher import StanzaPath
from sleekxmpp.xmlstream import register_stanza_plugin, ElementBase, ET, JID
@ -202,7 +201,6 @@ class StaticDisco(object):
except IqTimeout:
return None
def get_info(self, jid, node, ifrom, data):
"""
Return the stored info data for the requested JID/node combination.
@ -343,7 +341,8 @@ class StaticDisco(object):
"""
with self.lock:
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):
"""
@ -366,7 +365,8 @@ class StaticDisco(object):
"""
with self.lock:
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):
"""

View File

@ -10,9 +10,9 @@ import logging
import sleekxmpp
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.plugins.xep_0059 import Set
from sleekxmpp.plugins.xep_0059 import stanza, Set
from sleekxmpp.exceptions import XMPPError
@ -96,24 +96,24 @@ class ResultIterator():
raise StopIteration
class xep_0059(base_plugin):
class XEP_0059(BasePlugin):
"""
XEP-0050: Result Set Management
"""
name = 'xep_0059'
description = 'XEP-0059: Result Set Management'
dependencies = set(['xep_0030'])
stanza = stanza
def plugin_init(self):
"""
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)
register_stanza_plugin(self.xmpp['xep_0030'].stanza.DiscoItems,
self.stanza.Set)
def iterate(self, stanza, interface):
"""
@ -129,3 +129,8 @@ class xep_0059(base_plugin):
the interface 'disco_items' should be used.
"""
return ResultIterator(stanza, interface)
register_plugin(XEP_0059)
xep_0059 = XEP_0059