summaryrefslogtreecommitdiff
path: root/sleekxmpp/plugins/xep_0060
diff options
context:
space:
mode:
authorLance Stout <lancestout@gmail.com>2011-08-31 00:40:33 -0700
committerLance Stout <lancestout@gmail.com>2011-08-31 00:42:37 -0700
commit5ec4e4a026a5f3a3ec9c2cb6efd3dc1a4ccf580f (patch)
tree6daa500d5778ad3cc46c7e39841c4f1e82a39796 /sleekxmpp/plugins/xep_0060
parentc3df4dd0520a758837e8d9c51d408efc4d8e6a28 (diff)
downloadslixmpp-5ec4e4a026a5f3a3ec9c2cb6efd3dc1a4ccf580f.tar.gz
slixmpp-5ec4e4a026a5f3a3ec9c2cb6efd3dc1a4ccf580f.tar.bz2
slixmpp-5ec4e4a026a5f3a3ec9c2cb6efd3dc1a4ccf580f.tar.xz
slixmpp-5ec4e4a026a5f3a3ec9c2cb6efd3dc1a4ccf580f.zip
Added pubsub error stanza.
iq['error']['pubsub']['condition'] iq['error']['pubsub']['unsupported']
Diffstat (limited to 'sleekxmpp/plugins/xep_0060')
-rw-r--r--sleekxmpp/plugins/xep_0060/stanza/__init__.py1
-rw-r--r--sleekxmpp/plugins/xep_0060/stanza/pubsub_errors.py86
2 files changed, 87 insertions, 0 deletions
diff --git a/sleekxmpp/plugins/xep_0060/stanza/__init__.py b/sleekxmpp/plugins/xep_0060/stanza/__init__.py
index d7cd91a8..e3faf6a8 100644
--- a/sleekxmpp/plugins/xep_0060/stanza/__init__.py
+++ b/sleekxmpp/plugins/xep_0060/stanza/__init__.py
@@ -1,3 +1,4 @@
from sleekxmpp.plugins.xep_0060.stanza.pubsub import Pubsub, Affiliation, Affiliations, Subscription, Subscriptions, SubscribeOptions, Item, Items, Create, Publish, Retract, Unsubscribe, Subscribe, Configure, Options, PubsubState, PubsubStateEvent
from sleekxmpp.plugins.xep_0060.stanza.pubsub_owner import PubsubOwner, DefaultConfig, OwnerAffiliations, OwnerAffiliation, OwnerConfigure, OwnerDefault, OwnerDelete, OwnerPurge, OwnerRedirect, OwnerSubscriptions, OwnerSubscription
from sleekxmpp.plugins.xep_0060.stanza.pubsub_event import Event, EventItem, EventRetract, EventItems, EventCollection, EventAssociate, EventDisassociate, EventConfiguration, EventPurge, EventSubscription
+from sleekxmpp.plugins.xep_0060.stanza.pubsub_errors import PubsubErrorCondition
diff --git a/sleekxmpp/plugins/xep_0060/stanza/pubsub_errors.py b/sleekxmpp/plugins/xep_0060/stanza/pubsub_errors.py
new file mode 100644
index 00000000..46374a35
--- /dev/null
+++ b/sleekxmpp/plugins/xep_0060/stanza/pubsub_errors.py
@@ -0,0 +1,86 @@
+"""
+ 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.stanza import Error
+from sleekxmpp.xmlstream import ElementBase, ET, register_stanza_plugin
+
+
+class PubsubErrorCondition(ElementBase):
+
+ plugin_attrib = 'pubsub'
+ interfaces = set(('condition', 'unsupported'))
+ plugin_attrib_map = {}
+ plugin_tag_map = {}
+ conditions = set(('closed-node', 'configuration-required', 'invalid-jid',
+ 'invalid-options', 'invalid-payload', 'invalid-subid',
+ 'item-forbidden', 'item-required', 'jid-required',
+ 'max-items-exceeded', 'max-nodes-exceeded',
+ 'nodeid-required', 'not-in-roster-group',
+ 'not-subscribed', 'payload-too-big',
+ 'payload-required' 'pending-subscription',
+ 'presence-subscription-required', 'subid-required',
+ 'too-many-subscriptions', 'unsupported'))
+ condition_ns = 'http://jabber.org/protocol/pubsub#errors'
+
+ def setup(self, xml):
+ """Don't create XML for the plugin."""
+ self.xml = ET.Element('')
+
+ def get_condition(self):
+ """Return the condition element's name."""
+ for child in self.parent().xml.getchildren():
+ if "{%s}" % self.condition_ns in child.tag:
+ cond = child.tag.split('}', 1)[-1]
+ if cond in self.conditions:
+ return cond
+ return ''
+
+ def set_condition(self, value):
+ """
+ Set the tag name of the condition element.
+
+ Arguments:
+ value -- The tag name of the condition element.
+ """
+ if value in self.conditions:
+ del self['condition']
+ cond = ET.Element("{%s}%s" % (self.condition_ns, value))
+ self.parent().xml.append(cond)
+ return self
+
+ def del_condition(self):
+ """Remove the condition element."""
+ for child in self.parent().xml.getchildren():
+ if "{%s}" % self.condition_ns in child.tag:
+ tag = child.tag.split('}', 1)[-1]
+ if tag in self.conditions:
+ self.parent().xml.remove(child)
+ return self
+
+ def get_unsupported(self):
+ """Return the name of an unsupported feature"""
+ xml = self.parent().xml.find('{%s}unsupported' % self.condition_ns)
+ if xml is not None:
+ return xml.attrib.get('feature', '')
+ return ''
+
+ def set_unsupported(self, value):
+ """Mark a feature as unsupported"""
+ self.del_unsupported()
+ xml = ET.Element('{%s}unsupported' % self.condition_ns)
+ xml.attrib['feature'] = value
+ self.parent().xml.append(xml)
+
+ def del_unsupported(self):
+ """Delete an unsupported feature condition."""
+ xml = self.parent().xml.find('{%s}unsupported' % self.condition_ns)
+ if xml is not None:
+ self.parent().xml.remove(xml)
+
+
+register_stanza_plugin(Error, PubsubErrorCondition)