XMPPError: add optional by attribute

so it is added to the reply stanzas
This commit is contained in:
nicoco 2023-02-23 07:01:32 +01:00 committed by Nicolas Cedilnik
parent b6f148e4e6
commit abd3f40e96
2 changed files with 6 additions and 2 deletions

View file

@ -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

View file

@ -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),