Format: application/x-python-code
⬇ Download File (21.3 KB)
   1  o
   2  
   3  C'h.T�@s�ddlmZddlZddlmZmZmZddlZddlm	Z	ddl
   4  mZddlm
   5  Z
   6  dd	gZGd
   7  d�d�ZGdd	�d	ejeef�ZdS)�)�annotationsN)�parse_qs�unquote�	urlencode�)�QueryParamTypes)�urlparse��primitive_value_to_str�URL�QueryParamsc@sreZdZdZdNdOd	d
   8  �ZedPdd
   9  ��ZedQdd��ZedQdd��ZedPdd��Z	edPdd��Z
  10  edPdd��ZedQdd��ZedRdd��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)^ru(
  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  Ks2|rlttttttttttttd�}|��D]A\}}||vr&|�d�}t|��|durJt|||�sJ||j}t|�j}d|�d|�d|��}t|��t|t�rV|�	d�||<qd|vrl|�
  75  d�}	|	sddntt|	��|d<t|t�r|t|fi|��|_
  76  dSt|t�r�|j
  77  jdi|��|_
  78  dStd	t|��d
  79  |����)N)�scheme�username�password�userinfo�host�port�netloc�path�query�raw_path�fragment�paramsz) is an invalid keyword argument for URL()z	Argument z	 must be z	 but got �asciirrz6Invalid type for url.  Expected str or httpx.URL, got z: �)�str�bytes�int�object�items�	TypeError�
  80  isinstance�__name__�type�decode�poprr�_uri_referencer�	copy_with)
  81  �selfrr�allowed�key�value�message�expected�seenrr!r!�AC:\Users\shubh\Videos\agent\nova\Lib\site-packages\httpx/_urls.py�__init__MsP�
  82  
  83  
  84  
  85  �
  86  
  87  
  88  ���zURL.__init__r"cC�|jjS)zb
  89          The URL scheme, such as "http", "https".
  90          Always normalised to lowercase.
  91          )r-r�r/r!r!r6r~�z
  92  URL.schemer#cC�|jj�d�S)z�
  93          The raw bytes representation of the URL scheme, such as b"http", b"https".
  94          Always normalised to lowercase.
  95          r )r-r�encoder9r!r!r6�
  96  raw_scheme��zURL.raw_schemecCr;)zj
  97          The URL userinfo as a raw bytestring.
  98          For example: b"jo%40email.com:a%20secret".
  99          r )r-rr<r9r!r!r6r�r>zURL.userinfocC�|jj}t|�d�d�S)zn
 100          The URL username as a string, with URL decoding applied.
 101          For example: "jo@email.com"
 102          �:r�r-rr�	partition�r/rr!r!r6r��zURL.usernamecCr?)zj
 103          The URL password as a string, with URL decoding applied.
 104          For example: "a secret"
 105          r@�rArCr!r!r6r�rDzURL.passwordcCs |jj}|�d�rt�|�}|S)u%
 106          The URL host as a string.
 107          Always normalized to lowercase, with IDNA hosts decoded into unicode.
 108  
 109          Examples:
 110  
 111          url = httpx.URL("http://www.EXAMPLE.org")
 112          assert url.host == "www.example.org"
 113  
 114          url = httpx.URL("http://中国.icom.museum")
 115          assert url.host == "中国.icom.museum"
 116  
 117          url = httpx.URL("http://xn--fiqs8s.icom.museum")
 118          assert url.host == "中国.icom.museum"
 119  
 120          url = httpx.URL("https://[::ffff:192.168.0.1]")
 121          assert url.host == "::ffff:192.168.0.1"
 122          zxn--)r-r�
 123  startswith�idnar+)r/rr!r!r6r�s
 124  
 125  zURL.hostcCr;)uA
 126          The raw bytes representation of the URL host.
 127          Always normalized to lowercase, and IDNA encoded.
 128  
 129          Examples:
 130  
 131          url = httpx.URL("http://www.EXAMPLE.org")
 132          assert url.raw_host == b"www.example.org"
 133  
 134          url = httpx.URL("http://中国.icom.museum")
 135          assert url.raw_host == b"xn--fiqs8s.icom.museum"
 136  
 137          url = httpx.URL("http://xn--fiqs8s.icom.museum")
 138          assert url.raw_host == b"xn--fiqs8s.icom.museum"
 139  
 140          url = httpx.URL("https://[::ffff:192.168.0.1]")
 141          assert url.raw_host == b"::ffff:192.168.0.1"
 142          r )r-rr<r9r!r!r6�raw_host�szURL.raw_host�
 143  int | NonecCr8)a�
 144          The URL port as an integer.
 145  
 146          Note that the URL class performs port normalization as per the WHATWG spec.
 147          Default ports for "http", "https", "ws", "wss", and "ftp" schemes are always
 148          treated as `None`.
 149  
 150          For example:
 151  
 152          assert httpx.URL("http://www.example.com") == httpx.URL("http://www.example.com:80")
 153          assert httpx.URL("http://www.example.com:80").port is None
 154          )r-rr9r!r!r6r�szURL.portcCr;)z�
 155          Either `<host>` or `<host>:<port>` as bytes.
 156          Always normalized to lowercase, and IDNA encoded.
 157  
 158          This property may be used for generating the value of a request
 159          "Host" header.
 160          r )r-rr<r9r!r!r6r�s	z
 161  URL.netloccCs|jjpd}t|�S)z�
 162          The URL path as a string. Excluding the query string, and URL decoded.
 163  
 164          For example:
 165  
 166          url = httpx.URL("https://example.com/pa%20th")
 167          assert url.path == "/pa th"
 168          �/)r-rr�r/rr!r!r6r�s
 169  zURL.pathcCs|jjpd}|�d�S)a�
 170          The URL query string, as raw bytes, excluding the leading b"?".
 171  
 172          This is necessarily a bytewise interface, because we cannot
 173          perform URL decoding of this representation until we've parsed
 174          the keys and values into a QueryParams instance.
 175  
 176          For example:
 177  
 178          url = httpx.URL("https://example.com/?filter=some%20search%20terms")
 179          assert url.query == b"filter=some%20search%20terms"
 180          r
 181  r )r-rr<)r/rr!r!r6rs
 182  z	URL.queryrcCst|jj�S)zz
 183          The URL query parameters, neatly parsed and packaged into an immutable
 184          multidict representation.
 185          )rr-rr9r!r!r6rsz
 186  URL.paramscCs2|jjpd}|jjdur|d|jj7}|�d�S)a
 187          The complete URL path and query string as raw bytes.
 188          Used as the target when constructing HTTP requests.
 189  
 190          For example:
 191  
 192          GET /users?search=some%20text HTTP/1.1
 193          Host: www.example.org
 194          Connection: close
 195          rJN�?r )r-rrr<rKr!r!r6rs
 196  zURL.raw_pathcCst|jjpd�S)zk
 197          The URL fragments, as used in HTML anchors.
 198          As a string, without the leading '#'.
 199          r
 200  )rr-rr9r!r!r6r+szURL.fragment�boolcCst|jjo|jj�S)z�
 201          Return `True` for absolute URLs such as 'http://example.com/path',
 202          and `False` for relative URLs such as '/path'.
 203          )rMr-rrr9r!r!r6�is_absolute_url3s
 204  zURL.is_absolute_urlcCs|jS)z�
 205          Return `False` for absolute URLs such as 'http://example.com/path',
 206          and `True` for relative URLs such as '/path'.
 207          )rNr9r!r!r6�is_relative_url?r:zURL.is_relative_urlcKst|fi|��S)a�
 208          Copy this URL, returning a new URL with some components altered.
 209          Accepts the same set of parameters as the components that are made
 210          available via properties on the `URL` class.
 211  
 212          For example:
 213  
 214          url = httpx.URL("https://www.example.com").copy_with(
 215              username="jo@gmail.com", password="a secret"
 216          )
 217          assert url == "https://jo%40email.com:a%20secret@www.example.com"
 218          )r)r/rr!r!r6r.Gs
 219  z
 220  URL.copy_withNr1r2cC�|j|j�||�d�S�N)r)r.r�set�r/r1r2r!r!r6�copy_set_paramV�zURL.copy_set_paramcCrPrQ)r.r�addrSr!r!r6�copy_add_paramYrUzURL.copy_add_paramcC�|j|j�|�d�SrQ)r.r�remove�r/r1r!r!r6�copy_remove_param\�zURL.copy_remove_paramrrcCrXrQ)r.r�merge�r/rr!r!r6�copy_merge_params_r\zURL.copy_merge_paramscCs&ddlm}t|t|�tt|����S)z�
 221          Return an absolute URL, using this URL as the base.
 222  
 223          Eg.
 224  
 225          url = httpx.URL("https://www.example.com/test")
 226          url = url.join("/new/path")
 227          assert url == "https://www.example.com/new/path"
 228          r)�urljoin)�urllib.parser`rr")r/rr`r!r!r6�joinbs
 229  zURL.joinr$cC�tt|��S�N��hashr"r9r!r!r6�__hash__p�zURL.__hash__�othercCs"t|ttf�ot|�tt|��kSrd)r(rr"�r/rir!r!r6�__eq__ss"z
 230  URL.__eq__cC�
 231  t|j�Srd)r"r-r9r!r!r6�__str__v�
 232  zURL.__str__c
 233  Cs�|j\}}}}}}}d|vr|�d�d�d�}d�|r!|�d�ndd|vr,d|�d�n||dur6d|��ndg�}d�|rD|j�d�nd|rLd|��nd||durWd	|��nd|durad
 234  |��ndg�}	|jj�d|	�d�S)
 235  Nr@rz	:[secure]r
 236  �@�[�]z//rL�#�(�))r-�splitrbr�	__class__r))
 237  r/rrrrrrr�	authorityrr!r!r6�__repr__ys$����
 238  zURL.__repr__�tuple[bytes, bytes, int, bytes]cCsBddl}ddl}|�d�|�dgd��}||j|j|j|jd�S)NrzURL.raw is deprecated.�RawURL)r=rHrr)�collections�warnings�warn�
 239  namedtupler=rHrr)r/r{r|rzr!r!r6�raw�s
 240  ��zURL.raw)r
 241  )rrrrrr�rr")rr#)rrI)rr�rrM)rrrrrd)r1r"r2rrr)r1r"rr)rrrr)rrrr�rr$�rirrrM)rry)!r)�
 242  __module__�__qualname__�__doc__r7�propertyrr=rrrrrHrrrrrrrrNrOr.rTrWr[r_rbrgrkrmrxrr!r!r!r6rs^=1
 243  
 244  
 245  
 246  
 247  
 248  
 249  
 250  
 251  c@s�eZdZdZdCdd	�ZdDdd�ZdEdd�ZdFdd�ZdGdd�ZdHdIdd�Z	dJdd�Z
 252  dHdKd d!�ZdHdKd"d#�ZdLd$d%�Z
 253  dHdMd'd(�ZdNd)d*�ZdOd,d-�ZdPd/d0�ZdQd2d3�ZdRd4d5�ZdQd6d7�ZdSd9d:�ZdTd;d<�ZdTd=d>�ZdHdUd?d@�ZdVdAdB�ZdS)Wrz0
 254      URL query parameters, as a multi-dict.
 255      �args�QueryParamTypes | NonerrrrcOs�t|�dks
 256  Jd��|r|rJd��|r|dn|}|dus%t|ttf�r:t|t�r/|�d�n|}t|dd�|_dSt|t�rLdd	�|j��D�|_dSi}t|t	t
 257  f�rh|D]}|�|dg��|d
 258  �qWn	dd	�|��D�}dd	�|��D�|_dS)
 259  NrEzToo many arguments.z'Cannot mix named and unnamed arguments.rr T)�keep_blank_valuescSsi|]	\}}|t|��qSr!)�list��.0�k�vr!r!r6�
 260  <dictcomp>��z(QueryParams.__init__.<locals>.<dictcomp>rcSs.i|]\}}|t|ttf�rt|�n|g�qSr!)r(r��tupler�r!r!r6r��s��cSs$i|]\}}t|�dd�|D��qS)cSsg|]}t|��qSr!r	)r��itemr!r!r6�
 261  <listcomp>��z3QueryParams.__init__.<locals>.<dictcomp>.<listcomp>)r"r�r!r!r6r��s��)
 262  �lenr(r"r#r+r�_dictrr&r�r��
 263  setdefault�append)r/r�rr2Z
 264  dict_valuer�r!r!r6r7�s&
 265  ���zQueryParams.__init__�typing.KeysView[str]cCs
 266  |j��S)z�
 267          Return all the keys in the query params.
 268  
 269          Usage:
 270  
 271          q = httpx.QueryParams("a=123&a=456&b=789")
 272          assert list(q.keys()) == ["a", "b"]
 273          )r��keysr9r!r!r6r��s
 274  	zQueryParams.keys�typing.ValuesView[str]cCsdd�|j��D���S)a
 275          Return all the values in the query params. If a key occurs more than once
 276          only the first item for that key is returned.
 277  
 278          Usage:
 279  
 280          q = httpx.QueryParams("a=123&a=456&b=789")
 281          assert list(q.values()) == ["123", "789"]
 282          cS�i|]	\}}||d�qS�rr!r�r!r!r6r��r�z&QueryParams.values.<locals>.<dictcomp>)r�r&�valuesr9r!r!r6r���
 283  zQueryParams.values�typing.ItemsView[str, str]cCsdd�|j��D���S)a
 284          Return all items in the query params. If a key occurs more than once
 285          only the first item for that key is returned.
 286  
 287          Usage:
 288  
 289          q = httpx.QueryParams("a=123&a=456&b=789")
 290          assert list(q.items()) == [("a", "123"), ("b", "789")]
 291          cSr�r�r!r�r!r!r6r��r�z%QueryParams.items.<locals>.<dictcomp>)r�r&r9r!r!r6r&�r�zQueryParams.items�list[tuple[str, str]]cs4g}|j��D]\�}|��fdd�|D��q|S)z�
 292          Return all items in the query params. Allow duplicate keys to occur.
 293  
 294          Usage:
 295  
 296          q = httpx.QueryParams("a=123&a=456&b=789")
 297          assert list(q.multi_items()) == [("a", "123"), ("a", "456"), ("b", "789")]
 298          csg|]}�|f�qSr!r!)r��i�r�r!r6r��r�z+QueryParams.multi_items.<locals>.<listcomp>)r�r&�extend)r/�multi_itemsr�r!r�r6r��s	zQueryParams.multi_itemsNr1�defaultcCs ||jvr|jt|�dS|S)z�
 299          Get a value from the query param for a given key. If the key occurs
 300          more than once, then only the first value is returned.
 301  
 302          Usage:
 303  
 304          q = httpx.QueryParams("a=123&a=456&b=789")
 305          assert q.get("a") == "123"
 306          r)r�r")r/r1r�r!r!r6�gets
 307  
 308  zQueryParams.getr"�	list[str]cCst|j�t|�g��S)z�
 309          Get all values from the query param for a given key.
 310  
 311          Usage:
 312  
 313          q = httpx.QueryParams("a=123&a=456&b=789")
 314          assert q.get_list("a") == ["123", "456"]
 315          )r�r�r�r"rZr!r!r6�get_lists	zQueryParams.get_listr2cCs*t�}t|j�|_t|�g|jt|�<|S)z�
 316          Return a new QueryParams instance, setting the value of a key.
 317  
 318          Usage:
 319  
 320          q = httpx.QueryParams("a=123")
 321          q = q.set("a", "456")
 322          assert q == httpx.QueryParams("a=456")
 323          )r�dictr�r
 324  r"�r/r1r2�qr!r!r6rRs
 325  zQueryParams.setcCs4t�}t|j�|_|�|�t|�g|jt|�<|S)z�
 326          Return a new QueryParams instance, setting or appending the value of a key.
 327  
 328          Usage:
 329  
 330          q = httpx.QueryParams("a=123")
 331          q = q.add("a", "456")
 332          assert q == httpx.QueryParams("a=123&a=456")
 333          )rr�r�r�r
 334  r"r�r!r!r6rV(s
 335  zQueryParams.addcCs(t�}t|j�|_|j�t|�d�|S)z�
 336          Return a new QueryParams instance, removing the value of a key.
 337  
 338          Usage:
 339  
 340          q = httpx.QueryParams("a=123")
 341          q = q.remove("a")
 342          assert q == httpx.QueryParams("")
 343          N)rr�r�r,r")r/r1r�r!r!r6rY7s
 344  zQueryParams.removercCst|�}i|j�|j�|_|S)a\
 345          Return a new QueryParams instance, updated with.
 346  
 347          Usage:
 348  
 349          q = httpx.QueryParams("a=123")
 350          q = q.merge({"b": "456"})
 351          assert q == httpx.QueryParams("a=123&b=456")
 352  
 353          q = httpx.QueryParams("a=123")
 354          q = q.merge({"a": "456", "b": "789"})
 355          assert q == httpx.QueryParams("a=456&b=789")
 356          )rr�)r/rr�r!r!r6r]FszQueryParams.mergecCs|j|dS)Nr�r�rZr!r!r6�__getitem__XszQueryParams.__getitem__rMcCs
 357  ||jvSrdr�rZr!r!r6�__contains__[rnzQueryParams.__contains__�typing.Iterator[typing.Any]cC�t|���Srd)�iterr�r9r!r!r6�__iter__^rhzQueryParams.__iter__r$cCrlrd)r�r�r9r!r!r6�__len__arnzQueryParams.__len__cCrlrd)rMr�r9r!r!r6�__bool__drnzQueryParams.__bool__cCrcrdrer9r!r!r6rggrhzQueryParams.__hash__ricCs(t||j�sdSt|���t|���kS)NF)r(rv�sortedr�rjr!r!r6rkjszQueryParams.__eq__cCr�rd)rr�r9r!r!r6rmorhzQueryParams.__str__cCs |jj}t|�}|�d|�d�S)Nrsrt)rvr)r")r/�
 358  class_nameZquery_stringr!r!r6rxrszQueryParams.__repr__cC�td��)NzYQueryParams are immutable since 0.18.0. Use `q = q.merge(...)` to create an updated copy.��RuntimeErrorr^r!r!r6�updatew��zQueryParams.updatecCr�)Nz^QueryParams are immutable since 0.18.0. Use `q = q.set(key, value)` to create an updated copy.r�rSr!r!r6�__setitem__}r�zQueryParams.__setitem__)r�r�rrrr)rr�)rr�)rr�)rr�rd)r1rr�rrr)r1r"rr�)r1r"r2rrr)r1r"rr)rr�rr)r1rrr")r1rrrM)rr�r�r�r�r�)rr�rr)r1r"r2r"rr)r)r�r�r�r7r�r�r&r�r�r�rRrVrYr]r�r�r�r�r�rgrkrmrxr�r�r!r!r!r6r�s0
 359  
 360  &
 361  
 362  
 363  
 364  
 365  
 366  
 367  
 368  
 369  
 370  
 371  
 372  
 373  
 374  )�
 375  __future__r�typingrarrrrG�_typesrZ	_urlparser�_utilsr
 376  �__all__r�Mappingr"rr!r!r!r6�<module>s