summaryrefslogtreecommitdiff
path: root/sleekxmpp/stanza/rootstanza.py
diff options
context:
space:
mode:
authorNathan Fritz <fritzy@netflint.net>2010-01-05 21:56:48 +0000
committerNathan Fritz <fritzy@netflint.net>2010-01-05 21:56:48 +0000
commit093644ffbd6708121150c92359bce60408f924bb (patch)
treea7d6da57ff76a8e54b1ec3703aeffeed82f34fa1 /sleekxmpp/stanza/rootstanza.py
parent805afa4bc1f44598d786fddc92c5129c62464227 (diff)
downloadslixmpp-093644ffbd6708121150c92359bce60408f924bb.tar.gz
slixmpp-093644ffbd6708121150c92359bce60408f924bb.tar.bz2
slixmpp-093644ffbd6708121150c92359bce60408f924bb.tar.xz
slixmpp-093644ffbd6708121150c92359bce60408f924bb.zip
* major stanza improvements
* raise XMPPError in handler to reply with error stanza * started work on pubsub stanzas
Diffstat (limited to 'sleekxmpp/stanza/rootstanza.py')
-rw-r--r--sleekxmpp/stanza/rootstanza.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/sleekxmpp/stanza/rootstanza.py b/sleekxmpp/stanza/rootstanza.py
new file mode 100644
index 00000000..72ba5ca9
--- /dev/null
+++ b/sleekxmpp/stanza/rootstanza.py
@@ -0,0 +1,25 @@
+from .. xmlstream.stanzabase import StanzaBase
+from xml.etree import cElementTree as ET
+from . error import Error
+from .. exceptions import XMPPError
+import traceback
+
+class RootStanza(StanzaBase):
+
+ def exception(self, e): #called when a handler raises an exception
+ self.reply()
+ if isinstance(e, XMPPError): # we raised this deliberately
+ self['error']['condition'] = e.condition
+ self['error']['text'] = e.text
+ if e.extension is not None: # extended error tag
+ extxml = ET.Element("{%s}%s" % (e.extension_ns, e.extension), e.extension_args)
+ self['error'].xml.append(extxml)
+ self['error']['type'] = e.etype
+ else: # we probably didn't raise this on purpose, so send back a traceback
+ self['error']['condition'] = 'undefined-condition'
+ self['error']['text'] = traceback.format_tb(e.__traceback__)
+ self.send()
+
+# all jabber:client root stanzas should have the error plugin
+RootStanza.plugin_attrib_map['error'] = Error
+RootStanza.plugin_tag_map["{%s}%s" % (Error.namespace, Error.name)] = Error