Commit dcce30a4 authored by Philipp Hörist's avatar Philipp Hörist
Browse files

JID: Add option to coerce to bare jid while parsing

parent daf9c92c
......@@ -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)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment