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.
This commit is contained in:
@@ -144,7 +144,7 @@ class Iq(RootStanza):
|
||||
self.xml.remove(child)
|
||||
return self
|
||||
|
||||
def reply(self):
|
||||
def reply(self, clear=True):
|
||||
"""
|
||||
Send a reply <iq> stanza.
|
||||
|
||||
@@ -152,9 +152,13 @@ class Iq(RootStanza):
|
||||
|
||||
Sets the 'type' to 'result' in addition to the default
|
||||
StanzaBase.reply behavior.
|
||||
|
||||
Arguments:
|
||||
clear -- Indicates if existing content should be
|
||||
removed before replying. Defaults to True.
|
||||
"""
|
||||
self['type'] = 'result'
|
||||
StanzaBase.reply(self)
|
||||
StanzaBase.reply(self, clear)
|
||||
return self
|
||||
|
||||
def send(self, block=True, timeout=None, callback=None):
|
||||
|
||||
@@ -104,7 +104,7 @@ class Message(RootStanza):
|
||||
self['type'] = 'normal'
|
||||
return self
|
||||
|
||||
def reply(self, body=None):
|
||||
def reply(self, body=None, clear=True):
|
||||
"""
|
||||
Create a message reply.
|
||||
|
||||
@@ -114,7 +114,9 @@ class Message(RootStanza):
|
||||
adds a message body if one is given.
|
||||
|
||||
Arguments:
|
||||
body -- Optional text content for the message.
|
||||
body -- Optional text content for the message.
|
||||
clear -- Indicates if existing content should be removed
|
||||
before replying. Defaults to True.
|
||||
"""
|
||||
StanzaBase.reply(self)
|
||||
if self['type'] == 'groupchat':
|
||||
|
||||
@@ -173,14 +173,18 @@ class Presence(RootStanza):
|
||||
# The priority is not a number: we consider it 0 as a default
|
||||
return 0
|
||||
|
||||
def reply(self):
|
||||
def reply(self, clear=True):
|
||||
"""
|
||||
Set the appropriate presence reply type.
|
||||
|
||||
Overrides StanzaBase.reply.
|
||||
|
||||
Arguments:
|
||||
clear -- Indicates if the stanza contents should be removed
|
||||
before replying. Defaults to True.
|
||||
"""
|
||||
if self['type'] == 'unsubscribe':
|
||||
self['type'] = 'unsubscribed'
|
||||
elif self['type'] == 'subscribe':
|
||||
self['type'] = 'subscribed'
|
||||
return StanzaBase.reply(self)
|
||||
return StanzaBase.reply(self, clear)
|
||||
|
||||
@@ -43,8 +43,8 @@ class RootStanza(StanzaBase):
|
||||
Arguments:
|
||||
e -- Exception object
|
||||
"""
|
||||
self.reply()
|
||||
if isinstance(e, XMPPError):
|
||||
self.reply(clear=e.clear)
|
||||
# We raised this deliberately
|
||||
self['error']['condition'] = e.condition
|
||||
self['error']['text'] = e.text
|
||||
@@ -56,6 +56,7 @@ class RootStanza(StanzaBase):
|
||||
self['error']['type'] = e.etype
|
||||
self.send()
|
||||
else:
|
||||
self.reply()
|
||||
# We probably didn't raise this on purpose, so send an error stanza
|
||||
self['error']['condition'] = 'undefined-condition'
|
||||
self['error']['text'] = "SleekXMPP got into trouble."
|
||||
|
||||
Reference in New Issue
Block a user