2011-09-01 21:01:58 +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.
|
|
|
|
"""
|
|
|
|
|
2012-03-17 06:16:17 +00:00
|
|
|
import datetime as dt
|
|
|
|
|
2011-09-01 21:01:58 +00:00
|
|
|
from sleekxmpp import Message
|
|
|
|
from sleekxmpp.xmlstream import register_stanza_plugin, ElementBase, ET, JID
|
|
|
|
from sleekxmpp.plugins.xep_0004 import Form
|
2012-03-17 06:16:17 +00:00
|
|
|
from sleekxmpp.plugins import xep_0082
|
2011-09-01 21:01:58 +00:00
|
|
|
|
2011-08-04 06:56:24 +00:00
|
|
|
|
|
|
|
class Event(ElementBase):
|
2011-09-01 21:01:58 +00:00
|
|
|
namespace = 'http://jabber.org/protocol/pubsub#event'
|
|
|
|
name = 'event'
|
|
|
|
plugin_attrib = 'pubsub_event'
|
2012-03-10 08:07:15 +00:00
|
|
|
interfaces = set()
|
2011-08-04 06:56:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
class EventItem(ElementBase):
|
2011-09-01 21:01:58 +00:00
|
|
|
namespace = 'http://jabber.org/protocol/pubsub#event'
|
|
|
|
name = 'item'
|
|
|
|
plugin_attrib = name
|
2012-03-10 08:07:15 +00:00
|
|
|
interfaces = set(('id', 'payload', 'node', 'publisher'))
|
2011-09-01 21:01:58 +00:00
|
|
|
|
|
|
|
def set_payload(self, value):
|
|
|
|
self.xml.append(value)
|
|
|
|
|
|
|
|
def get_payload(self):
|
|
|
|
childs = self.xml.getchildren()
|
|
|
|
if len(childs) > 0:
|
|
|
|
return childs[0]
|
|
|
|
|
|
|
|
def del_payload(self):
|
|
|
|
for child in self.xml.getchildren():
|
|
|
|
self.xml.remove(child)
|
2011-08-04 06:56:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
class EventRetract(ElementBase):
|
2011-09-01 21:01:58 +00:00
|
|
|
namespace = 'http://jabber.org/protocol/pubsub#event'
|
|
|
|
name = 'retract'
|
|
|
|
plugin_attrib = name
|
|
|
|
interfaces = set(('id',))
|
|
|
|
|
2011-08-04 06:56:24 +00:00
|
|
|
|
|
|
|
class EventItems(ElementBase):
|
2011-09-01 21:01:58 +00:00
|
|
|
namespace = 'http://jabber.org/protocol/pubsub#event'
|
|
|
|
name = 'items'
|
|
|
|
plugin_attrib = name
|
|
|
|
interfaces = set(('node',))
|
2011-08-04 06:56:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
class EventCollection(ElementBase):
|
2011-09-01 21:01:58 +00:00
|
|
|
namespace = 'http://jabber.org/protocol/pubsub#event'
|
|
|
|
name = 'collection'
|
|
|
|
plugin_attrib = name
|
|
|
|
interfaces = set(('node',))
|
2011-08-04 06:56:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
class EventAssociate(ElementBase):
|
2011-09-01 21:01:58 +00:00
|
|
|
namespace = 'http://jabber.org/protocol/pubsub#event'
|
|
|
|
name = 'associate'
|
|
|
|
plugin_attrib = name
|
|
|
|
interfaces = set(('node',))
|
2011-08-04 06:56:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
class EventDisassociate(ElementBase):
|
2011-09-01 21:01:58 +00:00
|
|
|
namespace = 'http://jabber.org/protocol/pubsub#event'
|
|
|
|
name = 'disassociate'
|
|
|
|
plugin_attrib = name
|
|
|
|
interfaces = set(('node',))
|
2011-08-04 06:56:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
class EventConfiguration(ElementBase):
|
2011-09-01 21:01:58 +00:00
|
|
|
namespace = 'http://jabber.org/protocol/pubsub#event'
|
|
|
|
name = 'configuration'
|
|
|
|
plugin_attrib = name
|
2012-03-10 08:07:15 +00:00
|
|
|
interfaces = set(('node',))
|
2011-09-01 21:01:58 +00:00
|
|
|
|
2011-08-04 06:56:24 +00:00
|
|
|
|
|
|
|
class EventPurge(ElementBase):
|
2011-09-01 21:01:58 +00:00
|
|
|
namespace = 'http://jabber.org/protocol/pubsub#event'
|
|
|
|
name = 'purge'
|
|
|
|
plugin_attrib = name
|
|
|
|
interfaces = set(('node',))
|
2011-08-04 06:56:24 +00:00
|
|
|
|
|
|
|
|
2012-03-10 08:07:15 +00:00
|
|
|
class EventDelete(ElementBase):
|
|
|
|
namespace = 'http://jabber.org/protocol/pubsub#event'
|
|
|
|
name = 'delete'
|
|
|
|
plugin_attrib = name
|
|
|
|
interfaces = set(('node', 'redirect'))
|
|
|
|
|
|
|
|
def set_redirect(self, uri):
|
|
|
|
del self['redirect']
|
|
|
|
redirect = ET.Element('{%s}redirect' % self.namespace)
|
|
|
|
redirect.attrib['uri'] = uri
|
|
|
|
self.xml.append(redirect)
|
2012-03-12 04:37:13 +00:00
|
|
|
|
2012-03-10 08:07:15 +00:00
|
|
|
def get_redirect(self):
|
|
|
|
redirect = self.xml.find('{%s}redirect' % self.namespace)
|
|
|
|
if redirect is not None:
|
|
|
|
return redirect.attrib.get('uri', '')
|
|
|
|
return ''
|
|
|
|
|
|
|
|
def del_redirect(self):
|
|
|
|
redirect = self.xml.find('{%s}redirect' % self.namespace)
|
|
|
|
if redirect is not None:
|
|
|
|
self.xml.remove(redirect)
|
|
|
|
|
|
|
|
|
2011-08-04 06:56:24 +00:00
|
|
|
class EventSubscription(ElementBase):
|
2011-09-01 21:01:58 +00:00
|
|
|
namespace = 'http://jabber.org/protocol/pubsub#event'
|
|
|
|
name = 'subscription'
|
|
|
|
plugin_attrib = name
|
|
|
|
interfaces = set(('node', 'expiry', 'jid', 'subid', 'subscription'))
|
|
|
|
|
2012-03-17 06:16:17 +00:00
|
|
|
def get_expiry(self):
|
|
|
|
expiry = self._get_attr('expiry')
|
|
|
|
return xep_0082.parse(expiry)
|
|
|
|
|
|
|
|
def set_expiry(self, value):
|
|
|
|
if isinstance(value, dt.datetime):
|
|
|
|
value = xep_0082.format_datetime(value)
|
|
|
|
self._set_attr('expiry', value)
|
|
|
|
|
2011-09-01 21:01:58 +00:00
|
|
|
def set_jid(self, value):
|
|
|
|
self._set_attr('jid', str(value))
|
|
|
|
|
|
|
|
def get_jid(self):
|
|
|
|
return JID(self._get_attr('jid'))
|
|
|
|
|
|
|
|
|
|
|
|
register_stanza_plugin(Message, Event)
|
|
|
|
register_stanza_plugin(Event, EventCollection)
|
|
|
|
register_stanza_plugin(Event, EventConfiguration)
|
|
|
|
register_stanza_plugin(Event, EventPurge)
|
2012-03-10 08:07:15 +00:00
|
|
|
register_stanza_plugin(Event, EventDelete)
|
|
|
|
register_stanza_plugin(Event, EventItems)
|
2011-09-01 21:01:58 +00:00
|
|
|
register_stanza_plugin(Event, EventSubscription)
|
|
|
|
register_stanza_plugin(EventCollection, EventAssociate)
|
|
|
|
register_stanza_plugin(EventCollection, EventDisassociate)
|
|
|
|
register_stanza_plugin(EventConfiguration, Form)
|
|
|
|
register_stanza_plugin(EventItems, EventItem, iterable=True)
|
|
|
|
register_stanza_plugin(EventItems, EventRetract, iterable=True)
|