summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLance Stout <lancestout@gmail.com>2011-06-20 16:27:39 -0700
committerLance Stout <lancestout@gmail.com>2011-06-20 16:27:39 -0700
commit847510c6b577f889cdba5deaa0bb271475cc7c7f (patch)
tree100daed3b22acf6c7c6d338bc9c4f73fdb175467
parent393d702e77a82231a20b42a75e191b7e00b3f5c3 (diff)
parentd8d9e8df16c07bd13bbac72e4445a2930407b244 (diff)
downloadslixmpp-847510c6b577f889cdba5deaa0bb271475cc7c7f.tar.gz
slixmpp-847510c6b577f889cdba5deaa0bb271475cc7c7f.tar.bz2
slixmpp-847510c6b577f889cdba5deaa0bb271475cc7c7f.tar.xz
slixmpp-847510c6b577f889cdba5deaa0bb271475cc7c7f.zip
Merge branch 'develop' into exceptions
-rw-r--r--sleekxmpp/stanza/message.py2
-rw-r--r--sleekxmpp/xmlstream/xmlstream.py13
-rw-r--r--tests/test_stream_exceptions.py29
3 files changed, 38 insertions, 6 deletions
diff --git a/sleekxmpp/stanza/message.py b/sleekxmpp/stanza/message.py
index cb3d344c..3518fc7a 100644
--- a/sleekxmpp/stanza/message.py
+++ b/sleekxmpp/stanza/message.py
@@ -97,7 +97,7 @@ class Message(RootStanza):
clear -- Indicates if existing content should be removed
before replying. Defaults to True.
"""
- StanzaBase.reply(self)
+ StanzaBase.reply(self, clear)
if self['type'] == 'groupchat':
self['to'] = self['to'].bare
diff --git a/sleekxmpp/xmlstream/xmlstream.py b/sleekxmpp/xmlstream/xmlstream.py
index 5bc71f04..6282c8d0 100644
--- a/sleekxmpp/xmlstream/xmlstream.py
+++ b/sleekxmpp/xmlstream/xmlstream.py
@@ -944,13 +944,14 @@ class XMLStream(object):
func -- The event handler to execute.
args -- Arguments to the event handler.
"""
+ orig = copy.copy(args[0])
try:
func(*args)
except Exception as e:
error_msg = 'Error processing event handler: %s'
log.exception(error_msg % str(func))
- if hasattr(args[0], 'exception'):
- args[0].exception(e)
+ if hasattr(orig, 'exception'):
+ orig.exception(e)
def _event_runner(self):
"""
@@ -973,6 +974,7 @@ class XMLStream(object):
etype, handler = event[0:2]
args = event[2:]
+ orig = copy.copy(args[0])
if etype == 'stanza':
try:
@@ -980,7 +982,7 @@ class XMLStream(object):
except Exception as e:
error_msg = 'Error processing stream handler: %s'
log.exception(error_msg % handler.name)
- args[0].exception(e)
+ orig.exception(e)
elif etype == 'schedule':
try:
log.debug('Scheduled event: %s' % args)
@@ -989,6 +991,7 @@ class XMLStream(object):
log.exception('Error processing scheduled task')
elif etype == 'event':
func, threaded, disposable = handler
+ orig = copy.copy(args[0])
try:
if threaded:
x = threading.Thread(
@@ -1001,8 +1004,8 @@ class XMLStream(object):
except Exception as e:
error_msg = 'Error processing event handler: %s'
log.exception(error_msg % str(func))
- if hasattr(args[0], 'exception'):
- args[0].exception(e)
+ if hasattr(orig, 'exception'):
+ orig.exception(e)
elif etype == 'quit':
log.debug("Quitting event runner thread")
return False
diff --git a/tests/test_stream_exceptions.py b/tests/test_stream_exceptions.py
index bc01c2a7..1143ce28 100644
--- a/tests/test_stream_exceptions.py
+++ b/tests/test_stream_exceptions.py
@@ -15,6 +15,35 @@ class TestStreamExceptions(SleekTest):
sys.excepthook = sys.__excepthook__
self.stream_close()
+ def testExceptionReply(self):
+ """Test that raising an exception replies with the original stanza."""
+
+ def message(msg):
+ msg.reply()
+ msg['body'] = 'Body changed'
+ raise XMPPError(clear=False)
+
+
+ sys.excepthook = lambda *args, **kwargs: None
+ self.stream_start()
+ self.xmpp.add_event_handler('message', message)
+
+ self.recv("""
+ <message>
+ <body>This is going to cause an error.</body>
+ </message>
+ """)
+
+ self.send("""
+ <message type="error">
+ <body>This is going to cause an error.</body>
+ <error type="cancel" code="500">
+ <undefined-condition
+ xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" />
+ </error>
+ </message>
+ """)
+
def testXMPPErrorException(self):
"""Test raising an XMPPError exception."""