Skip to content
Myr

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

5 files+8 added−40 removed

modified:httpx/_models.py+1 added-2 removed
31 unmodified lines
32 AsyncByteStream,33 CookieTypes,34 HeaderTypes,35 QueryParamTypes,36 RawURL,36 RequestContent,37 RequestData,38 RequestFiles,39 ResponseContent,
264 unmodified lines
304class 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 lines
modified:httpx/_types.py-2 removed
28 unmodified lines
293031PrimitiveData = Optional[Union[str, int, float, bool]]3233RawURL = Tuple[bytes, bytes, Optional[int], bytes]3433URLTypes = Union["URL", str]3435QueryParamTypes = Union[36 "QueryParams",
113 unmodified lines
modified:httpx/_urls.py+3 added-31 removed
4 unmodified lines
5import rfc39866import rfc3986.exceptions78from ._exceptions import InvalidURL9from ._types import PrimitiveData, QueryParamTypes, RawURL, URLTypes9from ._types import PrimitiveData, QueryParamTypes, URLTypes10from ._utils import primitive_value_to_str111213class URL:
56 unmodified lines
70 be properly URL escaped when decoding the parameter names and values themselves.71 """7273 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}"8976 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 None
228 unmodified lines
309 """310 return unquote(self._uri_reference.fragment or "")311312 @property326 def raw(self) -> RawURL:327 """328 The URL in the raw representation used by the low level329 transport API. See `BaseTransport.handle_request`.330331 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 )339340 @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 lines
modified:tests/client/test_proxies.py+2 added-2 removed
8 unmodified lines
9 """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="/")151617@pytest.mark.parametrize(18 ["proxies", "expected_proxies"],
268 unmodified lines
modified:tests/models/test_url.py+2 added-3 removed
415 unmodified lines
416 assert url.netloc == b"[::ffff:192.168.0.1]:1234"417 assert str(url) == "http://[::ffff:192.168.0.1]:1234"418419420@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"])421def 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="/")423424 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]/"