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
| 13 | |
| 14 | |
| 15 | class URL: |
| 16 | class="st">""" |
| 17 | url = httpx.URL(class="st">"HTTPS://jo%40email.com:a%20secret@müller.de:1234/pa%20th?search=abclass="cm">#anchorlink") |
| 18 | |
| 19 | assert url.scheme == class="st">"https" |
| 20 | assert url.username == class="st">"jo@email.com" |
| 21 | assert url.password == class="st">"a secret" |
| 22 | assert url.userinfo == bclass="st">"jo%40email.com:a%20secret" |
| 23 | assert url.host == class="st">"müller.de" |
| 24 | assert url.raw_host == bclass="st">"xn--mller-kva.de" |
| 25 | assert url.port == 1234 |
| 26 | assert url.netloc == bclass="st">"xn--mller-kva.de:1234" |
| 27 | assert url.path == class="st">"/pa th" |
| 28 | assert url.query == bclass="st">"?search=ab" |
| 29 | assert url.raw_path == bclass="st">"/pa%20th?search=ab" |
| 30 | assert url.fragment == class="st">"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=abclass="cm">#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(class="st">"http://中国.icom.museum") |
| 46 | assert url.host == class="st">"中国.icom.museum" |
| 47 | url = httpx.URL(class="st">"http://xn--fiqs8s.icom.museum") |
| 48 | assert url.host == class="st">"中国.icom.museum" |
| 49 | |
| 50 | * `url.raw_host` is normalized to always be lowercased, and is IDNA encoded. |
| 51 | |
| 52 | url = httpx.URL(class="st">"http://中国.icom.museum") |
| 53 | assert url.raw_host == bclass="st">"xn--fiqs8s.icom.museum" |
| 54 | url = httpx.URL(class="st">"http://xn--fiqs8s.icom.museum") |
| 55 | assert url.raw_host == bclass="st">"xn--fiqs8s.icom.museum" |
| 56 | |
| 57 | * `url.port` is either None or an integer. URLs that include the default port for |
| 58 | class="st">"http", class="st">"https", class="st">"ws", class="st">"wss", and class="st">"ftp" schemes have their port |
| 59 | normalized to `None`. |
| 60 | |
| 61 | assert httpx.URL(class="st">"http://example.com") == httpx.URL(class="st">"http://example.com:80") |
| 62 | assert httpx.URL(class="st">"http://example.com").port is None |
| 63 | assert httpx.URL(class="st">"http://example.com:80").port is None |
| 64 | |
| 65 | * `url.userinfo` is raw bytes, without URL escaping. Usually you&class="cm">#x27;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&class="cm">#x27;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 |
no outgoing calls
no test coverage detected