]> git.ipfire.org Git - thirdparty/httpx.git/commitdiff
Drop RawURL (#2241)
authorTom Christie <tom@tomchristie.com>
Mon, 30 May 2022 13:54:47 +0000 (14:54 +0100)
committerGitHub <noreply@github.com>
Mon, 30 May 2022 13:54:47 +0000 (14:54 +0100)
httpx/_models.py
httpx/_types.py
httpx/_urls.py
tests/client/test_proxies.py
tests/models/test_url.py

index cff6929d9e5c1fd69ef4cc35e5cf95b21301ce37..8879532c8164a5e8e725d9bc54f80828ecfbfedd 100644 (file)
@@ -33,7 +33,6 @@ from ._types import (
     CookieTypes,
     HeaderTypes,
     QueryParamTypes,
-    RawURL,
     RequestContent,
     RequestData,
     RequestFiles,
@@ -306,7 +305,7 @@ class Request:
     def __init__(
         self,
         method: typing.Union[str, bytes],
-        url: typing.Union["URL", str, RawURL],
+        url: typing.Union["URL", str],
         *,
         params: typing.Optional[QueryParamTypes] = None,
         headers: typing.Optional[HeaderTypes] = None,
index c4063fe407a1b608a60b6a00b5d4de10f51c5076..784848ef8cc8acc6a2db66563e977dd4ef3c573a 100644 (file)
@@ -30,8 +30,6 @@ if TYPE_CHECKING:  # pragma: no cover
 
 PrimitiveData = Optional[Union[str, int, float, bool]]
 
-RawURL = Tuple[bytes, bytes, Optional[int], bytes]
-
 URLTypes = Union["URL", str]
 
 QueryParamTypes = Union[
index 8beeacf1601f0f0651084404b42a31923d636dc8..cf4df384c13d84b23499566e139d812bca6482fc 100644 (file)
@@ -6,7 +6,7 @@ import rfc3986
 import rfc3986.exceptions
 
 from ._exceptions import InvalidURL
-from ._types import PrimitiveData, QueryParamTypes, RawURL, URLTypes
+from ._types import PrimitiveData, QueryParamTypes, URLTypes
 from ._utils import primitive_value_to_str
 
 
@@ -71,22 +71,9 @@ class URL:
     """
 
     def __init__(
-        self, url: typing.Union["URL", str, RawURL] = "", **kwargs: typing.Any
+        self, url: typing.Union["URL", str] = "", **kwargs: typing.Any
     ) -> None:
-        if isinstance(url, (str, tuple)):
-            if isinstance(url, tuple):
-                raw_scheme, raw_host, port, raw_path = url
-                scheme = raw_scheme.decode("ascii")
-                host = raw_host.decode("ascii")
-                if host and ":" in host and host[0] != "[":
-                    # it's an IPv6 address, so it should be enclosed in "[" and "]"
-                    # ref: https://tools.ietf.org/html/rfc2732#section-2
-                    # ref: https://tools.ietf.org/html/rfc3986#section-3.2.2
-                    host = f"[{host}]"
-                port_str = "" if port is None else f":{port}"
-                path = raw_path.decode("ascii")
-                url = f"{scheme}://{host}{port_str}{path}"
-
+        if isinstance(url, str):
             try:
                 self._uri_reference = rfc3986.iri_reference(url).encode()
             except rfc3986.exceptions.InvalidAuthority as exc:
@@ -322,21 +309,6 @@ class URL:
         """
         return unquote(self._uri_reference.fragment or "")
 
-    @property
-    def raw(self) -> RawURL:
-        """
-        The URL in the raw representation used by the low level
-        transport API. See `BaseTransport.handle_request`.
-
-        Provides the (scheme, host, port, target) for the outgoing request.
-        """
-        return (
-            self.raw_scheme,
-            self.raw_host,
-            self.port,
-            self.raw_path,
-        )
-
     @property
     def is_absolute_url(self) -> bool:
         """
index 2e88f644bb60f2378533ea82a64d86e548014f97..c44cb54aa09d9f00c1adcd700de4c8aa09197b1d 100644 (file)
@@ -10,8 +10,8 @@ def url_to_origin(url: str):
     Given a URL string, return the origin in the raw tuple format that
     `httpcore` uses for it's representation.
     """
-    scheme, host, port = httpx.URL(url).raw[:3]
-    return httpcore.URL(scheme=scheme, host=host, port=port, target="/")
+    u = httpx.URL(url)
+    return httpcore.URL(scheme=u.raw_scheme, host=u.raw_host, port=u.port, target="/")
 
 
 @pytest.mark.parametrize(
index a088fc2a1031e5cbb32ddc0310aa2f038c7dab9d..321cffb3c9aca31dc0985f1d4ecdb412f034cd2a 100644 (file)
@@ -417,10 +417,9 @@ def test_ipv6_url_copy_with_host(url_str, new_host):
     assert str(url) == "http://[::ffff:192.168.0.1]:1234"
 
 
-@pytest.mark.parametrize("host", [b"[::ffff:192.168.0.1]", b"::ffff:192.168.0.1"])
+@pytest.mark.parametrize("host", ["[::ffff:192.168.0.1]", "::ffff:192.168.0.1"])
 def test_ipv6_url_from_raw_url(host):
-    raw_url = (b"https", host, 443, b"/")
-    url = httpx.URL(raw_url)
+    url = httpx.URL(scheme="https", host=host, port=443, path="/")
 
     assert url.host == "::ffff:192.168.0.1"
     assert url.netloc == b"[::ffff:192.168.0.1]"