diff --git a/httpx/_models.py b/httpx/_models.py index cff6929d9e..8879532c81 100644 --- a/httpx/_models.py +++ b/httpx/_models.py @@ -33,7 +33,6 @@ 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, diff --git a/httpx/_types.py b/httpx/_types.py index c4063fe407..784848ef8c 100644 --- a/httpx/_types.py +++ b/httpx/_types.py @@ -30,8 +30,6 @@ PrimitiveData = Optional[Union[str, int, float, bool]] -RawURL = Tuple[bytes, bytes, Optional[int], bytes] - URLTypes = Union["URL", str] QueryParamTypes = Union[ diff --git a/httpx/_urls.py b/httpx/_urls.py index 8beeacf160..cf4df384c1 100644 --- a/httpx/_urls.py +++ b/httpx/_urls.py @@ -6,7 +6,7 @@ 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 @@ def fragment(self) -> str: """ 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: """ diff --git a/tests/client/test_proxies.py b/tests/client/test_proxies.py index 2e88f644bb..c44cb54aa0 100644 --- a/tests/client/test_proxies.py +++ b/tests/client/test_proxies.py @@ -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( diff --git a/tests/models/test_url.py b/tests/models/test_url.py index a088fc2a10..321cffb3c9 100644 --- a/tests/models/test_url.py +++ b/tests/models/test_url.py @@ -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]"