# HG changeset patch # User Goffi # Date 1657377037 -7200 # Node ID 67fc066ed2cdb2e8ff18a6fa44a2b159f0cd72c2 # Parent 432aaba0d7fefd8a1c09c2165c6d6ae39d4d96a5 tools (common/uri): accept URIs without type: URIs without type are used to link JIDs. rel 369 diff -r 432aaba0d7fe -r 67fc066ed2cd sat/tools/common/uri.py --- a/sat/tools/common/uri.py Sat Jul 09 16:29:36 2022 +0200 +++ b/sat/tools/common/uri.py Sat Jul 09 16:30:37 2022 +0200 @@ -19,6 +19,7 @@ """ XMPP uri parsing tools """ +from typing import Optional import sys import urllib.parse import urllib.request, urllib.parse, urllib.error @@ -50,9 +51,13 @@ data = {"path": urllib.parse.unquote(uri_split.path)} query_end = uri_split.query.find(";") - query_type = uri_split.query[:query_end] - if query_end == -1 or "=" in query_type: - raise ValueError("no query type, invalid XMPP URI") + if query_end == -1: + # we just have a JID + query_type = None + else: + query_type = uri_split.query[:query_end] + if "=" in query_type: + raise ValueError("no query type, invalid XMPP URI") if sys.version_info >= (3, 9): # parse_qs behaviour has been modified in Python 3.9, ";" is not understood as a @@ -92,13 +97,19 @@ ) -def buildXMPPUri(type_, **kwargs): +def buildXMPPUri(type_: Optional[str] = None, **kwargs: str) -> str: uri = ["xmpp:"] subtype = kwargs.pop("subtype", None) path = kwargs.pop("path") uri.append(urllib.parse.quote_plus(path.encode("utf-8")).replace("%40", "@")) - if type_ == "pubsub": + if type_ is None: + # we have an URI to a JID + if kwargs: + raise NotImplementedError( + "keyword arguments are not supported for URI without type" + ) + elif type_ == "pubsub": if subtype == "microblog" and not kwargs.get("node"): kwargs["node"] = "urn:xmpp:microblog:0" if kwargs: