From abd3f40e96cedba6898ca203cec7c584990cb4b7 Mon Sep 17 00:00:00 2001 From: nicoco Date: Thu, 23 Feb 2023 07:01:32 +0100 Subject: [PATCH] XMPPError: add optional by attribute so it is added to the reply stanzas --- slixmpp/exceptions.py | 6 ++++-- slixmpp/stanza/rootstanza.py | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/slixmpp/exceptions.py b/slixmpp/exceptions.py index 61c6fa3c..a1a56a14 100644 --- a/slixmpp/exceptions.py +++ b/slixmpp/exceptions.py @@ -7,7 +7,8 @@ from typing import Optional -from .types import ErrorConditions, ErrorTypes +from .types import ErrorConditions, ErrorTypes, JidStr + class XMPPError(Exception): @@ -43,7 +44,7 @@ class XMPPError(Exception): def __init__(self, condition: ErrorConditions='undefined-condition', text='', etype: Optional[ErrorTypes]=None, extension=None, extension_ns=None, - extension_args=None, clear=True): + extension_args=None, clear=True, by: Optional[JidStr] = None): if extension_args is None: extension_args = {} if condition not in _DEFAULT_ERROR_TYPES: @@ -51,6 +52,7 @@ class XMPPError(Exception): if etype is None: etype = _DEFAULT_ERROR_TYPES[condition] + self.by = by self.condition = condition self.text = text self.etype = etype diff --git a/slixmpp/stanza/rootstanza.py b/slixmpp/stanza/rootstanza.py index 351596ff..0d59def7 100644 --- a/slixmpp/stanza/rootstanza.py +++ b/slixmpp/stanza/rootstanza.py @@ -63,6 +63,8 @@ class RootStanza(StanzaBase): reply['error']['condition'] = e.condition reply['error']['text'] = e.text reply['error']['type'] = e.etype + if e.by: + reply["error"]["by"] = e.by if e.extension is not None: # Extended error tag extxml = ET.Element("{%s}%s" % (e.extension_ns, e.extension),