Format: application/x-python-code
1 o
2
3 C'h.T � @ s� d dl mZ d dlZd dlmZmZmZ d dlZddlm Z ddl
4 mZ ddlm
5 Z
6 dd gZG d
7 d� d�ZG dd � d ejeef �ZdS )� )�annotationsN)�parse_qs�unquote� urlencode� )�QueryParamTypes)�urlparse��primitive_value_to_str�URL�QueryParamsc @ sr e Zd ZdZdNdOd d
8 �ZedPdd
9 ��ZedQdd��ZedQdd��ZedPdd��Z edPdd��Z
10 edPdd��ZedQdd��ZedRdd��Z
11 edQdd��ZedPd d!��ZedQd"d#��ZedSd%d&��ZedQd'd(��ZedPd)d*��ZedTd,d-��ZedTd.d/��ZdUd0d1�ZdVdWd5d6�ZdVdWd7d8�ZdXd9d:�ZdYd=d>�ZdZd?d@�Zd[dBdC�Zd\dEdF�ZdPdGdH�ZdPdIdJ�Zed]dLdM��Z d2S )^r u(
12
13 url = httpx.URL("HTTPS://jo%40email.com:a%20secret@müller.de:1234/pa%20th?search=ab#anchorlink")
14
15 assert url.scheme == "https"
16 assert url.username == "jo@email.com"
17 assert url.password == "a secret"
18 assert url.userinfo == b"jo%40email.com:a%20secret"
19 assert url.host == "müller.de"
20 assert url.raw_host == b"xn--mller-kva.de"
21 assert url.port == 1234
22 assert url.netloc == b"xn--mller-kva.de:1234"
23 assert url.path == "/pa th"
24 assert url.query == b"?search=ab"
25 assert url.raw_path == b"/pa%20th?search=ab"
26 assert url.fragment == "anchorlink"
27
28 The components of a URL are broken down like this:
29
30 https://jo%40email.com:a%20secret@müller.de:1234/pa%20th?search=ab#anchorlink
31 [scheme] [ username ] [password] [ host ][port][ path ] [ query ] [fragment]
32 [ userinfo ] [ netloc ][ raw_path ]
33
34 Note that:
35
36 * `url.scheme` is normalized to always be lowercased.
37
38 * `url.host` is normalized to always be lowercased. Internationalized domain
39 names are represented in unicode, without IDNA encoding applied. For instance:
40
41 url = httpx.URL("http://中国.icom.museum")
42 assert url.host == "中国.icom.museum"
43 url = httpx.URL("http://xn--fiqs8s.icom.museum")
44 assert url.host == "中国.icom.museum"
45
46 * `url.raw_host` is normalized to always be lowercased, and is IDNA encoded.
47
48 url = httpx.URL("http://中国.icom.museum")
49 assert url.raw_host == b"xn--fiqs8s.icom.museum"
50 url = httpx.URL("http://xn--fiqs8s.icom.museum")
51 assert url.raw_host == b"xn--fiqs8s.icom.museum"
52
53 * `url.port` is either None or an integer. URLs that include the default port for
54 "http", "https", "ws", "wss", and "ftp" schemes have their port
55 normalized to `None`.
56
57 assert httpx.URL("http://example.com") == httpx.URL("http://example.com:80")
58 assert httpx.URL("http://example.com").port is None
59 assert httpx.URL("http://example.com:80").port is None
60
61 * `url.userinfo` is raw bytes, without URL escaping. Usually you'll want to work
62 with `url.username` and `url.password` instead, which handle the URL escaping.
63
64 * `url.raw_path` is raw bytes of both the path and query, without URL escaping.
65 This portion is used as the target when constructing HTTP requests. Usually you'll
66 want to work with `url.path` instead.
67
68 * `url.query` is raw bytes, without URL escaping. A URL query string portion can
69 only be properly URL escaped when decoding the parameter names and values
70 themselves.
71 � �url� URL | str�kwargs�
72 typing.Any�return�Nonec
73
74 K s2 |rlt t t tt ttt ttt td�}|�� D ]A\}}||vr&|�d�}t|��|d urJt||| �sJ|| j}t|�j}d|�d|� d|� �}t|��t|t�rV|� d�||<