mirror of
https://github.com/correl/SleekXMPP.git
synced 2024-11-27 11:09:56 +00:00
Clean up pubsub stanzas.
This commit is contained in:
parent
462b375c8f
commit
8471a485d1
1 changed files with 74 additions and 109 deletions
|
@ -1,9 +1,13 @@
|
||||||
from sleekxmpp.xmlstream.stanzabase import registerStanzaPlugin, ElementBase, ET, JID
|
"""
|
||||||
from sleekxmpp.stanza.iq import Iq
|
SleekXMPP: The Sleek XMPP Library
|
||||||
from sleekxmpp.stanza.message import Message
|
Copyright (C) 2011 Nathanael C. Fritz
|
||||||
from sleekxmpp.basexmpp import basexmpp
|
This file is part of SleekXMPP.
|
||||||
from sleekxmpp.xmlstream.xmlstream import XMLStream
|
|
||||||
import logging
|
See the file LICENSE for copying permission.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from sleekxmpp import Iq, Message
|
||||||
|
from sleekxmpp.xmlstream import register_stanza_plugin, ElementBase, ET, JID
|
||||||
from sleekxmpp.plugins import xep_0004
|
from sleekxmpp.plugins import xep_0004
|
||||||
from sleekxmpp.plugins.xep_0060.stanza.base import OptionalSetting
|
from sleekxmpp.plugins.xep_0060.stanza.base import OptionalSetting
|
||||||
|
|
||||||
|
@ -13,10 +17,13 @@ class Pubsub(ElementBase):
|
||||||
name = 'pubsub'
|
name = 'pubsub'
|
||||||
plugin_attrib = 'pubsub'
|
plugin_attrib = 'pubsub'
|
||||||
interfaces = set(tuple())
|
interfaces = set(tuple())
|
||||||
plugin_attrib_map = {}
|
|
||||||
plugin_tag_map = {}
|
|
||||||
|
|
||||||
registerStanzaPlugin(Iq, Pubsub)
|
|
||||||
|
class Affiliations(ElementBase):
|
||||||
|
namespace = 'http://jabber.org/protocol/pubsub'
|
||||||
|
name = 'affiliations'
|
||||||
|
plugin_attrib = 'affiliations'
|
||||||
|
interfaces = set(('node',))
|
||||||
|
|
||||||
|
|
||||||
class Affiliation(ElementBase):
|
class Affiliation(ElementBase):
|
||||||
|
@ -24,25 +31,12 @@ class Affiliation(ElementBase):
|
||||||
name = 'affiliation'
|
name = 'affiliation'
|
||||||
plugin_attrib = name
|
plugin_attrib = name
|
||||||
interfaces = set(('node', 'affiliation', 'jid'))
|
interfaces = set(('node', 'affiliation', 'jid'))
|
||||||
plugin_attrib_map = {}
|
|
||||||
plugin_tag_map = {}
|
|
||||||
|
|
||||||
def setJid(self, value):
|
def set_jid(self, value):
|
||||||
self._setAttr('jid', str(value))
|
self._set_attr('jid', str(value))
|
||||||
|
|
||||||
def getJid(self):
|
def get_jid(self):
|
||||||
return JID(self._getAttr('jid'))
|
return JID(self._get_attr('jid'))
|
||||||
|
|
||||||
class Affiliations(ElementBase):
|
|
||||||
namespace = 'http://jabber.org/protocol/pubsub'
|
|
||||||
name = 'affiliations'
|
|
||||||
plugin_attrib = 'affiliations'
|
|
||||||
interfaces = set(('node',))
|
|
||||||
plugin_attrib_map = {}
|
|
||||||
plugin_tag_map = {}
|
|
||||||
subitem = (Affiliation,)
|
|
||||||
|
|
||||||
registerStanzaPlugin(Pubsub, Affiliations)
|
|
||||||
|
|
||||||
|
|
||||||
class Subscription(ElementBase):
|
class Subscription(ElementBase):
|
||||||
|
@ -50,57 +44,44 @@ class Subscription(ElementBase):
|
||||||
name = 'subscription'
|
name = 'subscription'
|
||||||
plugin_attrib = name
|
plugin_attrib = name
|
||||||
interfaces = set(('jid', 'node', 'subscription', 'subid'))
|
interfaces = set(('jid', 'node', 'subscription', 'subid'))
|
||||||
plugin_attrib_map = {}
|
|
||||||
plugin_tag_map = {}
|
|
||||||
|
|
||||||
def setjid(self, value):
|
def set_jid(self, value):
|
||||||
self._setattr('jid', str(value))
|
self._set_attr('jid', str(value))
|
||||||
|
|
||||||
def getjid(self):
|
def get_jid(self):
|
||||||
return jid(self._getattr('jid'))
|
return JID(self._get_attr('jid'))
|
||||||
|
|
||||||
registerStanzaPlugin(Pubsub, Subscription)
|
|
||||||
|
|
||||||
class Subscriptions(ElementBase):
|
class Subscriptions(ElementBase):
|
||||||
namespace = 'http://jabber.org/protocol/pubsub'
|
namespace = 'http://jabber.org/protocol/pubsub'
|
||||||
name = 'subscriptions'
|
name = 'subscriptions'
|
||||||
plugin_attrib = 'subscriptions'
|
plugin_attrib = 'subscriptions'
|
||||||
interfaces = set(('node',))
|
interfaces = set(('node',))
|
||||||
plugin_attrib_map = {}
|
|
||||||
plugin_tag_map = {}
|
|
||||||
subitem = (Subscription,)
|
|
||||||
|
|
||||||
registerStanzaPlugin(Pubsub, Subscriptions)
|
|
||||||
|
|
||||||
|
|
||||||
class SubscribeOptions(ElementBase, OptionalSetting):
|
class SubscribeOptions(ElementBase, OptionalSetting):
|
||||||
namespace = 'http://jabber.org/protocol/pubsub'
|
namespace = 'http://jabber.org/protocol/pubsub'
|
||||||
name = 'subscribe-options'
|
name = 'subscribe-options'
|
||||||
plugin_attrib = 'suboptions'
|
plugin_attrib = 'suboptions'
|
||||||
plugin_attrib_map = {}
|
|
||||||
plugin_tag_map = {}
|
|
||||||
interfaces = set(('required',))
|
interfaces = set(('required',))
|
||||||
|
|
||||||
registerStanzaPlugin(Subscription, SubscribeOptions)
|
|
||||||
|
|
||||||
class Item(ElementBase):
|
class Item(ElementBase):
|
||||||
namespace = 'http://jabber.org/protocol/pubsub'
|
namespace = 'http://jabber.org/protocol/pubsub'
|
||||||
name = 'item'
|
name = 'item'
|
||||||
plugin_attrib = name
|
plugin_attrib = name
|
||||||
interfaces = set(('id', 'payload'))
|
interfaces = set(('id', 'payload'))
|
||||||
plugin_attrib_map = {}
|
|
||||||
plugin_tag_map = {}
|
|
||||||
|
|
||||||
def setPayload(self, value):
|
def set_payload(self, value):
|
||||||
del self['payload']
|
del self['payload']
|
||||||
self.append(value)
|
self.append(value)
|
||||||
|
|
||||||
def getPayload(self):
|
def get_payload(self):
|
||||||
childs = self.xml.getchildren()
|
childs = self.xml.getchildren()
|
||||||
if len(childs) > 0:
|
if len(childs) > 0:
|
||||||
return childs[0]
|
return childs[0]
|
||||||
|
|
||||||
def delPayload(self):
|
def del_payload(self):
|
||||||
for child in self.xml.getchildren():
|
for child in self.xml.getchildren():
|
||||||
self.xml.remove(child)
|
self.xml.remove(child)
|
||||||
|
|
||||||
|
@ -109,143 +90,111 @@ class Items(ElementBase):
|
||||||
name = 'items'
|
name = 'items'
|
||||||
plugin_attrib = 'items'
|
plugin_attrib = 'items'
|
||||||
interfaces = set(('node', 'max_items'))
|
interfaces = set(('node', 'max_items'))
|
||||||
plugin_attrib_map = {}
|
|
||||||
plugin_tag_map = {}
|
|
||||||
subitem = (Item,)
|
|
||||||
|
|
||||||
def set_max_items(self, value):
|
def set_max_items(self, value):
|
||||||
self._set_attr('max_items', str(value))
|
self._set_attr('max_items', str(value))
|
||||||
|
|
||||||
registerStanzaPlugin(Pubsub, Items)
|
|
||||||
|
|
||||||
class Create(ElementBase):
|
class Create(ElementBase):
|
||||||
namespace = 'http://jabber.org/protocol/pubsub'
|
namespace = 'http://jabber.org/protocol/pubsub'
|
||||||
name = 'create'
|
name = 'create'
|
||||||
plugin_attrib = name
|
plugin_attrib = name
|
||||||
interfaces = set(('node',))
|
interfaces = set(('node',))
|
||||||
plugin_attrib_map = {}
|
|
||||||
plugin_tag_map = {}
|
|
||||||
|
|
||||||
registerStanzaPlugin(Pubsub, Create)
|
|
||||||
|
|
||||||
#class Default(ElementBase):
|
#class Default(ElementBase):
|
||||||
# namespace = 'http://jabber.org/protocol/pubsub'
|
# namespace = 'http://jabber.org/protocol/pubsub'
|
||||||
# name = 'default'
|
# name = 'default'
|
||||||
# plugin_attrib = name
|
# plugin_attrib = name
|
||||||
# interfaces = set(('node', 'type'))
|
# interfaces = set(('node', 'type'))
|
||||||
# plugin_attrib_map = {}
|
|
||||||
# plugin_tag_map = {}
|
|
||||||
#
|
#
|
||||||
# def getType(self):
|
# def getType(self):
|
||||||
# t = self._getAttr('type')
|
# t = self._get_attr('type')
|
||||||
# if not t: t == 'leaf'
|
# if not t: t == 'leaf'
|
||||||
# return t
|
# return t
|
||||||
#
|
#
|
||||||
#registerStanzaPlugin(Pubsub, Default)
|
#register_stanza_plugin(Pubsub, Default)
|
||||||
|
|
||||||
class Publish(ElementBase):
|
class Publish(ElementBase):
|
||||||
namespace = 'http://jabber.org/protocol/pubsub'
|
namespace = 'http://jabber.org/protocol/pubsub'
|
||||||
name = 'publish'
|
name = 'publish'
|
||||||
plugin_attrib = name
|
plugin_attrib = name
|
||||||
interfaces = set(('node',))
|
interfaces = set(('node',))
|
||||||
plugin_attrib_map = {}
|
|
||||||
plugin_tag_map = {}
|
|
||||||
subitem = (Item,)
|
|
||||||
|
|
||||||
registerStanzaPlugin(Pubsub, Publish)
|
|
||||||
registerStanzaPlugin(Publish, Item)
|
|
||||||
|
|
||||||
class Retract(ElementBase):
|
class Retract(ElementBase):
|
||||||
namespace = 'http://jabber.org/protocol/pubsub'
|
namespace = 'http://jabber.org/protocol/pubsub'
|
||||||
name = 'retract'
|
name = 'retract'
|
||||||
plugin_attrib = name
|
plugin_attrib = name
|
||||||
interfaces = set(('node', 'notify'))
|
interfaces = set(('node', 'notify'))
|
||||||
plugin_attrib_map = {}
|
|
||||||
plugin_tag_map = {}
|
|
||||||
|
|
||||||
registerStanzaPlugin(Pubsub, Retract)
|
|
||||||
registerStanzaPlugin(Retract, Item)
|
|
||||||
|
|
||||||
class Unsubscribe(ElementBase):
|
class Unsubscribe(ElementBase):
|
||||||
namespace = 'http://jabber.org/protocol/pubsub'
|
namespace = 'http://jabber.org/protocol/pubsub'
|
||||||
name = 'unsubscribe'
|
name = 'unsubscribe'
|
||||||
plugin_attrib = name
|
plugin_attrib = name
|
||||||
interfaces = set(('node', 'jid', 'subid'))
|
interfaces = set(('node', 'jid', 'subid'))
|
||||||
plugin_attrib_map = {}
|
|
||||||
plugin_tag_map = {}
|
|
||||||
|
|
||||||
def setJid(self, value):
|
def set_jid(self, value):
|
||||||
self._setAttr('jid', str(value))
|
self._set_attr('jid', str(value))
|
||||||
|
|
||||||
def getJid(self):
|
def get_jid(self):
|
||||||
return JID(self._getAttr('jid'))
|
return JID(self._get_attr('jid'))
|
||||||
|
|
||||||
registerStanzaPlugin(Pubsub, Unsubscribe)
|
|
||||||
|
|
||||||
class Subscribe(ElementBase):
|
class Subscribe(ElementBase):
|
||||||
namespace = 'http://jabber.org/protocol/pubsub'
|
namespace = 'http://jabber.org/protocol/pubsub'
|
||||||
name = 'subscribe'
|
name = 'subscribe'
|
||||||
plugin_attrib = name
|
plugin_attrib = name
|
||||||
interfaces = set(('node', 'jid'))
|
interfaces = set(('node', 'jid'))
|
||||||
plugin_attrib_map = {}
|
|
||||||
plugin_tag_map = {}
|
|
||||||
|
|
||||||
def setJid(self, value):
|
def set_jid(self, value):
|
||||||
self._setAttr('jid', str(value))
|
self._set_attr('jid', str(value))
|
||||||
|
|
||||||
def getJid(self):
|
def get_jid(self):
|
||||||
return JID(self._getAttr('jid'))
|
return JID(self._get_attr('jid'))
|
||||||
|
|
||||||
registerStanzaPlugin(Pubsub, Subscribe)
|
|
||||||
|
|
||||||
class Configure(ElementBase):
|
class Configure(ElementBase):
|
||||||
namespace = 'http://jabber.org/protocol/pubsub'
|
namespace = 'http://jabber.org/protocol/pubsub'
|
||||||
name = 'configure'
|
name = 'configure'
|
||||||
plugin_attrib = name
|
plugin_attrib = name
|
||||||
interfaces = set(('node', 'type'))
|
interfaces = set(('node', 'type'))
|
||||||
plugin_attrib_map = {}
|
|
||||||
plugin_tag_map = {}
|
|
||||||
|
|
||||||
def getType(self):
|
def getType(self):
|
||||||
t = self._getAttr('type')
|
t = self._get_attr('type')
|
||||||
if not t: t == 'leaf'
|
if not t: t == 'leaf'
|
||||||
return t
|
return t
|
||||||
|
|
||||||
registerStanzaPlugin(Pubsub, Configure)
|
|
||||||
registerStanzaPlugin(Configure, xep_0004.Form)
|
|
||||||
|
|
||||||
class Options(ElementBase):
|
class Options(ElementBase):
|
||||||
namespace = 'http://jabber.org/protocol/pubsub'
|
namespace = 'http://jabber.org/protocol/pubsub'
|
||||||
name = 'options'
|
name = 'options'
|
||||||
plugin_attrib = 'options'
|
plugin_attrib = 'options'
|
||||||
interfaces = set(('jid', 'node', 'options'))
|
interfaces = set(('jid', 'node', 'options'))
|
||||||
plugin_attrib_map = {}
|
|
||||||
plugin_tag_map = {}
|
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
ElementBase.__init__(self, *args, **kwargs)
|
ElementBase.__init__(self, *args, **kwargs)
|
||||||
|
|
||||||
def getOptions(self):
|
def get_options(self):
|
||||||
config = self.xml.find('{jabber:x:data}x')
|
config = self.xml.find('{jabber:x:data}x')
|
||||||
form = xep_0004.Form(xml=config)
|
form = xep_0004.Form(xml=config)
|
||||||
return form
|
return form
|
||||||
|
|
||||||
def setOptions(self, value):
|
def set_options(self, value):
|
||||||
self.xml.append(value.getXML())
|
self.xml.append(value.getXML())
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def delOptions(self):
|
def del_options(self):
|
||||||
config = self.xml.find('{jabber:x:data}x')
|
config = self.xml.find('{jabber:x:data}x')
|
||||||
self.xml.remove(config)
|
self.xml.remove(config)
|
||||||
|
|
||||||
def setJid(self, value):
|
def set_jid(self, value):
|
||||||
self._setAttr('jid', str(value))
|
self._set_attr('jid', str(value))
|
||||||
|
|
||||||
def getJid(self):
|
def get_jid(self):
|
||||||
return JID(self._getAttr('jid'))
|
return JID(self._get_attr('jid'))
|
||||||
|
|
||||||
registerStanzaPlugin(Pubsub, Options)
|
|
||||||
registerStanzaPlugin(Subscribe, Options)
|
|
||||||
|
|
||||||
class PublishOptions(ElementBase):
|
class PublishOptions(ElementBase):
|
||||||
namespace = 'http://jabber.org/protocol/pubsub'
|
namespace = 'http://jabber.org/protocol/pubsub'
|
||||||
|
@ -253,8 +202,6 @@ class PublishOptions(ElementBase):
|
||||||
plugin_attrib = 'publish_options'
|
plugin_attrib = 'publish_options'
|
||||||
interfaces = set(('publish_options',))
|
interfaces = set(('publish_options',))
|
||||||
is_extension = True
|
is_extension = True
|
||||||
plugin_attrib_map = {}
|
|
||||||
plugin_tag_map = {}
|
|
||||||
|
|
||||||
def get_publish_options(self):
|
def get_publish_options(self):
|
||||||
config = self.xml.find('{jabber:x:data}x')
|
config = self.xml.find('{jabber:x:data}x')
|
||||||
|
@ -276,37 +223,55 @@ class PublishOptions(ElementBase):
|
||||||
self.xml.remove(config)
|
self.xml.remove(config)
|
||||||
self.parent().xml.remove(self.xml)
|
self.parent().xml.remove(self.xml)
|
||||||
|
|
||||||
registerStanzaPlugin(Pubsub, PublishOptions)
|
|
||||||
|
|
||||||
class PubsubState(ElementBase):
|
class PubsubState(ElementBase):
|
||||||
namespace = 'http://jabber.org/protocol/psstate'
|
namespace = 'http://jabber.org/protocol/psstate'
|
||||||
name = 'state'
|
name = 'state'
|
||||||
plugin_attrib = 'psstate'
|
plugin_attrib = 'psstate'
|
||||||
interfaces = set(('node', 'item', 'payload'))
|
interfaces = set(('node', 'item', 'payload'))
|
||||||
plugin_attrib_map = {}
|
|
||||||
plugin_tag_map = {}
|
|
||||||
|
|
||||||
def setPayload(self, value):
|
def set_payload(self, value):
|
||||||
self.xml.append(value)
|
self.xml.append(value)
|
||||||
|
|
||||||
def getPayload(self):
|
def get_payload(self):
|
||||||
childs = self.xml.getchildren()
|
childs = self.xml.getchildren()
|
||||||
if len(childs) > 0:
|
if len(childs) > 0:
|
||||||
return childs[0]
|
return childs[0]
|
||||||
|
|
||||||
def delPayload(self):
|
def del_payload(self):
|
||||||
for child in self.xml.getchildren():
|
for child in self.xml.getchildren():
|
||||||
self.xml.remove(child)
|
self.xml.remove(child)
|
||||||
|
|
||||||
registerStanzaPlugin(Iq, PubsubState)
|
|
||||||
|
|
||||||
class PubsubStateEvent(ElementBase):
|
class PubsubStateEvent(ElementBase):
|
||||||
namespace = 'http://jabber.org/protocol/psstate#event'
|
namespace = 'http://jabber.org/protocol/psstate#event'
|
||||||
name = 'event'
|
name = 'event'
|
||||||
plugin_attrib = 'psstate_event'
|
plugin_attrib = 'psstate_event'
|
||||||
intefaces = set(tuple())
|
intefaces = set(tuple())
|
||||||
plugin_attrib_map = {}
|
|
||||||
plugin_tag_map = {}
|
|
||||||
|
|
||||||
registerStanzaPlugin(Message, PubsubStateEvent)
|
|
||||||
registerStanzaPlugin(PubsubStateEvent, PubsubState)
|
register_stanza_plugin(Iq, Pubsub)
|
||||||
|
register_stanza_plugin(Pubsub, Affiliations)
|
||||||
|
register_stanza_plugin(Pubsub, Configure)
|
||||||
|
register_stanza_plugin(Pubsub, Create)
|
||||||
|
register_stanza_plugin(Pubsub, Items)
|
||||||
|
register_stanza_plugin(Pubsub, Options)
|
||||||
|
register_stanza_plugin(Pubsub, Publish)
|
||||||
|
register_stanza_plugin(Pubsub, PublishOptions)
|
||||||
|
register_stanza_plugin(Pubsub, Retract)
|
||||||
|
register_stanza_plugin(Pubsub, Subscribe)
|
||||||
|
register_stanza_plugin(Pubsub, Subscription)
|
||||||
|
register_stanza_plugin(Pubsub, Subscriptions)
|
||||||
|
register_stanza_plugin(Pubsub, Unsubscribe)
|
||||||
|
register_stanza_plugin(Affiliations, Affiliation, iterable=True)
|
||||||
|
register_stanza_plugin(Configure, xep_0004.Form)
|
||||||
|
register_stanza_plugin(Items, Item, iterable=True)
|
||||||
|
register_stanza_plugin(Publish, Item, iterable=True)
|
||||||
|
register_stanza_plugin(Retract, Item)
|
||||||
|
register_stanza_plugin(Subscribe, Options)
|
||||||
|
register_stanza_plugin(Subscription, SubscribeOptions)
|
||||||
|
register_stanza_plugin(Subscriptions, Subscription, iterable=True)
|
||||||
|
|
||||||
|
register_stanza_plugin(Message, PubsubStateEvent)
|
||||||
|
register_stanza_plugin(Iq, PubsubState)
|
||||||
|
register_stanza_plugin(PubsubStateEvent, PubsubState)
|
||||||
|
|
Loading…
Reference in a new issue