summaryrefslogtreecommitdiff
path: root/sleekxmpp/stanza/rootstanza.py
diff options
context:
space:
mode:
authorNathan Fritz <nathan@andyet.net>2010-08-19 16:09:47 -0700
committerNathan Fritz <nathan@andyet.net>2010-08-19 16:09:47 -0700
commitd150b35464742de7af9b3105bc7eeb55171b96ee (patch)
treef1dce9115efbe4c85d37bc27d6ae35f1e937a043 /sleekxmpp/stanza/rootstanza.py
parent21b7109c06695955632692814fed11b3717e0fc7 (diff)
parente4240dd593207a5912de996c42451b3946f113b2 (diff)
downloadslixmpp-d150b35464742de7af9b3105bc7eeb55171b96ee.tar.gz
slixmpp-d150b35464742de7af9b3105bc7eeb55171b96ee.tar.bz2
slixmpp-d150b35464742de7af9b3105bc7eeb55171b96ee.tar.xz
slixmpp-d150b35464742de7af9b3105bc7eeb55171b96ee.zip
fixed todo merge
Diffstat (limited to 'sleekxmpp/stanza/rootstanza.py')
-rw-r--r--sleekxmpp/stanza/rootstanza.py80
1 files changed, 55 insertions, 25 deletions
diff --git a/sleekxmpp/stanza/rootstanza.py b/sleekxmpp/stanza/rootstanza.py
index 3b4822d8..eafc79a2 100644
--- a/sleekxmpp/stanza/rootstanza.py
+++ b/sleekxmpp/stanza/rootstanza.py
@@ -3,34 +3,64 @@
Copyright (C) 2010 Nathanael C. Fritz
This file is part of SleekXMPP.
- See the file license.txt for copying permission.
+ See the file LICENSE for copying permission.
"""
-from .. xmlstream.stanzabase import StanzaBase
-from xml.etree import cElementTree as ET
-from . error import Error
-from .. exceptions import XMPPError
+
+import logging
import traceback
import sys
+from sleekxmpp.exceptions import XMPPError
+from sleekxmpp.stanza import Error
+from sleekxmpp.xmlstream.stanzabase import ET, StanzaBase, registerStanzaPlugin
+
+
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'
- if sys.version_info < (3,0):
- self['error']['text'] = "SleekXMPP got into trouble."
- else:
- 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
+ """
+ A top-level XMPP stanza in an XMLStream.
+
+ The RootStanza class provides a more XMPP specific exception
+ handler than provided by the generic StanzaBase class.
+
+ Methods:
+ exception -- Overrides StanzaBase.exception
+ """
+
+ def exception(self, e):
+ """
+ Create and send an error reply.
+
+ Typically called when an event handler raises an exception.
+ The error's type and text content are based on the exception
+ object's type and content.
+
+ Overrides StanzaBase.exception.
+
+ Arguments:
+ e -- Exception object
+ """
+ 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'].append(extxml)
+ self['error']['type'] = e.etype
+ else:
+ # We probably didn't raise this on purpose, so send a traceback
+ self['error']['condition'] = 'undefined-condition'
+ if sys.version_info < (3, 0):
+ self['error']['text'] = "SleekXMPP got into trouble."
+ else:
+ self['error']['text'] = traceback.format_tb(e.__traceback__)
+ logging.exception('Error handling {%s}%s stanza' %
+ (self.namespace, self.name))
+ self.send()
+
+
+registerStanzaPlugin(RootStanza, Error)