Drop RawURL (#2241)

This commit is contained in:
Tom Christie 2022-05-30 14:54:47 +01:00 committed by GitHub
parent 5b06aea1d6
commit 9baf3a6cd2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 8 additions and 40 deletions

View 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,

View 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[

View 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:
"""

View 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(

View 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]"