From: cdeler Date: Mon, 14 Sep 2020 11:16:45 +0000 (+0300) Subject: Refactoring of models api (#1284) X-Git-Tag: 0.15.0~17 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=62c6c1c8ad68556542d7b7a4be9dc6997bad1e01;p=thirdparty%2Fhttpx.git Refactoring of models api (#1284) * Made Request.prepare private (i.e. renamed it to _prepare) * Added bytes as a new possible QueryParamTypes --- diff --git a/httpx/_models.py b/httpx/_models.py index 526ee2ce..9d467523 100644 --- a/httpx/_models.py +++ b/httpx/_models.py @@ -242,7 +242,8 @@ class QueryParams(typing.Mapping[str, str]): value = args[0] if args else kwargs items: typing.Sequence[typing.Tuple[str, PrimitiveData]] - if value is None or isinstance(value, str): + if value is None or isinstance(value, (str, bytes)): + value = value.decode("ascii") if isinstance(value, bytes) else value items = parse_qsl(value) elif isinstance(value, QueryParams): items = value.multi_items() @@ -606,9 +607,9 @@ class Request: else: self.stream = encode(data, files, json) - self.prepare() + self._prepare() - def prepare(self) -> None: + def _prepare(self) -> None: for key, value in self.stream.get_headers().items(): # Ignore Transfer-Encoding if the Content-Length has been set explicitly. if key.lower() == "transfer-encoding" and "content-length" in self.headers: diff --git a/httpx/_types.py b/httpx/_types.py index 8989b282..8aed3e83 100644 --- a/httpx/_types.py +++ b/httpx/_types.py @@ -34,6 +34,7 @@ QueryParamTypes = Union[ Mapping[str, Union[PrimitiveData, Sequence[PrimitiveData]]], List[Tuple[str, PrimitiveData]], str, + bytes, None, ]