From 71128349a4d65e2d7790d40dba618f381e0989b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Sat, 18 Mar 2023 20:16:49 +0100 Subject: [PATCH] jid: add 'bare' parameter to JID to discard resource MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- slixmpp/jid.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/slixmpp/jid.py b/slixmpp/jid.py index c705a422..5a9257cc 100644 --- a/slixmpp/jid.py +++ b/slixmpp/jid.py @@ -303,13 +303,15 @@ class JID: :param string jid: A string of the form ``'[user@]domain[/resource]'``. + :param bool bare: + If present, discard the provided resource. :raises InvalidJID: """ __slots__ = ('_node', '_domain', '_resource', '_bare', '_full') - def __init__(self, jid: Optional[Union[str, 'JID']] = None): + def __init__(self, jid: Optional[Union[str, 'JID']] = None, bare: bool = False): if not jid: self._node = '' self._domain = '' @@ -318,11 +320,14 @@ class JID: self._full = '' return elif not isinstance(jid, JID): - self._node, self._domain, self._resource = _parse_jid(jid) + node, domain, resource = _parse_jid(jid) + self._node = node + self._domain = domain + self._resource = resource if not bare else '' else: self._node = jid._node self._domain = jid._domain - self._resource = jid._resource + self._resource = jid._resource if not bare else '' self._update_bare_full() def unescape(self):