summaryrefslogtreecommitdiff
path: root/sleekxmpp/plugins/stanza_pubsub.py
diff options
context:
space:
mode:
authorNathan Fritz <fritz@netflint.net>2010-01-13 09:04:05 -0800
committerNathan Fritz <fritz@netflint.net>2010-01-13 09:04:05 -0800
commit6e1aa0690f4c2bcc1031aed05305ef84f36fbb57 (patch)
treee9536281f035071b8c0cb6126c04ea8b072a075b /sleekxmpp/plugins/stanza_pubsub.py
parentd14045f5a6eec370f0374b1e7dab6eb58bc70d48 (diff)
downloadslixmpp-6e1aa0690f4c2bcc1031aed05305ef84f36fbb57.tar.gz
slixmpp-6e1aa0690f4c2bcc1031aed05305ef84f36fbb57.tar.bz2
slixmpp-6e1aa0690f4c2bcc1031aed05305ef84f36fbb57.tar.xz
slixmpp-6e1aa0690f4c2bcc1031aed05305ef84f36fbb57.zip
Completed basic test coverage of xmlns http://jabber.org/protocol/pubsub stanzas
Diffstat (limited to 'sleekxmpp/plugins/stanza_pubsub.py')
-rw-r--r--sleekxmpp/plugins/stanza_pubsub.py135
1 files changed, 55 insertions, 80 deletions
diff --git a/sleekxmpp/plugins/stanza_pubsub.py b/sleekxmpp/plugins/stanza_pubsub.py
index 9bae7c94..900f3c82 100644
--- a/sleekxmpp/plugins/stanza_pubsub.py
+++ b/sleekxmpp/plugins/stanza_pubsub.py
@@ -51,9 +51,25 @@ class Affiliations(ElementBase):
self.xml.append(affiliation.xml)
return self.iterables.append(affiliation)
-
stanzaPlugin(Pubsub, Affiliations)
+
+class Subscription(ElementBase):
+ namespace = 'http://jabber.org/protocol/pubsub'
+ name = 'subscription'
+ plugin_attrib = name
+ interfaces = set(('jid', 'node', 'subscription'))
+ plugin_attrib_map = {}
+ plugin_tag_map = {}
+
+ def setJid(self, value):
+ self._setAttr('jid', str(value))
+
+ def getJid(self):
+ return JID(self._getAttr('jid'))
+
+stanzaPlugin(Pubsub, Subscription)
+
class Subscriptions(ElementBase):
namespace = 'http://jabber.org/protocol/pubsub'
name = 'subscriptions'
@@ -61,6 +77,7 @@ class Subscriptions(ElementBase):
interfaces = set(tuple())
plugin_attrib_map = {}
plugin_tag_map = {}
+ subitem = Subscription
def __init__(self, *args, **kwargs):
ElementBase.__init__(self, *args, **kwargs)
@@ -97,25 +114,8 @@ class Subscriptions(ElementBase):
stanzaPlugin(Pubsub, Subscriptions)
-
-class Subscription(ElementBase):
- namespace = 'http://jabber.org/protocol/pubsub'
- name = 'subscription'
- plugin_attrib = name
- interfaces = set(('jid', 'node', 'subid', 'subscription'))
- plugin_attrib_map = {}
- plugin_tag_map = {}
-
- def setJid(self, value):
- self._setAttr('jid', str(value))
-
- def getJid(self):
- return JID(self._getAttr('from'))
-
-stanzaPlugin(Pubsub, Subscription)
-
class OptionalSetting(object):
- interfaces = set(('required'))
+ interfaces = set(('required',))
def setRequired(self, value):
value = bool(value)
@@ -140,55 +140,13 @@ class OptionalSetting(object):
class SubscribeOptions(ElementBase, OptionalSetting):
namespace = 'http://jabber.org/protocol/pubsub'
name = 'subscribe-options'
- plugin_attrib = 'options'
+ plugin_attrib = 'suboptions'
plugin_attrib_map = {}
plugin_tag_map = {}
+ interfaces = set(('required',))
stanzaPlugin(Subscription, SubscribeOptions)
-class Items(ElementBase):
- namespace = 'http://jabber.org/protocol/pubsub'
- name = 'items'
- plugin_attrib = 'items'
- interfaces = set(tuple())
- plugin_attrib_map = {}
- plugin_tag_map = {}
-
- def __init__(self, *args, **kwargs):
- ElementBase.__init__(self, *args, **kwargs)
- self.items = []
- self.idx = 0
-
- def __iter__(self):
- self.idx = 0
- return self
-
- def __next__(self):
- self.idx += 1
- if self.idx + 1 > len(self.items):
- self.idx = 0
- raise StopIteration
- return self.items[self.idx]
-
- def __len__(self):
- return len(self.items)
-
- def append(self, item):
- if not isinstance(item, Item):
- raise TypeError
- self.xml.append(item.xml)
- return self.items.append(item)
-
- def pop(self, idx=0):
- aff = self.items.pop(idx)
- self.xml.remove(aff.xml)
- return aff
-
- def find(self, item):
- return self.items.find(item)
-
-stanzaPlugin(Pubsub, Items)
-
class Item(ElementBase):
namespace = 'http://jabber.org/protocol/pubsub'
name = 'item'
@@ -209,30 +167,41 @@ class Item(ElementBase):
for child in self.xml.getchildren():
self.xml.remove(child)
-class Create(ElementBase):
+class Items(ElementBase):
namespace = 'http://jabber.org/protocol/pubsub'
- name = 'create'
- plugin_attrib = name
- interfaces = set(('node'))
+ name = 'items'
+ plugin_attrib = 'items'
+ interfaces = set(tuple())
plugin_attrib_map = {}
plugin_tag_map = {}
+ subitem = Item
-stanzaPlugin(Pubsub, Create)
+stanzaPlugin(Pubsub, Items)
-class Default(ElementBase):
+class Create(ElementBase):
namespace = 'http://jabber.org/protocol/pubsub'
- name = 'default'
+ name = 'create'
plugin_attrib = name
- interfaces = set(('node', 'type'))
+ interfaces = set(('node',))
plugin_attrib_map = {}
plugin_tag_map = {}
- def getType(self):
- t = self._getAttr('type')
- if not t: t == 'leaf'
- return t
+stanzaPlugin(Pubsub, Create)
-stanzaPlugin(Pubsub, Default)
+#class Default(ElementBase):
+# namespace = 'http://jabber.org/protocol/pubsub'
+# name = 'default'
+# plugin_attrib = name
+# interfaces = set(('node', 'type'))
+# plugin_attrib_map = {}
+# plugin_tag_map = {}
+#
+# def getType(self):
+# t = self._getAttr('type')
+# if not t: t == 'leaf'
+# return t
+#
+#stanzaPlugin(Pubsub, Default)
class Publish(Items):
namespace = 'http://jabber.org/protocol/pubsub'
@@ -280,7 +249,7 @@ class Subscribe(ElementBase):
self._setAttr('jid', str(value))
def getJid(self):
- return JID(self._getAttr('from'))
+ return JID(self._getAttr('jid'))
stanzaPlugin(Pubsub, Subscribe)
@@ -313,11 +282,12 @@ class Configure(ElementBase):
self.xml.remove(config)
stanzaPlugin(Pubsub, Configure)
+stanzaPlugin(Create, Configure)
class DefaultConfig(ElementBase):
namespace = 'http://jabber.org/protocol/pubsub'
name = 'default'
- plugin_attrib = 'defaultconfig'
+ plugin_attrib = 'default'
interfaces = set(('node', 'type', 'config'))
plugin_attrib_map = {}
plugin_tag_map = {}
@@ -340,6 +310,11 @@ class DefaultConfig(ElementBase):
config = self.xml.find('{jabber:x:data}x')
self.xml.remove(config)
+ def getType(self):
+ t = self._getAttr('type')
+ if not t: t == 'leaf'
+ return t
+
stanzaPlugin(Pubsub, DefaultConfig)
class Options(ElementBase):
@@ -372,10 +347,10 @@ class Options(ElementBase):
self._setAttr('jid', str(value))
def getJid(self):
- return JID(self._getAttr('from'))
+ return JID(self._getAttr('jid'))
stanzaPlugin(Pubsub, Options)
-
+stanzaPlugin(Subscribe, Options)
#iq = Iq()
#iq['pubsub']['defaultconfig']