From 776efc56f4f660b8f0e0aa0b6520f60fae48c8cc Mon Sep 17 00:00:00 2001 From: David Robertson Date: Thu, 7 Apr 2022 17:29:12 +0100 Subject: [PATCH] I think `encode_query_args` is redundant. Rich thought that `QueryParams` is good enough to pass into urlencode (in #8372). It seems that `urlencode` has accepted its query parameters as strings or bytes since Python 3.2. --- synapse/http/client.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/synapse/http/client.py b/synapse/http/client.py index 6f59dc1c073b..8310fb466ac5 100644 --- a/synapse/http/client.py +++ b/synapse/http/client.py @@ -907,7 +907,7 @@ def read_body_with_max_size( return d -def encode_query_args(args: Optional[Mapping[str, Union[str, List[str]]]]) -> bytes: +def encode_query_args(args: Optional[QueryParams]) -> bytes: """ Encodes a map of query arguments to bytes which can be appended to a URL. @@ -920,13 +920,7 @@ def encode_query_args(args: Optional[Mapping[str, Union[str, List[str]]]]) -> by if args is None: return b"" - encoded_args = {} - for k, vs in args.items(): - if isinstance(vs, str): - vs = [vs] - encoded_args[k] = [v.encode("utf8") for v in vs] - - query_str = urllib.parse.urlencode(encoded_args, True) + query_str = urllib.parse.urlencode(args, True) return query_str.encode("utf8")