From f6b3a0c6cffa5ebf10d20c20b5cadd575c91fe81 Mon Sep 17 00:00:00 2001 From: mathieui Date: Thu, 12 Feb 2015 12:17:01 +0100 Subject: Fix the uses of stanza.reply() This is relying on the stanzas being copied for each handler. We no longer do that for performance reasons, so instead of editing the copy in-place, stanza.reply() now returns a new stanza. --- slixmpp/stanza/rootstanza.py | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'slixmpp/stanza/rootstanza.py') diff --git a/slixmpp/stanza/rootstanza.py b/slixmpp/stanza/rootstanza.py index 7bd0c32d..ff139382 100644 --- a/slixmpp/stanza/rootstanza.py +++ b/slixmpp/stanza/rootstanza.py @@ -46,37 +46,37 @@ class RootStanza(StanzaBase): # locally. Using the condition/text from that error # response could leak too much information, so we'll # only use a generic error here. - self.reply() - self['error']['condition'] = 'undefined-condition' - self['error']['text'] = 'External error' - self['error']['type'] = 'cancel' + reply = self.reply() + reply['error']['condition'] = 'undefined-condition' + reply['error']['text'] = 'External error' + reply['error']['type'] = 'cancel' log.warning('You should catch IqError exceptions') - self.send() + reply.send() elif isinstance(e, IqTimeout): - self.reply() - self['error']['condition'] = 'remote-server-timeout' - self['error']['type'] = 'wait' + reply = self.reply() + reply['error']['condition'] = 'remote-server-timeout' + reply['error']['type'] = 'wait' log.warning('You should catch IqTimeout exceptions') - self.send() + reply.send() elif isinstance(e, XMPPError): # We raised this deliberately - self.reply(clear=e.clear) - self['error']['condition'] = e.condition - self['error']['text'] = e.text - self['error']['type'] = e.etype + reply = self.reply(clear=e.clear) + reply['error']['condition'] = e.condition + reply['error']['text'] = e.text + reply['error']['type'] = e.etype 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.send() + reply['error'].append(extxml) + reply.send() else: # We probably didn't raise this on purpose, so send an error stanza - self.reply() - self['error']['condition'] = 'undefined-condition' - self['error']['text'] = "Slixmpp got into trouble." - self['error']['type'] = 'cancel' - self.send() + reply = self.reply() + reply['error']['condition'] = 'undefined-condition' + reply['error']['text'] = "Slixmpp got into trouble." + reply['error']['type'] = 'cancel' + reply.send() # log the error log.exception('Error handling {%s}%s stanza', self.namespace, self.name) -- cgit v1.2.3