diff options
author | lovetox <philipp@hoerist.com> | 2022-01-10 19:38:58 +0300 |
---|---|---|
committer | lovetox <philipp@hoerist.com> | 2022-01-10 19:38:58 +0300 |
commit | dcce30a46c367286b2836f56a6492234d8489ab4 (patch) | |
tree | 68c1ff5c51086f5d1a739a27e7d2d41dee0ae859 | |
parent | daf9c92cd6f2a81e491de53e88ad6a4281954f01 (diff) |
JID: Add option to coerce to bare jid while parsing
-rw-r--r-- | nbxmpp/protocol.py | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/nbxmpp/protocol.py b/nbxmpp/protocol.py index 35d8308..8814ed3 100644 --- a/nbxmpp/protocol.py +++ b/nbxmpp/protocol.py @@ -595,7 +595,7 @@ class JID: @classmethod @functools.lru_cache(maxsize=None) - def from_string(cls, jid_string: str) -> JID: + def from_string(cls, jid_string: str, force_bare: bool = False) -> JID: # https://tools.ietf.org/html/rfc7622#section-3.2 # Remove any portion from the first '/' character to the end of the @@ -614,6 +614,11 @@ class JID: else: localpart, domainpart = None, rest + if force_bare: + if localpart is None: + raise LocalpartByteLimit + resourcepart = None + return cls(localpart=localpart, domain=domainpart, resource=resourcepart) |