From 0d326383799a7d7bb69fec9dcd1eaf9e1a64eab8 Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Fri, 11 Feb 2011 15:20:26 -0500 Subject: XMPPError exceptions can keep a stanza's contents. This allows exceptions to include the original content of a stanza in the error response by including the parameter clear=False when raising the exception. --- sleekxmpp/xmlstream/stanzabase.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'sleekxmpp/xmlstream/stanzabase.py') diff --git a/sleekxmpp/xmlstream/stanzabase.py b/sleekxmpp/xmlstream/stanzabase.py index 3937a7a9..1f229cea 100644 --- a/sleekxmpp/xmlstream/stanzabase.py +++ b/sleekxmpp/xmlstream/stanzabase.py @@ -1161,12 +1161,17 @@ class StanzaBase(ElementBase): self.clear() return self - def reply(self): + def reply(self, clear=True): """ - Reset the stanza and swap its 'from' and 'to' attributes to prepare - for sending a reply stanza. + Swap the 'from' and 'to' attributes to prepare the stanza for + sending a reply. If clear=True, then also remove the stanza's + contents to make room for the reply content. For client streams, the 'from' attribute is removed. + + Arguments: + clear -- Indicates if the stanza's contents should be + removed. Defaults to True """ # if it's a component, use from if self.stream and hasattr(self.stream, "is_component") and \ @@ -1175,7 +1180,8 @@ class StanzaBase(ElementBase): else: self['to'] = self['from'] del self['from'] - self.clear() + if clear: + self.clear() return self def error(self): -- cgit v1.2.3