comparison sat/tools/common/uri.py @ 3661:cbb988a6f507

merge bookmark `@`
author Goffi <goffi@goffi.org>
date Wed, 08 Sep 2021 11:20:37 +0200
parents cc3b453670a2
children 67fc066ed2cd
comparison
equal deleted inserted replaced
3639:05db744f194f 3661:cbb988a6f507
17 # You should have received a copy of the GNU Affero General Public License 17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. 18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 19
20 """ XMPP uri parsing tools """ 20 """ XMPP uri parsing tools """
21 21
22 import sys
22 import urllib.parse 23 import urllib.parse
23 import urllib.request, urllib.parse, urllib.error 24 import urllib.request, urllib.parse, urllib.error
24 25
25 # FIXME: basic implementation, need to follow RFC 5122 26 # FIXME: basic implementation, need to follow RFC 5122
26 27
51 query_end = uri_split.query.find(";") 52 query_end = uri_split.query.find(";")
52 query_type = uri_split.query[:query_end] 53 query_type = uri_split.query[:query_end]
53 if query_end == -1 or "=" in query_type: 54 if query_end == -1 or "=" in query_type:
54 raise ValueError("no query type, invalid XMPP URI") 55 raise ValueError("no query type, invalid XMPP URI")
55 56
56 pairs = urllib.parse.parse_qs(uri_split.geturl()) 57 if sys.version_info >= (3, 9):
58 # parse_qs behaviour has been modified in Python 3.9, ";" is not understood as a
59 # parameter separator anymore but the "separator" argument has been added to
60 # change it.
61 pairs = urllib.parse.parse_qs(uri_split.geturl(), separator=";")
62 else:
63 pairs = urllib.parse.parse_qs(uri_split.geturl())
57 for k, v in list(pairs.items()): 64 for k, v in list(pairs.items()):
58 if len(v) != 1: 65 if len(v) != 1:
59 raise NotImplementedError("multiple values not managed") 66 raise NotImplementedError("multiple values not managed")
60 if k in ("path", "type", "sub_type"): 67 if k in ("path", "type", "sub_type"):
61 raise NotImplementedError("reserved key used in URI, this is not supported") 68 raise NotImplementedError("reserved key used in URI, this is not supported")