Skip to content
Myr

Add back in URL.raw with NamedTuple (#2481)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* add back in URL.raw with NamedTuple * Update _urls.py * Update _urls.py

authored by Demetri · committed by GitHub · parent 933551c · Browse files · 3 files+37 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Co-authored-by: Tom Christie <tom@tomchristie.com>

Diff stats

3 files+37 added−1 removed

  • tests:+10 added−0 removed
  • other:+27 added−1 removed

3 files+37 added−1 removed

modified:httpx/_types.py+11 added
14 unmodified lines
15 Iterable,16 Iterator,17 List,18 Mapping,19 NamedTuple,20 Optional,21 Sequence,22 Tuple,23 Union,
7 unmodified lines
313233PrimitiveData = Optional[Union[str, int, float, bool]]3435RawURL = NamedTuple(36 "RawURL",37 [38 ("raw_scheme", bytes),39 ("raw_host", bytes),40 ("port", Optional[int]),41 ("raw_path", bytes),42 ],43)4445URLTypes = Union["URL", str]4647QueryParamTypes = Union[48 "QueryParams",
84 unmodified lines
modified:httpx/_urls.py+16 added-1 removed
4 unmodified lines
5import rfc39866import rfc3986.exceptions78from ._exceptions import InvalidURL9from ._types import PrimitiveData, QueryParamTypes, URLTypes9from ._types import PrimitiveData, QueryParamTypes, RawURL, URLTypes10from ._utils import primitive_value_to_str111213class URL:
297 unmodified lines
311 """312 return unquote(self._uri_reference.fragment or "")313314 @property315 def raw(self) -> RawURL:316 """317 Provides the (scheme, host, port, target) for the outgoing request.318319 In older versions of `httpx` this was used in the low-level transport API.320 We no longer use `RawURL`, and this property will be deprecated in a future release.321 """322 return RawURL(323 self.raw_scheme,324 self.raw_host,325 self.port,326 self.raw_path,327 )328329 @property330 def is_absolute_url(self) -> bool:331 """332 Return `True` for absolute URLs such as 'http://example.com/path',333 and `False` for relative URLs such as '/path'.
435 unmodified lines
modified:tests/models/test_url.py+10 added
422 unmodified lines
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]/"427428429def test_url_raw_compatibility():430 url = httpx.URL("https://www.example.com/path")431 scheme, host, port, raw_path = url.raw432433 assert scheme == b"https"434 assert host == b"www.example.com"435 assert port is None436 assert raw_path == b"/path"