]> git.ipfire.org Git - thirdparty/httpx.git/commitdiff
Refactoring of models api (#1284)
authorcdeler <serj.krotov@gmail.com>
Mon, 14 Sep 2020 11:16:45 +0000 (14:16 +0300)
committerGitHub <noreply@github.com>
Mon, 14 Sep 2020 11:16:45 +0000 (12:16 +0100)
* Made Request.prepare private (i.e. renamed it to _prepare)

* Added bytes as a new possible QueryParamTypes

httpx/_models.py
httpx/_types.py

index 526ee2cebf1e12745c29d44c69c2538008cfbde7..9d46752372fd622a01bc27616f9b9483053ff6d6 100644 (file)
@@ -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:
index 8989b2826c7172228b6d6ea01aa7df79e223d137..8aed3e83adc6d5e34be13107f9ffb6a018751e77 100644 (file)
@@ -34,6 +34,7 @@ QueryParamTypes = Union[
     Mapping[str, Union[PrimitiveData, Sequence[PrimitiveData]]],
     List[Tuple[str, PrimitiveData]],
     str,
+    bytes,
     None,
 ]