Condensed all of the stanzaPlugin functions into a single registerStanzaPlugin function.

Updated plugins and tests to use new function.
This commit is contained in:
Lance Stout 2010-07-19 13:58:53 -04:00
parent e6bec8681e
commit d5e42ac0e7
23 changed files with 98 additions and 106 deletions

View file

@ -16,6 +16,7 @@ from . xmlstream.handler.xmlcallback import XMLCallback
from . xmlstream.handler.xmlwaiter import XMLWaiter from . xmlstream.handler.xmlwaiter import XMLWaiter
from . xmlstream.handler.waiter import Waiter from . xmlstream.handler.waiter import Waiter
from . xmlstream.handler.callback import Callback from . xmlstream.handler.callback import Callback
from . xmlstream.stanzabase import registerStanzaPlugin
from . import plugins from . import plugins
from . stanza.message import Message from . stanza.message import Message
from . stanza.iq import Iq from . stanza.iq import Iq
@ -35,12 +36,6 @@ if sys.version_info < (3,0):
reload(sys) reload(sys)
sys.setdefaultencoding('utf8') sys.setdefaultencoding('utf8')
def stanzaPlugin(stanza, plugin):
stanza.plugin_attrib_map[plugin.plugin_attrib] = plugin
stanza.plugin_tag_map["{%s}%s" % (plugin.namespace, plugin.name)] = plugin
class basexmpp(object): class basexmpp(object):
def __init__(self): def __init__(self):
self.id = 0 self.id = 0
@ -62,13 +57,9 @@ class basexmpp(object):
self.registerStanza(Message) self.registerStanza(Message)
self.registerStanza(Iq) self.registerStanza(Iq)
self.registerStanza(Presence) self.registerStanza(Presence)
self.stanzaPlugin(Iq, Roster) registerStanzaPlugin(Iq, Roster)
self.stanzaPlugin(Message, Nick) registerStanzaPlugin(Message, Nick)
self.stanzaPlugin(Message, HTMLIM) registerStanzaPlugin(Message, HTMLIM)
def stanzaPlugin(self, stanza, plugin):
stanza.plugin_attrib_map[plugin.plugin_attrib] = plugin
stanza.plugin_tag_map["{%s}%s" % (plugin.namespace, plugin.name)] = plugin
def Message(self, *args, **kwargs): def Message(self, *args, **kwargs):
return Message(self, *args, **kwargs) return Message(self, *args, **kwargs)

View file

@ -11,7 +11,7 @@ import copy
from . import base from . import base
from .. xmlstream.handler.callback import Callback from .. xmlstream.handler.callback import Callback
from .. xmlstream.matcher.xpath import MatchXPath from .. xmlstream.matcher.xpath import MatchXPath
from .. xmlstream.stanzabase import ElementBase, ET, JID from .. xmlstream.stanzabase import registerStanzaPlugin, ElementBase, ET, JID
from .. stanza.message import Message from .. stanza.message import Message
@ -318,9 +318,9 @@ class alt_0004(base.base_plugin):
Form.namespace)), Form.namespace)),
self.handle_form)) self.handle_form))
self.xmpp.stanzaPlugin(FormField, FieldOption) registerStanzaPlugin(FormField, FieldOption)
self.xmpp.stanzaPlugin(Form, FormField) registerStanzaPlugin(Form, FormField)
self.xmpp.stanzaPlugin(Message, Form) registerStanzaPlugin(Message, Form)
def post_init(self): def post_init(self):
base.base_plugin.post_init(self) base.base_plugin.post_init(self)

View file

@ -10,7 +10,7 @@ import logging
from . import base from . import base
from .. xmlstream.handler.callback import Callback from .. xmlstream.handler.callback import Callback
from .. xmlstream.matcher.xpath import MatchXPath from .. xmlstream.matcher.xpath import MatchXPath
from .. xmlstream.stanzabase import ElementBase, ET, JID from .. xmlstream.stanzabase import registerStanzaPlugin, ElementBase, ET, JID
from .. stanza.iq import Iq from .. stanza.iq import Iq
@ -109,9 +109,9 @@ class gmail_notify(base.base_plugin):
NewMail.name)), NewMail.name)),
self.handle_new_mail)) self.handle_new_mail))
self.xmpp.stanzaPlugin(Iq, GmailQuery) registerStanzaPlugin(Iq, GmailQuery)
self.xmpp.stanzaPlugin(Iq, MailBox) registerStanzaPlugin(Iq, MailBox)
self.xmpp.stanzaPlugin(Iq, NewMail) registerStanzaPlugin(Iq, NewMail)
self.last_result_time = None self.last_result_time = None

View file

@ -1,4 +1,4 @@
from .. xmlstream.stanzabase import ElementBase, ET, JID from .. xmlstream.stanzabase import registerStanzaPlugin, ElementBase, ET, JID
from .. stanza.iq import Iq from .. stanza.iq import Iq
from .. stanza.message import Message from .. stanza.message import Message
from .. basexmpp import basexmpp from .. basexmpp import basexmpp
@ -6,9 +6,6 @@ from .. xmlstream.xmlstream import XMLStream
import logging import logging
from . import xep_0004 from . import xep_0004
def stanzaPlugin(stanza, plugin):
stanza.plugin_attrib_map[plugin.plugin_attrib] = plugin
stanza.plugin_tag_map["{%s}%s" % (plugin.namespace, plugin.name)] = plugin
class PubsubState(ElementBase): class PubsubState(ElementBase):
namespace = 'http://jabber.org/protocol/psstate' namespace = 'http://jabber.org/protocol/psstate'
@ -30,7 +27,7 @@ class PubsubState(ElementBase):
for child in self.xml.getchildren(): for child in self.xml.getchildren():
self.xml.remove(child) self.xml.remove(child)
stanzaPlugin(Iq, PubsubState) registerStanzaPlugin(Iq, PubsubState)
class PubsubStateEvent(ElementBase): class PubsubStateEvent(ElementBase):
namespace = 'http://jabber.org/protocol/psstate#event' namespace = 'http://jabber.org/protocol/psstate#event'
@ -40,8 +37,8 @@ class PubsubStateEvent(ElementBase):
plugin_attrib_map = {} plugin_attrib_map = {}
plugin_tag_map = {} plugin_tag_map = {}
stanzaPlugin(Message, PubsubStateEvent) registerStanzaPlugin(Message, PubsubStateEvent)
stanzaPlugin(PubsubStateEvent, PubsubState) registerStanzaPlugin(PubsubStateEvent, PubsubState)
class Pubsub(ElementBase): class Pubsub(ElementBase):
namespace = 'http://jabber.org/protocol/pubsub' namespace = 'http://jabber.org/protocol/pubsub'
@ -51,7 +48,7 @@ class Pubsub(ElementBase):
plugin_attrib_map = {} plugin_attrib_map = {}
plugin_tag_map = {} plugin_tag_map = {}
stanzaPlugin(Iq, Pubsub) registerStanzaPlugin(Iq, Pubsub)
class PubsubOwner(ElementBase): class PubsubOwner(ElementBase):
namespace = 'http://jabber.org/protocol/pubsub#owner' namespace = 'http://jabber.org/protocol/pubsub#owner'
@ -61,7 +58,7 @@ class PubsubOwner(ElementBase):
plugin_attrib_map = {} plugin_attrib_map = {}
plugin_tag_map = {} plugin_tag_map = {}
stanzaPlugin(Iq, PubsubOwner) registerStanzaPlugin(Iq, PubsubOwner)
class Affiliation(ElementBase): class Affiliation(ElementBase):
namespace = 'http://jabber.org/protocol/pubsub' namespace = 'http://jabber.org/protocol/pubsub'
@ -86,7 +83,7 @@ class Affiliations(ElementBase):
self.xml.append(affiliation.xml) self.xml.append(affiliation.xml)
return self.iterables.append(affiliation) return self.iterables.append(affiliation)
stanzaPlugin(Pubsub, Affiliations) registerStanzaPlugin(Pubsub, Affiliations)
class Subscription(ElementBase): class Subscription(ElementBase):
@ -103,7 +100,7 @@ class Subscription(ElementBase):
def getjid(self): def getjid(self):
return jid(self._getattr('jid')) return jid(self._getattr('jid'))
stanzaPlugin(Pubsub, Subscription) registerStanzaPlugin(Pubsub, Subscription)
class Subscriptions(ElementBase): class Subscriptions(ElementBase):
namespace = 'http://jabber.org/protocol/pubsub' namespace = 'http://jabber.org/protocol/pubsub'
@ -114,7 +111,7 @@ class Subscriptions(ElementBase):
plugin_tag_map = {} plugin_tag_map = {}
subitem = (Subscription,) subitem = (Subscription,)
stanzaPlugin(Pubsub, Subscriptions) registerStanzaPlugin(Pubsub, Subscriptions)
class OptionalSetting(object): class OptionalSetting(object):
interfaces = set(('required',)) interfaces = set(('required',))
@ -147,7 +144,7 @@ class SubscribeOptions(ElementBase, OptionalSetting):
plugin_tag_map = {} plugin_tag_map = {}
interfaces = set(('required',)) interfaces = set(('required',))
stanzaPlugin(Subscription, SubscribeOptions) registerStanzaPlugin(Subscription, SubscribeOptions)
class Item(ElementBase): class Item(ElementBase):
namespace = 'http://jabber.org/protocol/pubsub' namespace = 'http://jabber.org/protocol/pubsub'
@ -178,7 +175,7 @@ class Items(ElementBase):
plugin_tag_map = {} plugin_tag_map = {}
subitem = (Item,) subitem = (Item,)
stanzaPlugin(Pubsub, Items) registerStanzaPlugin(Pubsub, Items)
class Create(ElementBase): class Create(ElementBase):
namespace = 'http://jabber.org/protocol/pubsub' namespace = 'http://jabber.org/protocol/pubsub'
@ -188,7 +185,7 @@ class Create(ElementBase):
plugin_attrib_map = {} plugin_attrib_map = {}
plugin_tag_map = {} plugin_tag_map = {}
stanzaPlugin(Pubsub, Create) registerStanzaPlugin(Pubsub, Create)
#class Default(ElementBase): #class Default(ElementBase):
# namespace = 'http://jabber.org/protocol/pubsub' # namespace = 'http://jabber.org/protocol/pubsub'
@ -203,7 +200,7 @@ stanzaPlugin(Pubsub, Create)
# if not t: t == 'leaf' # if not t: t == 'leaf'
# return t # return t
# #
#stanzaPlugin(Pubsub, Default) #registerStanzaPlugin(Pubsub, Default)
class Publish(Items): class Publish(Items):
namespace = 'http://jabber.org/protocol/pubsub' namespace = 'http://jabber.org/protocol/pubsub'
@ -214,7 +211,7 @@ class Publish(Items):
plugin_tag_map = {} plugin_tag_map = {}
subitem = (Item,) subitem = (Item,)
stanzaPlugin(Pubsub, Publish) registerStanzaPlugin(Pubsub, Publish)
class Retract(Items): class Retract(Items):
namespace = 'http://jabber.org/protocol/pubsub' namespace = 'http://jabber.org/protocol/pubsub'
@ -224,7 +221,7 @@ class Retract(Items):
plugin_attrib_map = {} plugin_attrib_map = {}
plugin_tag_map = {} plugin_tag_map = {}
stanzaPlugin(Pubsub, Retract) registerStanzaPlugin(Pubsub, Retract)
class Unsubscribe(ElementBase): class Unsubscribe(ElementBase):
namespace = 'http://jabber.org/protocol/pubsub' namespace = 'http://jabber.org/protocol/pubsub'
@ -254,7 +251,7 @@ class Subscribe(ElementBase):
def getJid(self): def getJid(self):
return JID(self._getAttr('jid')) return JID(self._getAttr('jid'))
stanzaPlugin(Pubsub, Subscribe) registerStanzaPlugin(Pubsub, Subscribe)
class Configure(ElementBase): class Configure(ElementBase):
namespace = 'http://jabber.org/protocol/pubsub' namespace = 'http://jabber.org/protocol/pubsub'
@ -284,7 +281,7 @@ class Configure(ElementBase):
config = self.xml.find('{jabber:x:data}x') config = self.xml.find('{jabber:x:data}x')
self.xml.remove(config) self.xml.remove(config)
stanzaPlugin(Pubsub, Configure) registerStanzaPlugin(Pubsub, Configure)
class DefaultConfig(ElementBase): class DefaultConfig(ElementBase):
namespace = 'http://jabber.org/protocol/pubsub#owner' namespace = 'http://jabber.org/protocol/pubsub#owner'
@ -317,7 +314,7 @@ class DefaultConfig(ElementBase):
if not t: t = 'leaf' if not t: t = 'leaf'
return t return t
stanzaPlugin(PubsubOwner, DefaultConfig) registerStanzaPlugin(PubsubOwner, DefaultConfig)
class Options(ElementBase): class Options(ElementBase):
namespace = 'http://jabber.org/protocol/pubsub' namespace = 'http://jabber.org/protocol/pubsub'
@ -351,8 +348,8 @@ class Options(ElementBase):
def getJid(self): def getJid(self):
return JID(self._getAttr('jid')) return JID(self._getAttr('jid'))
stanzaPlugin(Pubsub, Options) registerStanzaPlugin(Pubsub, Options)
stanzaPlugin(Subscribe, Options) registerStanzaPlugin(Subscribe, Options)
class OwnerAffiliations(Affiliations): class OwnerAffiliations(Affiliations):
namespace = 'http://jabber.org/protocol/pubsub#owner' namespace = 'http://jabber.org/protocol/pubsub#owner'
@ -366,7 +363,7 @@ class OwnerAffiliations(Affiliations):
self.xml.append(affiliation.xml) self.xml.append(affiliation.xml)
return self.affiliations.append(affiliation) return self.affiliations.append(affiliation)
stanzaPlugin(PubsubOwner, OwnerAffiliations) registerStanzaPlugin(PubsubOwner, OwnerAffiliations)
class OwnerAffiliation(Affiliation): class OwnerAffiliation(Affiliation):
namespace = 'http://jabber.org/protocol/pubsub#owner' namespace = 'http://jabber.org/protocol/pubsub#owner'
@ -380,7 +377,7 @@ class OwnerConfigure(Configure):
plugin_attrib_map = {} plugin_attrib_map = {}
plugin_tag_map = {} plugin_tag_map = {}
stanzaPlugin(PubsubOwner, OwnerConfigure) registerStanzaPlugin(PubsubOwner, OwnerConfigure)
class OwnerDefault(OwnerConfigure): class OwnerDefault(OwnerConfigure):
namespace = 'http://jabber.org/protocol/pubsub#owner' namespace = 'http://jabber.org/protocol/pubsub#owner'
@ -388,7 +385,7 @@ class OwnerDefault(OwnerConfigure):
plugin_attrib_map = {} plugin_attrib_map = {}
plugin_tag_map = {} plugin_tag_map = {}
stanzaPlugin(PubsubOwner, OwnerDefault) registerStanzaPlugin(PubsubOwner, OwnerDefault)
class OwnerDelete(ElementBase, OptionalSetting): class OwnerDelete(ElementBase, OptionalSetting):
namespace = 'http://jabber.org/protocol/pubsub#owner' namespace = 'http://jabber.org/protocol/pubsub#owner'
@ -398,7 +395,7 @@ class OwnerDelete(ElementBase, OptionalSetting):
plugin_tag_map = {} plugin_tag_map = {}
interfaces = set(('node',)) interfaces = set(('node',))
stanzaPlugin(PubsubOwner, OwnerDelete) registerStanzaPlugin(PubsubOwner, OwnerDelete)
class OwnerPurge(ElementBase, OptionalSetting): class OwnerPurge(ElementBase, OptionalSetting):
namespace = 'http://jabber.org/protocol/pubsub#owner' namespace = 'http://jabber.org/protocol/pubsub#owner'
@ -407,7 +404,7 @@ class OwnerPurge(ElementBase, OptionalSetting):
plugin_attrib_map = {} plugin_attrib_map = {}
plugin_tag_map = {} plugin_tag_map = {}
stanzaPlugin(PubsubOwner, OwnerPurge) registerStanzaPlugin(PubsubOwner, OwnerPurge)
class OwnerRedirect(ElementBase): class OwnerRedirect(ElementBase):
namespace = 'http://jabber.org/protocol/pubsub#owner' namespace = 'http://jabber.org/protocol/pubsub#owner'
@ -423,7 +420,7 @@ class OwnerRedirect(ElementBase):
def getJid(self): def getJid(self):
return JID(self._getAttr('jid')) return JID(self._getAttr('jid'))
stanzaPlugin(OwnerDelete, OwnerRedirect) registerStanzaPlugin(OwnerDelete, OwnerRedirect)
class OwnerSubscriptions(Subscriptions): class OwnerSubscriptions(Subscriptions):
namespace = 'http://jabber.org/protocol/pubsub#owner' namespace = 'http://jabber.org/protocol/pubsub#owner'
@ -437,7 +434,7 @@ class OwnerSubscriptions(Subscriptions):
self.xml.append(subscription.xml) self.xml.append(subscription.xml)
return self.subscriptions.append(subscription) return self.subscriptions.append(subscription)
stanzaPlugin(PubsubOwner, OwnerSubscriptions) registerStanzaPlugin(PubsubOwner, OwnerSubscriptions)
class OwnerSubscription(ElementBase): class OwnerSubscription(ElementBase):
namespace = 'http://jabber.org/protocol/pubsub#owner' namespace = 'http://jabber.org/protocol/pubsub#owner'
@ -461,7 +458,7 @@ class Event(ElementBase):
plugin_attrib_map = {} plugin_attrib_map = {}
plugin_tag_map = {} plugin_tag_map = {}
stanzaPlugin(Message, Event) registerStanzaPlugin(Message, Event)
class EventItem(ElementBase): class EventItem(ElementBase):
namespace = 'http://jabber.org/protocol/pubsub#event' namespace = 'http://jabber.org/protocol/pubsub#event'
@ -501,7 +498,7 @@ class EventItems(ElementBase):
plugin_tag_map = {} plugin_tag_map = {}
subitem = (EventItem, EventRetract) subitem = (EventItem, EventRetract)
stanzaPlugin(Event, EventItems) registerStanzaPlugin(Event, EventItems)
class EventCollection(ElementBase): class EventCollection(ElementBase):
namespace = 'http://jabber.org/protocol/pubsub#event' namespace = 'http://jabber.org/protocol/pubsub#event'
@ -511,7 +508,7 @@ class EventCollection(ElementBase):
plugin_attrib_map = {} plugin_attrib_map = {}
plugin_tag_map = {} plugin_tag_map = {}
stanzaPlugin(Event, EventCollection) registerStanzaPlugin(Event, EventCollection)
class EventAssociate(ElementBase): class EventAssociate(ElementBase):
namespace = 'http://jabber.org/protocol/pubsub#event' namespace = 'http://jabber.org/protocol/pubsub#event'
@ -521,7 +518,7 @@ class EventAssociate(ElementBase):
plugin_attrib_map = {} plugin_attrib_map = {}
plugin_tag_map = {} plugin_tag_map = {}
stanzaPlugin(EventCollection, EventAssociate) registerStanzaPlugin(EventCollection, EventAssociate)
class EventDisassociate(ElementBase): class EventDisassociate(ElementBase):
namespace = 'http://jabber.org/protocol/pubsub#event' namespace = 'http://jabber.org/protocol/pubsub#event'
@ -531,7 +528,7 @@ class EventDisassociate(ElementBase):
plugin_attrib_map = {} plugin_attrib_map = {}
plugin_tag_map = {} plugin_tag_map = {}
stanzaPlugin(EventCollection, EventDisassociate) registerStanzaPlugin(EventCollection, EventDisassociate)
class EventConfiguration(ElementBase): class EventConfiguration(ElementBase):
namespace = 'http://jabber.org/protocol/pubsub#event' namespace = 'http://jabber.org/protocol/pubsub#event'
@ -556,7 +553,7 @@ class EventConfiguration(ElementBase):
config = self.xml.find('{jabber:x:data}x') config = self.xml.find('{jabber:x:data}x')
self.xml.remove(config) self.xml.remove(config)
stanzaPlugin(Event, EventConfiguration) registerStanzaPlugin(Event, EventConfiguration)
class EventPurge(ElementBase): class EventPurge(ElementBase):
namespace = 'http://jabber.org/protocol/pubsub#event' namespace = 'http://jabber.org/protocol/pubsub#event'
@ -566,7 +563,7 @@ class EventPurge(ElementBase):
plugin_attrib_map = {} plugin_attrib_map = {}
plugin_tag_map = {} plugin_tag_map = {}
stanzaPlugin(Event, EventPurge) registerStanzaPlugin(Event, EventPurge)
class EventSubscription(ElementBase): class EventSubscription(ElementBase):
namespace = 'http://jabber.org/protocol/pubsub#event' namespace = 'http://jabber.org/protocol/pubsub#event'
@ -582,4 +579,4 @@ class EventSubscription(ElementBase):
def getJid(self): def getJid(self):
return JID(self._getAttr('jid')) return JID(self._getAttr('jid'))
stanzaPlugin(Event, EventSubscription) registerStanzaPlugin(Event, EventSubscription)

View file

@ -10,7 +10,7 @@ import logging
from . import base from . import base
from .. xmlstream.handler.callback import Callback from .. xmlstream.handler.callback import Callback
from .. xmlstream.matcher.xpath import MatchXPath from .. xmlstream.matcher.xpath import MatchXPath
from .. xmlstream.stanzabase import ElementBase, ET, JID from .. xmlstream.stanzabase import registerStanzaPlugin, ElementBase, ET, JID
from .. stanza.iq import Iq from .. stanza.iq import Iq
class DiscoInfo(ElementBase): class DiscoInfo(ElementBase):
@ -204,8 +204,8 @@ class xep_0030(base.base_plugin):
DiscoInfo.namespace)), DiscoInfo.namespace)),
self.handle_info_query)) self.handle_info_query))
self.xmpp.stanzaPlugin(Iq, DiscoInfo) registerStanzaPlugin(Iq, DiscoInfo)
self.xmpp.stanzaPlugin(Iq, DiscoItems) registerStanzaPlugin(Iq, DiscoItems)
self.xmpp.add_event_handler('disco_items_request', self.handle_disco_items) self.xmpp.add_event_handler('disco_items_request', self.handle_disco_items)
self.xmpp.add_event_handler('disco_info_request', self.handle_disco_info) self.xmpp.add_event_handler('disco_info_request', self.handle_disco_info)

View file

@ -10,7 +10,7 @@ import logging
from . import base from . import base
from .. xmlstream.handler.callback import Callback from .. xmlstream.handler.callback import Callback
from .. xmlstream.matcher.xpath import MatchXPath from .. xmlstream.matcher.xpath import MatchXPath
from .. xmlstream.stanzabase import ElementBase, ET, JID from .. xmlstream.stanzabase import registerStanzaPlugin, ElementBase, ET, JID
from .. stanza.message import Message from .. stanza.message import Message
@ -154,7 +154,7 @@ class xep_0030(base.base_plugin):
self.xep = '0033' self.xep = '0033'
self.description = 'Extended Stanza Addressing' self.description = 'Extended Stanza Addressing'
self.xmpp.stanzaPlugin(Message, Addresses) registerStanzaPlugin(Message, Addresses)
def post_init(self): def post_init(self):
base.base_plugin.post_init(self) base.base_plugin.post_init(self)

View file

@ -21,7 +21,7 @@ from __future__ import with_statement
from . import base from . import base
import logging import logging
from xml.etree import cElementTree as ET from xml.etree import cElementTree as ET
from .. xmlstream.stanzabase import ElementBase, JID from .. xmlstream.stanzabase import registerStanzaPlugin, ElementBase, JID
from .. stanza.presence import Presence from .. stanza.presence import Presence
from .. xmlstream.handler.callback import Callback from .. xmlstream.handler.callback import Callback
from .. xmlstream.matcher.xpath import MatchXPath from .. xmlstream.matcher.xpath import MatchXPath
@ -125,7 +125,7 @@ class xep_0045(base.base_plugin):
self.xep = '0045' self.xep = '0045'
self.description = 'Multi User Chat' self.description = 'Multi User Chat'
# load MUC support in presence stanzas # load MUC support in presence stanzas
self.xmpp.stanzaPlugin(Presence, MUCPresence) registerStanzaPlugin(Presence, MUCPresence)
self.xmpp.registerHandler(Callback('MUCPresence', MatchXMLMask("<presence xmlns='%s' />" % self.xmpp.default_ns), self.handle_groupchat_presence)) self.xmpp.registerHandler(Callback('MUCPresence', MatchXMLMask("<presence xmlns='%s' />" % self.xmpp.default_ns), self.handle_groupchat_presence))
self.xmpp.registerHandler(Callback('MUCMessage', MatchXMLMask("<message xmlns='%s' type='groupchat'><body/></message>" % self.xmpp.default_ns), self.handle_groupchat_message)) self.xmpp.registerHandler(Callback('MUCMessage', MatchXMLMask("<message xmlns='%s' type='groupchat'><body/></message>" % self.xmpp.default_ns), self.handle_groupchat_message))

View file

@ -2,7 +2,7 @@ from __future__ import with_statement
from . import base from . import base
import logging import logging
#from xml.etree import cElementTree as ET #from xml.etree import cElementTree as ET
from .. xmlstream.stanzabase import ElementBase, ET from .. xmlstream.stanzabase import registerStanzaPlugin, ElementBase, ET
from . import stanza_pubsub from . import stanza_pubsub
class xep_0060(base.base_plugin): class xep_0060(base.base_plugin):

View file

@ -10,7 +10,7 @@ import logging
from . import base from . import base
from .. xmlstream.handler.callback import Callback from .. xmlstream.handler.callback import Callback
from .. xmlstream.matcher.xpath import MatchXPath from .. xmlstream.matcher.xpath import MatchXPath
from .. xmlstream.stanzabase import ElementBase, ET, JID from .. xmlstream.stanzabase import registerStanzaPlugin, ElementBase, ET, JID
from .. stanza.message import Message from .. stanza.message import Message
@ -85,11 +85,11 @@ class xep_0085(base.base_plugin):
handler[1])), handler[1])),
self._handleChatState)) self._handleChatState))
self.xmpp.stanzaPlugin(Message, Active) registerStanzaPlugin(Message, Active)
self.xmpp.stanzaPlugin(Message, Composing) registerStanzaPlugin(Message, Composing)
self.xmpp.stanzaPlugin(Message, Gone) registerStanzaPlugin(Message, Gone)
self.xmpp.stanzaPlugin(Message, Inactive) registerStanzaPlugin(Message, Inactive)
self.xmpp.stanzaPlugin(Message, Paused) registerStanzaPlugin(Message, Paused)
def post_init(self): def post_init(self):
base.base_plugin.post_init(self) base.base_plugin.post_init(self)

View file

@ -10,7 +10,7 @@ import logging
from . import base from . import base
from .. xmlstream.handler.callback import Callback from .. xmlstream.handler.callback import Callback
from .. xmlstream.matcher.xpath import MatchXPath from .. xmlstream.matcher.xpath import MatchXPath
from .. xmlstream.stanzabase import ElementBase, ET, JID from .. xmlstream.stanzabase import registerStanzaPlugin, ElementBase, ET, JID
from .. stanza.iq import Iq from .. stanza.iq import Iq
from . xep_0030 import DiscoInfo, DiscoItems from . xep_0030 import DiscoInfo, DiscoItems
from . alt_0004 import Form from . alt_0004 import Form
@ -25,8 +25,8 @@ class xep_0128(base.base_plugin):
self.xep = '0128' self.xep = '0128'
self.description = 'Service Discovery Extensions' self.description = 'Service Discovery Extensions'
self.xmpp.stanzaPlugin(DiscoInfo, Form) registerStanzaPlugin(DiscoInfo, Form)
self.xmpp.stanzaPlugin(DiscoItems, Form) registerStanzaPlugin(DiscoItems, Form)
def extend_info(self, node, data=None): def extend_info(self, node, data=None):
if data is None: if data is None:

View file

@ -1,4 +1,4 @@
from .. xmlstream.stanzabase import ElementBase, ET, JID from .. xmlstream.stanzabase import registerStanzaPlugin, ElementBase, ET, JID
from xml.etree import cElementTree as ET from xml.etree import cElementTree as ET
class AtomEntry(ElementBase): class AtomEntry(ElementBase):

View file

@ -5,7 +5,7 @@
See the file license.txt for copying permission. See the file license.txt for copying permission.
""" """
from .. xmlstream.stanzabase import ElementBase, ET from .. xmlstream.stanzabase import registerStanzaPlugin, ElementBase, ET
class Error(ElementBase): class Error(ElementBase):
namespace = 'jabber:client' namespace = 'jabber:client'

View file

@ -5,7 +5,7 @@
See the file license.txt for copying permission. See the file license.txt for copying permission.
""" """
from .. xmlstream.stanzabase import ElementBase, ET from .. xmlstream.stanzabase import registerStanzaPlugin, ElementBase, ET
class HTMLIM(ElementBase): class HTMLIM(ElementBase):
namespace = 'http://jabber.org/protocol/xhtml-im' namespace = 'http://jabber.org/protocol/xhtml-im'

View file

@ -5,7 +5,7 @@
See the file license.txt for copying permission. See the file license.txt for copying permission.
""" """
from .. xmlstream.stanzabase import ElementBase, ET from .. xmlstream.stanzabase import registerStanzaPlugin, ElementBase, ET
class Nick(ElementBase): class Nick(ElementBase):
namespace = 'http://jabber.org/nick/nick' namespace = 'http://jabber.org/nick/nick'

View file

@ -5,7 +5,7 @@
See the file license.txt for copying permission. See the file license.txt for copying permission.
""" """
from .. xmlstream.stanzabase import ElementBase, ET, JID from .. xmlstream.stanzabase import registerStanzaPlugin, ElementBase, ET, JID
import logging import logging
class Roster(ElementBase): class Roster(ElementBase):

View file

@ -19,6 +19,16 @@ else:
xmltester = type(ET.Element('xml')) xmltester = type(ET.Element('xml'))
def registerStanzaPlugin(stanza, plugin):
"""
Associate a stanza object as a plugin for another stanza.
"""
tag = "{%s}%s" % (plugin.namespace, plugin.name)
stanza.plugin_attrib_map[plugin.plugin_attrib] = plugin
stanza.plugin_tag_map[tag] = plugin
class JID(object): class JID(object):
def __init__(self, jid): def __init__(self, jid):
self.jid = jid self.jid = jid
@ -392,4 +402,4 @@ class StanzaBase(ElementBase):
def __copy__(self): def __copy__(self):
return self.__class__(xml=copy.deepcopy(self.xml), stream=self.stream) return self.__class__(xml=copy.deepcopy(self.xml), stream=self.stream)

View file

@ -17,6 +17,8 @@ from sleekxmpp import ClientXMPP
from sleekxmpp import Message, Iq from sleekxmpp import Message, Iq
from sleekxmpp.stanza.presence import Presence from sleekxmpp.stanza.presence import Presence
from sleekxmpp.xmlstream.matcher.stanzapath import StanzaPath from sleekxmpp.xmlstream.matcher.stanzapath import StanzaPath
from sleekxmpp.xmlstream.stanzabase import registerStanzaPlugin
class TestSocket(object): class TestSocket(object):
@ -88,14 +90,6 @@ class SleekTest(unittest.TestCase):
methods for comparing message, iq, and presence stanzas. methods for comparing message, iq, and presence stanzas.
""" """
def stanzaPlugin(self, stanza, plugin):
"""
Associate a stanza object as a plugin for another stanza.
"""
tag = "{%s}%s" % (plugin.namespace, plugin.name)
stanza.plugin_attrib_map[plugin.plugin_attrib] = plugin
stanza.plugin_tag_map[tag] = plugin
# ------------------------------------------------------------------ # ------------------------------------------------------------------
# Shortcut methods for creating stanza objects # Shortcut methods for creating stanza objects

View file

@ -5,7 +5,7 @@ import sleekxmpp.plugins.xep_0033 as xep_0033
class TestAddresses(SleekTest): class TestAddresses(SleekTest):
def setUp(self): def setUp(self):
self.stanzaPlugin(Message, xep_0033.Addresses) registerStanzaPlugin(Message, xep_0033.Addresses)
def testAddAddress(self): def testAddAddress(self):
"""Testing adding extended stanza address.""" """Testing adding extended stanza address."""

View file

@ -4,11 +4,11 @@ import sleekxmpp.plugins.xep_0085 as xep_0085
class TestChatStates(SleekTest): class TestChatStates(SleekTest):
def setUp(self): def setUp(self):
self.stanzaPlugin(Message, xep_0085.Active) registerStanzaPlugin(Message, xep_0085.Active)
self.stanzaPlugin(Message, xep_0085.Composing) registerStanzaPlugin(Message, xep_0085.Composing)
self.stanzaPlugin(Message, xep_0085.Gone) registerStanzaPlugin(Message, xep_0085.Gone)
self.stanzaPlugin(Message, xep_0085.Inactive) registerStanzaPlugin(Message, xep_0085.Inactive)
self.stanzaPlugin(Message, xep_0085.Paused) registerStanzaPlugin(Message, xep_0085.Paused)
def testCreateChatState(self): def testCreateChatState(self):
"""Testing creating chat states.""" """Testing creating chat states."""

View file

@ -5,8 +5,8 @@ import sleekxmpp.plugins.xep_0030 as xep_0030
class TestDisco(SleekTest): class TestDisco(SleekTest):
def setUp(self): def setUp(self):
self.stanzaPlugin(Iq, xep_0030.DiscoInfo) registerStanzaPlugin(Iq, xep_0030.DiscoInfo)
self.stanzaPlugin(Iq, xep_0030.DiscoItems) registerStanzaPlugin(Iq, xep_0030.DiscoItems)
def testCreateInfoQueryNoNode(self): def testCreateInfoQueryNoNode(self):
"""Testing disco#info query with no node.""" """Testing disco#info query with no node."""

View file

@ -5,9 +5,9 @@ import sleekxmpp.plugins.alt_0004 as xep_0004
class TestDataForms(SleekTest): class TestDataForms(SleekTest):
def setUp(self): def setUp(self):
self.stanzaPlugin(Message, xep_0004.Form) registerStanzaPlugin(Message, xep_0004.Form)
self.stanzaPlugin(xep_0004.Form, xep_0004.FormField) registerStanzaPlugin(xep_0004.Form, xep_0004.FormField)
self.stanzaPlugin(xep_0004.FormField, xep_0004.FieldOption) registerStanzaPlugin(xep_0004.FormField, xep_0004.FieldOption)
def testMultipleInstructions(self): def testMultipleInstructions(self):
"""Testing using multiple instructions elements in a data form.""" """Testing using multiple instructions elements in a data form."""

View file

@ -5,9 +5,9 @@ import sleekxmpp.plugins.gmail_notify as gmail
class TestGmail(SleekTest): class TestGmail(SleekTest):
def setUp(self): def setUp(self):
self.stanzaPlugin(Iq, gmail.GmailQuery) registerStanzaPlugin(Iq, gmail.GmailQuery)
self.stanzaPlugin(Iq, gmail.MailBox) registerStanzaPlugin(Iq, gmail.MailBox)
self.stanzaPlugin(Iq, gmail.NewMail) registerStanzaPlugin(Iq, gmail.NewMail)
def testCreateQuery(self): def testCreateQuery(self):
"""Testing querying Gmail for emails.""" """Testing querying Gmail for emails."""

View file

@ -5,9 +5,9 @@ class testmessagestanzas(unittest.TestCase):
def setUp(self): def setUp(self):
import sleekxmpp.stanza.message as m import sleekxmpp.stanza.message as m
from sleekxmpp.basexmpp import stanzaPlugin from sleekxmpp.basexmpp import registerStanzaPlugin
from sleekxmpp.stanza.htmlim import HTMLIM from sleekxmpp.stanza.htmlim import HTMLIM
stanzaPlugin(m.Message, HTMLIM) registerStanzaPlugin(m.Message, HTMLIM)
self.m = m self.m = m
def testGroupchatReplyRegression(self): def testGroupchatReplyRegression(self):