2010-03-26 21:32:16 +00:00
|
|
|
"""
|
|
|
|
SleekXMPP: The Sleek XMPP Library
|
|
|
|
Copyright (C) 2010 Nathanael C. Fritz
|
|
|
|
This file is part of SleekXMPP.
|
|
|
|
|
|
|
|
See the file license.txt for copying permission.
|
|
|
|
"""
|
2009-12-15 04:37:10 +00:00
|
|
|
from .. xmlstream.stanzabase import ElementBase, ET
|
|
|
|
|
|
|
|
class Error(ElementBase):
|
|
|
|
namespace = 'jabber:client'
|
|
|
|
name = 'error'
|
|
|
|
plugin_attrib = 'error'
|
|
|
|
conditions = set(('bad-request', 'conflict', 'feature-not-implemented', 'forbidden', 'gone', 'item-not-found', 'jid-malformed', 'not-acceptable', 'not-allowed', 'not-authorized', 'payment-required', 'recipient-unavailable', 'redirect', 'registration-required', 'remote-server-not-found', 'remote-server-timeout', 'service-unavailable', 'subscription-required', 'undefined-condition', 'unexpected-request'))
|
2010-05-22 14:39:35 +00:00
|
|
|
interfaces = set(('code', 'condition', 'text', 'type'))
|
2009-12-15 04:37:10 +00:00
|
|
|
types = set(('cancel', 'continue', 'modify', 'auth', 'wait'))
|
|
|
|
sub_interfaces = set(('text',))
|
|
|
|
condition_ns = 'urn:ietf:params:xml:ns:xmpp-stanzas'
|
|
|
|
|
|
|
|
def setup(self, xml=None):
|
|
|
|
if ElementBase.setup(self, xml): #if we had to generate xml
|
|
|
|
self['type'] = 'cancel'
|
|
|
|
self['condition'] = 'feature-not-implemented'
|
|
|
|
if self.parent is not None:
|
2010-05-12 20:45:36 +00:00
|
|
|
self.parent()['type'] = 'error'
|
2009-12-15 04:37:10 +00:00
|
|
|
|
|
|
|
def getCondition(self):
|
|
|
|
for child in self.xml.getchildren():
|
|
|
|
if "{%s}" % self.condition_ns in child.tag:
|
|
|
|
return child.tag.split('}', 1)[-1]
|
|
|
|
return ''
|
|
|
|
|
|
|
|
def setCondition(self, value):
|
|
|
|
if value in self.conditions:
|
|
|
|
for child in self.xml.getchildren():
|
|
|
|
if "{%s}" % self.condition_ns in child.tag:
|
|
|
|
self.xml.remove(child)
|
|
|
|
condition = ET.Element("{%s}%s" % (self.condition_ns, value))
|
|
|
|
self.xml.append(condition)
|
|
|
|
return self
|
|
|
|
|
|
|
|
def delCondition(self):
|
|
|
|
return self
|
|
|
|
|
|
|
|
def getText(self):
|
|
|
|
text = ''
|
|
|
|
textxml = self.xml.find("{urn:ietf:params:xml:ns:xmpp-stanzas}text")
|
|
|
|
if textxml is not None:
|
|
|
|
text = textxml.text
|
|
|
|
return text
|
|
|
|
|
|
|
|
def setText(self, value):
|
|
|
|
self.delText()
|
|
|
|
textxml = ET.Element('{urn:ietf:params:xml:ns:xmpp-stanzas}text')
|
|
|
|
textxml.text = value
|
|
|
|
self.xml.append(textxml)
|
|
|
|
return self
|
|
|
|
|
|
|
|
def delText(self):
|
|
|
|
textxml = self.xml.find("{urn:ietf:params:xml:ns:xmpp-stanzas}text")
|
|
|
|
if textxml is not None:
|
|
|
|
self.xml.remove(textxml)
|