2011-09-01 20:11:05 +00:00
|
|
|
"""
|
|
|
|
SleekXMPP: The Sleek XMPP Library
|
|
|
|
Copyright (C) 2011 Nathanael C. Fritz
|
|
|
|
This file is part of SleekXMPP.
|
|
|
|
|
|
|
|
See the file LICENSE for copying permission.
|
|
|
|
"""
|
|
|
|
|
|
|
|
from sleekxmpp import Iq, Message
|
|
|
|
from sleekxmpp.xmlstream import register_stanza_plugin, ElementBase, ET, JID
|
2011-08-04 06:56:24 +00:00
|
|
|
from sleekxmpp.plugins import xep_0004
|
2011-08-04 18:38:14 +00:00
|
|
|
from sleekxmpp.plugins.xep_0060.stanza.base import OptionalSetting
|
2011-08-04 06:56:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Pubsub(ElementBase):
|
2011-08-12 23:35:36 +00:00
|
|
|
namespace = 'http://jabber.org/protocol/pubsub'
|
|
|
|
name = 'pubsub'
|
2011-09-01 21:03:11 +00:00
|
|
|
plugin_attrib = name
|
2011-08-12 23:35:36 +00:00
|
|
|
interfaces = set(tuple())
|
2011-08-04 06:56:24 +00:00
|
|
|
|
2011-09-01 20:11:05 +00:00
|
|
|
|
|
|
|
class Affiliations(ElementBase):
|
|
|
|
namespace = 'http://jabber.org/protocol/pubsub'
|
|
|
|
name = 'affiliations'
|
2011-09-01 21:03:11 +00:00
|
|
|
plugin_attrib = name
|
2011-09-01 20:11:05 +00:00
|
|
|
interfaces = set(('node',))
|
2011-08-04 06:56:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Affiliation(ElementBase):
|
2011-08-12 23:35:36 +00:00
|
|
|
namespace = 'http://jabber.org/protocol/pubsub'
|
|
|
|
name = 'affiliation'
|
|
|
|
plugin_attrib = name
|
|
|
|
interfaces = set(('node', 'affiliation', 'jid'))
|
2011-08-30 06:05:14 +00:00
|
|
|
|
2011-09-01 20:11:05 +00:00
|
|
|
def set_jid(self, value):
|
|
|
|
self._set_attr('jid', str(value))
|
2011-08-12 23:32:09 +00:00
|
|
|
|
2011-09-01 20:11:05 +00:00
|
|
|
def get_jid(self):
|
|
|
|
return JID(self._get_attr('jid'))
|
2011-08-04 06:56:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Subscription(ElementBase):
|
2011-08-12 23:35:36 +00:00
|
|
|
namespace = 'http://jabber.org/protocol/pubsub'
|
|
|
|
name = 'subscription'
|
|
|
|
plugin_attrib = name
|
|
|
|
interfaces = set(('jid', 'node', 'subscription', 'subid'))
|
2011-08-04 06:56:24 +00:00
|
|
|
|
2011-09-01 20:11:05 +00:00
|
|
|
def set_jid(self, value):
|
|
|
|
self._set_attr('jid', str(value))
|
2011-08-04 18:38:14 +00:00
|
|
|
|
2011-09-01 20:11:05 +00:00
|
|
|
def get_jid(self):
|
|
|
|
return JID(self._get_attr('jid'))
|
2011-08-04 06:56:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Subscriptions(ElementBase):
|
2011-08-12 23:35:36 +00:00
|
|
|
namespace = 'http://jabber.org/protocol/pubsub'
|
|
|
|
name = 'subscriptions'
|
2011-09-01 21:03:11 +00:00
|
|
|
plugin_attrib = name
|
2011-09-01 18:19:25 +00:00
|
|
|
interfaces = set(('node',))
|
2011-08-04 06:56:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
class SubscribeOptions(ElementBase, OptionalSetting):
|
2011-08-12 23:35:36 +00:00
|
|
|
namespace = 'http://jabber.org/protocol/pubsub'
|
|
|
|
name = 'subscribe-options'
|
|
|
|
plugin_attrib = 'suboptions'
|
|
|
|
interfaces = set(('required',))
|
2011-08-04 06:56:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Item(ElementBase):
|
2011-08-12 23:35:36 +00:00
|
|
|
namespace = 'http://jabber.org/protocol/pubsub'
|
|
|
|
name = 'item'
|
|
|
|
plugin_attrib = name
|
|
|
|
interfaces = set(('id', 'payload'))
|
2011-08-04 06:56:24 +00:00
|
|
|
|
2011-09-01 20:11:05 +00:00
|
|
|
def set_payload(self, value):
|
2011-08-31 21:31:20 +00:00
|
|
|
del self['payload']
|
|
|
|
self.append(value)
|
2011-08-04 18:38:14 +00:00
|
|
|
|
2011-09-01 20:11:05 +00:00
|
|
|
def get_payload(self):
|
2012-06-19 16:47:31 +00:00
|
|
|
childs = list(self.xml)
|
2011-08-12 23:35:36 +00:00
|
|
|
if len(childs) > 0:
|
|
|
|
return childs[0]
|
2011-08-04 18:38:14 +00:00
|
|
|
|
2011-09-01 20:11:05 +00:00
|
|
|
def del_payload(self):
|
2012-06-19 16:47:31 +00:00
|
|
|
for child in self.xml:
|
2011-08-12 23:35:36 +00:00
|
|
|
self.xml.remove(child)
|
2011-08-04 06:56:24 +00:00
|
|
|
|
2011-09-01 20:25:35 +00:00
|
|
|
|
2011-08-04 06:56:24 +00:00
|
|
|
class Items(ElementBase):
|
2011-08-12 23:35:36 +00:00
|
|
|
namespace = 'http://jabber.org/protocol/pubsub'
|
|
|
|
name = 'items'
|
2011-09-01 21:03:11 +00:00
|
|
|
plugin_attrib = name
|
2011-08-30 06:05:14 +00:00
|
|
|
interfaces = set(('node', 'max_items'))
|
2011-08-04 06:56:24 +00:00
|
|
|
|
2011-09-01 16:27:10 +00:00
|
|
|
def set_max_items(self, value):
|
|
|
|
self._set_attr('max_items', str(value))
|
|
|
|
|
2011-08-04 06:56:24 +00:00
|
|
|
|
|
|
|
class Create(ElementBase):
|
2011-08-12 23:35:36 +00:00
|
|
|
namespace = 'http://jabber.org/protocol/pubsub'
|
|
|
|
name = 'create'
|
|
|
|
plugin_attrib = name
|
|
|
|
interfaces = set(('node',))
|
2011-08-04 06:56:24 +00:00
|
|
|
|
|
|
|
|
2011-09-01 20:25:35 +00:00
|
|
|
class Default(ElementBase):
|
|
|
|
namespace = 'http://jabber.org/protocol/pubsub'
|
|
|
|
name = 'default'
|
|
|
|
plugin_attrib = name
|
|
|
|
interfaces = set(('node', 'type'))
|
|
|
|
|
|
|
|
def get_type(self):
|
|
|
|
t = self._get_attr('type')
|
|
|
|
if not t:
|
|
|
|
return 'leaf'
|
|
|
|
return t
|
|
|
|
|
2011-08-04 06:56:24 +00:00
|
|
|
|
2011-09-01 06:48:22 +00:00
|
|
|
class Publish(ElementBase):
|
2011-08-12 23:35:36 +00:00
|
|
|
namespace = 'http://jabber.org/protocol/pubsub'
|
|
|
|
name = 'publish'
|
|
|
|
plugin_attrib = name
|
|
|
|
interfaces = set(('node',))
|
2011-08-04 06:56:24 +00:00
|
|
|
|
|
|
|
|
2011-08-31 23:03:32 +00:00
|
|
|
class Retract(ElementBase):
|
2011-08-12 23:35:36 +00:00
|
|
|
namespace = 'http://jabber.org/protocol/pubsub'
|
|
|
|
name = 'retract'
|
|
|
|
plugin_attrib = name
|
|
|
|
interfaces = set(('node', 'notify'))
|
2011-08-04 06:56:24 +00:00
|
|
|
|
2011-09-01 20:36:11 +00:00
|
|
|
def get_notify(self):
|
|
|
|
notify = self._get_attr('notify')
|
|
|
|
if notify in ('0', 'false'):
|
|
|
|
return False
|
|
|
|
elif notify in ('1', 'true'):
|
|
|
|
return True
|
|
|
|
return None
|
|
|
|
|
|
|
|
def set_notify(self, value):
|
|
|
|
del self['notify']
|
|
|
|
if value is None:
|
|
|
|
return
|
|
|
|
elif value in (True, '1', 'true', 'True'):
|
|
|
|
self._set_attr('notify', 'true')
|
|
|
|
else:
|
|
|
|
self._set_attr('notify', 'false')
|
|
|
|
|
2011-08-04 06:56:24 +00:00
|
|
|
|
|
|
|
class Unsubscribe(ElementBase):
|
2011-08-12 23:35:36 +00:00
|
|
|
namespace = 'http://jabber.org/protocol/pubsub'
|
|
|
|
name = 'unsubscribe'
|
|
|
|
plugin_attrib = name
|
|
|
|
interfaces = set(('node', 'jid', 'subid'))
|
2011-08-04 18:38:14 +00:00
|
|
|
|
2011-09-01 20:11:05 +00:00
|
|
|
def set_jid(self, value):
|
|
|
|
self._set_attr('jid', str(value))
|
2011-08-04 18:38:14 +00:00
|
|
|
|
2011-09-01 20:11:05 +00:00
|
|
|
def get_jid(self):
|
|
|
|
return JID(self._get_attr('jid'))
|
2011-08-04 06:56:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Subscribe(ElementBase):
|
2011-08-12 23:35:36 +00:00
|
|
|
namespace = 'http://jabber.org/protocol/pubsub'
|
|
|
|
name = 'subscribe'
|
|
|
|
plugin_attrib = name
|
|
|
|
interfaces = set(('node', 'jid'))
|
2011-08-04 06:56:24 +00:00
|
|
|
|
2011-09-01 20:11:05 +00:00
|
|
|
def set_jid(self, value):
|
|
|
|
self._set_attr('jid', str(value))
|
2011-08-04 18:38:14 +00:00
|
|
|
|
2011-09-01 20:11:05 +00:00
|
|
|
def get_jid(self):
|
|
|
|
return JID(self._get_attr('jid'))
|
2011-08-04 06:56:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Configure(ElementBase):
|
2011-08-12 23:35:36 +00:00
|
|
|
namespace = 'http://jabber.org/protocol/pubsub'
|
|
|
|
name = 'configure'
|
|
|
|
plugin_attrib = name
|
|
|
|
interfaces = set(('node', 'type'))
|
|
|
|
|
|
|
|
def getType(self):
|
2011-09-01 20:11:05 +00:00
|
|
|
t = self._get_attr('type')
|
2011-09-01 20:25:35 +00:00
|
|
|
if not t:
|
|
|
|
t == 'leaf'
|
2011-08-12 23:35:36 +00:00
|
|
|
return t
|
2011-08-04 18:38:14 +00:00
|
|
|
|
2011-08-04 06:56:24 +00:00
|
|
|
|
|
|
|
class Options(ElementBase):
|
2011-08-12 23:35:36 +00:00
|
|
|
namespace = 'http://jabber.org/protocol/pubsub'
|
|
|
|
name = 'options'
|
2011-09-01 21:03:11 +00:00
|
|
|
plugin_attrib = name
|
2011-08-12 23:35:36 +00:00
|
|
|
interfaces = set(('jid', 'node', 'options'))
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
ElementBase.__init__(self, *args, **kwargs)
|
|
|
|
|
2011-09-01 20:11:05 +00:00
|
|
|
def get_options(self):
|
2011-08-12 23:35:36 +00:00
|
|
|
config = self.xml.find('{jabber:x:data}x')
|
2011-08-31 06:10:13 +00:00
|
|
|
form = xep_0004.Form(xml=config)
|
2011-08-12 23:35:36 +00:00
|
|
|
return form
|
|
|
|
|
2011-09-01 20:11:05 +00:00
|
|
|
def set_options(self, value):
|
2011-08-12 23:35:36 +00:00
|
|
|
self.xml.append(value.getXML())
|
|
|
|
return self
|
|
|
|
|
2011-09-01 20:11:05 +00:00
|
|
|
def del_options(self):
|
2011-08-12 23:35:36 +00:00
|
|
|
config = self.xml.find('{jabber:x:data}x')
|
|
|
|
self.xml.remove(config)
|
|
|
|
|
2011-09-01 20:11:05 +00:00
|
|
|
def set_jid(self, value):
|
|
|
|
self._set_attr('jid', str(value))
|
2011-08-12 23:35:36 +00:00
|
|
|
|
2011-09-01 20:11:05 +00:00
|
|
|
def get_jid(self):
|
|
|
|
return JID(self._get_attr('jid'))
|
2011-08-04 06:56:24 +00:00
|
|
|
|
|
|
|
|
2011-08-31 05:44:19 +00:00
|
|
|
class PublishOptions(ElementBase):
|
|
|
|
namespace = 'http://jabber.org/protocol/pubsub'
|
|
|
|
name = 'publish-options'
|
|
|
|
plugin_attrib = 'publish_options'
|
2011-08-31 06:03:04 +00:00
|
|
|
interfaces = set(('publish_options',))
|
|
|
|
is_extension = True
|
2011-08-31 05:44:19 +00:00
|
|
|
|
|
|
|
def get_publish_options(self):
|
|
|
|
config = self.xml.find('{jabber:x:data}x')
|
2011-08-31 23:03:32 +00:00
|
|
|
if config is None:
|
|
|
|
return None
|
2011-08-31 06:10:13 +00:00
|
|
|
form = xep_0004.Form(xml=config)
|
2011-08-31 05:44:19 +00:00
|
|
|
return form
|
|
|
|
|
|
|
|
def set_publish_options(self, value):
|
2011-08-31 21:55:37 +00:00
|
|
|
if value is None:
|
2011-08-31 23:03:32 +00:00
|
|
|
self.del_publish_options()
|
2011-08-31 21:55:37 +00:00
|
|
|
else:
|
|
|
|
self.xml.append(value.getXML())
|
2011-08-31 05:44:19 +00:00
|
|
|
return self
|
|
|
|
|
|
|
|
def del_publish_options(self):
|
|
|
|
config = self.xml.find('{jabber:x:data}x')
|
2011-08-31 21:55:37 +00:00
|
|
|
if config is not None:
|
|
|
|
self.xml.remove(config)
|
2011-08-31 23:03:32 +00:00
|
|
|
self.parent().xml.remove(self.xml)
|
2011-08-31 05:44:19 +00:00
|
|
|
|
|
|
|
|
2011-08-04 06:56:24 +00:00
|
|
|
class PubsubState(ElementBase):
|
2011-09-01 22:29:05 +00:00
|
|
|
"""This is an experimental pubsub extension."""
|
2011-08-04 06:56:24 +00:00
|
|
|
namespace = 'http://jabber.org/protocol/psstate'
|
|
|
|
name = 'state'
|
|
|
|
plugin_attrib = 'psstate'
|
|
|
|
interfaces = set(('node', 'item', 'payload'))
|
2011-08-04 18:38:14 +00:00
|
|
|
|
2011-09-01 20:11:05 +00:00
|
|
|
def set_payload(self, value):
|
2011-08-04 06:56:24 +00:00
|
|
|
self.xml.append(value)
|
2011-08-04 18:38:14 +00:00
|
|
|
|
2011-09-01 20:11:05 +00:00
|
|
|
def get_payload(self):
|
2012-06-19 16:47:31 +00:00
|
|
|
childs = list(self.xml)
|
2011-08-04 06:56:24 +00:00
|
|
|
if len(childs) > 0:
|
|
|
|
return childs[0]
|
2011-08-04 18:38:14 +00:00
|
|
|
|
2011-09-01 20:11:05 +00:00
|
|
|
def del_payload(self):
|
2012-06-19 16:47:31 +00:00
|
|
|
for child in self.xml:
|
2011-08-04 06:56:24 +00:00
|
|
|
self.xml.remove(child)
|
|
|
|
|
|
|
|
|
|
|
|
class PubsubStateEvent(ElementBase):
|
2011-09-01 22:29:05 +00:00
|
|
|
"""This is an experimental pubsub extension."""
|
2011-08-04 06:56:24 +00:00
|
|
|
namespace = 'http://jabber.org/protocol/psstate#event'
|
|
|
|
name = 'event'
|
|
|
|
plugin_attrib = 'psstate_event'
|
|
|
|
intefaces = set(tuple())
|
|
|
|
|
2011-09-01 20:11:05 +00:00
|
|
|
|
2011-09-01 20:36:11 +00:00
|
|
|
register_stanza_plugin(Iq, PubsubState)
|
|
|
|
register_stanza_plugin(Message, PubsubStateEvent)
|
|
|
|
register_stanza_plugin(PubsubStateEvent, PubsubState)
|
|
|
|
|
|
|
|
|
2011-09-01 20:11:05 +00:00
|
|
|
register_stanza_plugin(Iq, Pubsub)
|
|
|
|
register_stanza_plugin(Pubsub, Affiliations)
|
|
|
|
register_stanza_plugin(Pubsub, Configure)
|
|
|
|
register_stanza_plugin(Pubsub, Create)
|
2011-09-01 20:25:35 +00:00
|
|
|
register_stanza_plugin(Pubsub, Default)
|
2011-09-01 20:11:05 +00:00
|
|
|
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)
|