diff options
author | Philipp Hörist <philipp@hoerist.com> | 2023-09-17 22:21:43 +0300 |
---|---|---|
committer | Philipp Hörist <philipp@hoerist.com> | 2023-09-17 22:21:43 +0300 |
commit | 4ff3d8eccf8a934c74e44578b44c56a1c4b59542 (patch) | |
tree | 1ea8bf89038fb2fdb4b45bbb643b11540920df7f /nbxmpp/xmppiri.py | |
parent | 5a9e65af7c76e038daa42dff09b9cdb529b87939 (diff) |
feat: JID: Add JID.from_iri()
Diffstat (limited to 'nbxmpp/xmppiri.py')
-rw-r--r-- | nbxmpp/xmppiri.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/nbxmpp/xmppiri.py b/nbxmpp/xmppiri.py index bc0035e..fd3c491 100644 --- a/nbxmpp/xmppiri.py +++ b/nbxmpp/xmppiri.py @@ -115,3 +115,20 @@ def escape_inode(node: str) -> str: def escape_ires(res: str) -> str: return _escape(res, rx_ires) + + +def clean_iri(iri_str: str) -> str: + if not iri_str.startswith('xmpp:'): + raise ValueError('IRI must start with xmpp scheme') + + iri_str = iri_str.removeprefix('xmpp:') + + if iri_str.startswith('//'): + # Remove auth component + iri_str = iri_str.removeprefix('//') + iri_str = iri_str.split('/', maxsplit=1)[1] + + # Remove query and fragment + iri_str = iri_str.split('?', maxsplit=1)[0] + iri_str = iri_str.split('#', maxsplit=1)[0] + return iri_str |