summaryrefslogtreecommitdiff
path: root/sleekxmpp/stanza/error.py
blob: 4cb7310a0c53bb8c80834746d485c4d1113f0725 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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'))
	interfaces = set(('condition', 'text', 'type'))
	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:
			self.parent['type'] = 'error'
	
	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)