Drop RawURL (#2241)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Tom Christie · committed by GitHub · parent 5b06aea · Browse files · 5 files·+8 added−40 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
5 files+8 added−40 removed
- tests:+4 added−5 removed
- other:+4 added−35 removed
Provenance
- Commit
9baf3a6- Tree
838910c- Author
Tom Christie <tom@tomchristie.com>- Committer
GitHub <noreply@github.com>- Parent
5b06aea
5 files changed+8 added−40 removed
modified:httpx/_models.py+1 added-2 removed
31 unmodified lines32 AsyncByteStream,33 CookieTypes,34 HeaderTypes,35 QueryParamTypes,36- RawURL,36 RequestContent,37 RequestData,38 RequestFiles,39 ResponseContent,264 unmodified lines304 class Request:305 def __init__(306 self,307 method: typing.Union[str, bytes],309- url: typing.Union["URL", str, RawURL],308+ url: typing.Union["URL", str],309 *,310 params: typing.Optional[QueryParamTypes] = None,311 headers: typing.Optional[HeaderTypes] = None,312 cookies: typing.Optional[CookieTypes] = None,883 unmodified linesmodified:httpx/_types.py-2 removed
28 unmodified lines29 30 31 PrimitiveData = Optional[Union[str, int, float, bool]]32 33-RawURL = Tuple[bytes, bytes, Optional[int], bytes]34-33 URLTypes = Union["URL", str]34 35 QueryParamTypes = Union[36 "QueryParams",113 unmodified linesmodified:httpx/_urls.py+3 added-31 removed
4 unmodified lines5 import rfc39866 import rfc3986.exceptions7 8 from ._exceptions import InvalidURL9-from ._types import PrimitiveData, QueryParamTypes, RawURL, URLTypes9+from ._types import PrimitiveData, QueryParamTypes, URLTypes10 from ._utils import primitive_value_to_str11 12 13 class URL:56 unmodified lines70 be properly URL escaped when decoding the parameter names and values themselves.71 """72 73 def __init__(74- self, url: typing.Union["URL", str, RawURL] = "", **kwargs: typing.Any74+ self, url: typing.Union["URL", str] = "", **kwargs: typing.Any75 ) -> None:76- if isinstance(url, (str, tuple)):77- if isinstance(url, tuple):78- raw_scheme, raw_host, port, raw_path = url79- scheme = raw_scheme.decode("ascii")80- host = raw_host.decode("ascii")81- if host and ":" in host and host[0] != "[":82- # it's an IPv6 address, so it should be enclosed in "[" and "]"83- # ref: https://tools.ietf.org/html/rfc2732#section-284- # ref: https://tools.ietf.org/html/rfc3986#section-3.2.285- host = f"[{host}]"86- port_str = "" if port is None else f":{port}"87- path = raw_path.decode("ascii")88- url = f"{scheme}://{host}{port_str}{path}"89-76+ if isinstance(url, str):77 try:78 self._uri_reference = rfc3986.iri_reference(url).encode()79 except rfc3986.exceptions.InvalidAuthority as exc:80 raise InvalidURL(message=str(exc)) from None228 unmodified lines309 """310 return unquote(self._uri_reference.fragment or "")311 312 @property326- def raw(self) -> RawURL:327- """328- The URL in the raw representation used by the low level329- transport API. See `BaseTransport.handle_request`.330-331- Provides the (scheme, host, port, target) for the outgoing request.332- """333- return (334- self.raw_scheme,335- self.raw_host,336- self.port,337- self.raw_path,338- )339-340- @property313 def is_absolute_url(self) -> bool:314 """315 Return `True` for absolute URLs such as 'http://example.com/path',316 and `False` for relative URLs such as '/path'.435 unmodified linesmodified:tests/client/test_proxies.py+2 added-2 removed
8 unmodified lines9 """10 Given a URL string, return the origin in the raw tuple format that11 `httpcore` uses for it's representation.12 """13- scheme, host, port = httpx.URL(url).raw[:3]14- return httpcore.URL(scheme=scheme, host=host, port=port, target="/")13+ u = httpx.URL(url)14+ return httpcore.URL(scheme=u.raw_scheme, host=u.raw_host, port=u.port, target="/")15 16 17 @pytest.mark.parametrize(18 ["proxies", "expected_proxies"],268 unmodified linesmodified:tests/models/test_url.py+2 added-3 removed
415 unmodified lines416 assert url.netloc == b"[::ffff:192.168.0.1]:1234"417 assert str(url) == "http://[::ffff:192.168.0.1]:1234"418 419 420-@pytest.mark.parametrize("host", [b"[::ffff:192.168.0.1]", b"::ffff:192.168.0.1"])420+@pytest.mark.parametrize("host", ["[::ffff:192.168.0.1]", "::ffff:192.168.0.1"])421 def test_ipv6_url_from_raw_url(host):422- raw_url = (b"https", host, 443, b"/")423- url = httpx.URL(raw_url)422+ url = httpx.URL(scheme="https", host=host, port=443, path="/")423 424 assert url.host == "::ffff:192.168.0.1"425 assert url.netloc == b"[::ffff:192.168.0.1]"426 assert str(url) == "https://[::ffff:192.168.0.1]/"