MCPcopy
hub / github.com/encode/httpx / URL

Class URL

httpx/_urls.py:15–417  ·  view source on GitHub ↗

url = httpx.URL("HTTPS://jo%40email.com:a%20secret@müller.de:1234/pa%20th?search=ab#anchorlink") assert url.scheme == "https" assert url.username == "jo@email.com" assert url.password == "a secret" assert url.userinfo == b"jo%40email.com:a%20secret" assert url.host == "müll

Source from the content-addressed store, hash-verified

13
14
15class URL:
16 """
17 url = httpx.URL("HTTPS://jo%40email.com:a%20secret@müller.de:1234/pa%20th?search=ab#anchorlink")
18
19 assert url.scheme == "https"
20 assert url.username == "jo@email.com"
21 assert url.password == "a secret"
22 assert url.userinfo == b"jo%40email.com:a%20secret"
23 assert url.host == "müller.de"
24 assert url.raw_host == b"xn--mller-kva.de"
25 assert url.port == 1234
26 assert url.netloc == b"xn--mller-kva.de:1234"
27 assert url.path == "/pa th"
28 assert url.query == b"?search=ab"
29 assert url.raw_path == b"/pa%20th?search=ab"
30 assert url.fragment == "anchorlink"
31
32 The components of a URL are broken down like this:
33
34 https://jo%40email.com:a%20secret@müller.de:1234/pa%20th?search=ab#anchorlink
35 [scheme] [ username ] [password] [ host ][port][ path ] [ query ] [fragment]
36 [ userinfo ] [ netloc ][ raw_path ]
37
38 Note that:
39
40 * `url.scheme` is normalized to always be lowercased.
41
42 * `url.host` is normalized to always be lowercased. Internationalized domain
43 names are represented in unicode, without IDNA encoding applied. For instance:
44
45 url = httpx.URL("http://中国.icom.museum")
46 assert url.host == "中国.icom.museum"
47 url = httpx.URL("http://xn--fiqs8s.icom.museum")
48 assert url.host == "中国.icom.museum"
49
50 * `url.raw_host` is normalized to always be lowercased, and is IDNA encoded.
51
52 url = httpx.URL("http://中国.icom.museum")
53 assert url.raw_host == b"xn--fiqs8s.icom.museum"
54 url = httpx.URL("http://xn--fiqs8s.icom.museum")
55 assert url.raw_host == b"xn--fiqs8s.icom.museum"
56
57 * `url.port` is either None or an integer. URLs that include the default port for
58 "http", "https", "ws", "wss", and "ftp" schemes have their port
59 normalized to `None`.
60
61 assert httpx.URL("http://example.com") == httpx.URL("http://example.com:80")
62 assert httpx.URL("http://example.com").port is None
63 assert httpx.URL("http://example.com:80").port is None
64
65 * `url.userinfo` is raw bytes, without URL escaping. Usually you'll want to work
66 with `url.username` and `url.password` instead, which handle the URL escaping.
67
68 * `url.raw_path` is raw bytes of both the path and query, without URL escaping.
69 This portion is used as the target when constructing HTTP requests. Usually you'll
70 want to work with `url.path` instead.
71
72 * `url.query` is raw bytes, without URL escaping. A URL query string portion can

Callers 10

__init__Method · 0.85
copy_withMethod · 0.85
joinMethod · 0.85
__eq__Method · 0.85
__init__Method · 0.85
__init__Method · 0.85
base_urlMethod · 0.85
_merge_urlMethod · 0.85
_redirect_urlMethod · 0.85
__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected