Skip to content

Commit

Permalink
Drop RawURL (#2241)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomchristie committed May 30, 2022
1 parent 5b06aea commit 9baf3a6
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 40 deletions.
3 changes: 1 addition & 2 deletions httpx/_models.py
Expand Up @@ -33,7 +33,6 @@
CookieTypes,
HeaderTypes,
QueryParamTypes,
RawURL,
RequestContent,
RequestData,
RequestFiles,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 0 additions & 2 deletions httpx/_types.py
Expand Up @@ -30,8 +30,6 @@

PrimitiveData = Optional[Union[str, int, float, bool]]

RawURL = Tuple[bytes, bytes, Optional[int], bytes]

URLTypes = Union["URL", str]

QueryParamTypes = Union[
Expand Down
34 changes: 3 additions & 31 deletions httpx/_urls.py
Expand Up @@ -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


Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
"""
Expand Down
4 changes: 2 additions & 2 deletions tests/client/test_proxies.py
Expand Up @@ -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(
Expand Down
5 changes: 2 additions & 3 deletions tests/models/test_url.py
Expand Up @@ -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]"
Expand Down

0 comments on commit 9baf3a6

Please sign in to comment.