Format: application/x-python-code
⬇ Download File (40.5 KB)
   1  o
   2  
   3  C'h��@s`ddlmZddlZddlZddlZddlZddlZddlZddlm	Z	m
   4  Z
   5  ddlmZddl
   6  m
   7  Z
   8  ddlmZmZmZddlmZmZmZmZmZmZdd	lmZdd
   9  lmZmZmZmZddl m!Z!m"Z"m#Z#m$Z$ddl%m&Z&dd
  10  l'm(Z(m)Z)ddl*m+Z+m,Z,ddl-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:ddl;m<Z<m=Z=ddl>m?Z?m@Z@ejAr�ddlBZBgd�ZCejDddd�ZEejDddd�ZFd7dd�ZGd8d d!�ZHd9d#d$�ZIGd%d&�d&�ZJeJ�ZKe�Ld'�ZMd(e
  11  ��ZNd)�Od*d+�e�P�D��ZQGd,d-�d-ejR�ZSGd.d/�d/e9�ZTGd0d1�d1e.�ZUejVd2ejWfZXGd3d4�d4�ZYGd5d�deY�ZZGd6d�deY�Z[dS):�)�annotationsN)�asynccontextmanager�contextmanager)�
  12  TracebackType�)�__version__)�Auth�	BasicAuth�FunctionAuth)�DEFAULT_LIMITS�DEFAULT_MAX_REDIRECTS�DEFAULT_TIMEOUT_CONFIG�Limits�Proxy�Timeout)�SUPPORTED_DECODERS)�
  13  InvalidURL�RemoteProtocolError�TooManyRedirects�request_context)�Cookies�Headers�Request�Response)�codes)�AsyncBaseTransport�
  14  BaseTransport)�AsyncHTTPTransport�
  15  HTTPTransport)
  16  �AsyncByteStream�	AuthTypes�	CertTypes�CookieTypes�HeaderTypes�
  17  ProxyTypes�QueryParamTypes�RequestContent�RequestData�RequestExtensions�RequestFiles�SyncByteStream�TimeoutTypes)�URL�QueryParams)�
  18  URLPattern�get_environment_proxies)�USE_CLIENT_DEFAULT�AsyncClient�Client�Tr2)�bound�Ur1�urlr,�location�return�boolcCs<|j|jkrdS|jdkot|�dko|jdkot|�dkS)zA
  19      Return 'True' if 'location' is a HTTPS upgrade of 'url'
  20      F�http�P�https�)�host�scheme�_port_or_default)r6r7�rA�CC:\Users\shubh\Videos\agent\nova\Lib\site-packages\httpx/_client.py�_is_https_redirect>s
  21  
  22  ��
  23  �rC�
  24  int | NonecCs"|jdur|jSddd��|j�S)Nr;r=)r:r<)�port�getr?�r6rArArBr@Ms
  25  r@�othercCs(|j|jko|j|jkot|�t|�kS)z@
  26      Return 'True' if the given URLs share the same origin.
  27      )r?r>r@)r6rHrArArB�_same_originSs
  28  
  29  ��rIc@seZdZdZdS)�UseClientDefaulta<
  30      For some parameters such as `auth=...` and `timeout=...` we need to be able
  31      to indicate the default "unset" state, in a way that is distinctly different
  32      to using `None`.
  33  
  34      The default "unset" state indicates that whatever default is set on the
  35      client should be used. This is different to setting `None`, which
  36      explicitly disables the parameter, possibly overriding a client default.
  37  
  38      For example we use `timeout=USE_CLIENT_DEFAULT` in the `request()` signature.
  39      Omitting the `timeout` parameter will send a request using whatever default
  40      timeout has been configured on the client. Including `timeout=None` will
  41      ensure no timeout is used.
  42  
  43      Note that user code shouldn't need to use the `USE_CLIENT_DEFAULT` constant,
  44      but it is used internally when a parameter is not included.
  45      N)�__name__�
  46  __module__�__qualname__�__doc__rArArArBrJ^srJZhttpxz
  47  python-httpx/z, cCsg|]}|dkr|�qS)�identityrA)�.0�keyrArArB�
  48  <listcomp>ysrRc@seZdZdZdZdZdS)�ClientStater��N)rKrLrM�UNOPENED�OPENED�CLOSEDrArArArBrS}srSc@�.eZdZdZdd
  49  d�Zdd
  50  d�Zddd�ZdS)�BoundSyncStreamz�
  51      A byte stream that is bound to a given response instance, and that
  52      ensures the `response.elapsed` is set once the response is closed.
  53      �streamr*�responser�start�floatr8�NonecC�||_||_||_dS�N��_stream�	_response�_start��selfr[r\r]rArArB�__init__��
  54  zBoundSyncStream.__init__�typing.Iterator[bytes]ccs�|jD]}|VqdSra�rc�rg�chunkrArArB�__iter__�s�
  55  �zBoundSyncStream.__iter__cCs,t��|j}tj|d�|j_|j��dS�N)�seconds)	�time�perf_counterre�datetime�	timedeltard�elapsedrc�close�rgrurArArBrv�szBoundSyncStream.closeN)r[r*r\rr]r^r8r_)r8rj�r8r_)rKrLrMrNrhrnrvrArArArBrZ��
  56  
  57  
  58  rZc@rY)�BoundAsyncStreamz�
  59      An async byte stream that is bound to a given response instance, and that
  60      ensures the `response.elapsed` is set once the response is closed.
  61      r[rr\rr]r^r8r_cCr`rarbrfrArArBrh�rizBoundAsyncStream.__init__�typing.AsyncIterator[bytes]cCs"�|j2z	3dHW}|Vq6dSrarkrlrArArB�	__aiter__�s��zBoundAsyncStream.__aiter__c�s4�t��|j}tj|d�|j_|j��IdHdSro)	rqrrrersrtrdrurc�acloserwrArArBr}�s�zBoundAsyncStream.acloseN)r[rr\rr]r^r8r_)r8r{rx)rKrLrMrNrhr|r}rArArArBrz�ryrz.c@s�eZdZddddededdddd�d|dd�Zed}d d!��Zed}d"d#��Zd~d&d'�Z	dd,d-�Z
  62  ed�d/d0��Zejd�d1d0��Zed�d3d4��Z
  63  e
  64  jd�d5d4��Z
  65  ed�d7d8��Zejd�d:d8��Zed�d;d<��Zejd�d=d<��Zed�d?d@��Zejd�dBd@��Zed�dDdE��Zejd�dGdE��Zed�dIdJ��Zejd�dLdJ��ZdddddddeddM�	d�d\d]�Zd�d^d_�Zd�d�d`da�Zd�d�dbdc�Z	d�d�ddde�Zd�dfdg�Zefd�dkdl�Zd�dodp�Zd�dqdr�Zd�dsdt�Zd�dudv�Zd�dxdy�Zd�dzd{�Z dS)��
  66  BaseClientNF�T�utf-8��auth�params�headers�cookies�timeout�follow_redirects�
  67  max_redirects�event_hooks�base_url�	trust_env�default_encodingr��AuthTypes | Noner��QueryParamTypes | Noner��HeaderTypes | Noner��CookieTypes | Noner�r+r�r9r��intr��+None | typing.Mapping[str, list[EventHook]]r��	URL | strr�r��#str | typing.Callable[[bytes], str]r8r_cCs�|durin|}|�t|	��|_|�|�|_t|�|_t|�|_t	|�|_
  68  t|�|_||_
  69  ||_t|�dg��t|�dg��d�|_|
  70  |_||_tj|_dS�N�requestr\)r�r\)�_enforce_trailing_slashr,�	_base_url�_build_auth�_authr-�_paramsrr�r�_cookiesr�_timeoutr�r��listrF�_event_hooks�
  71  _trust_env�_default_encodingrSrV�_state)rgr�r�r�r�r�r�r�r�r�r�r�rArArBrh�s
  72  
  73  
  74  
  75  �zBaseClient.__init__cCs|jtjkS)z2
  76          Check if the client being closed
  77          )r�rSrX�rgrArArB�	is_closed�szBaseClient.is_closedcC�|jSra)r�r�rArArBr���zBaseClient.trust_envr6r,cCs"|j�d�r|S|j|jdd�S)N�/��raw_path)r��endswith�	copy_with�rgr6rArArBr��sz"BaseClient._enforce_trailing_slash�proxy�ProxyTypes | None�allow_env_proxies�dict[str, Proxy | None]cCsH|dur|rdd�t���D�SiSt|ttf�rt|d�n|}d|iS)NcSs(i|]\}}||dur
  78  dnt|d��qS)NrG)r)rPrQr6rArArB�
  79  <dictcomp>�s��z-BaseClient._get_proxy_map.<locals>.<dictcomp>rGzall://)r/�items�
  80  isinstance�strr,r)rgr�r�rArArB�_get_proxy_map�s�zBaseClient._get_proxy_maprcCr�ra)r�r�rArArBr��r�zBaseClient.timeoutcC�t|�|_dSra)rr�)rgr�rArArBr���dict[str, list[EventHook]]cCr�ra)r�r�rArArBr�r�zBaseClient.event_hookscCs(t|�dg��t|�dg��d�|_dSr�)r�rFr�)rgr�rArArBr�	s��Auth | NonecCr�)z�
  81          Authentication class used when none is passed at the request-level.
  82  
  83          See also [Authentication][0].
  84  
  85          [0]: /quickstart/#authentication
  86          )r�r�rArArBr�s	zBaseClient.authr cCs|�|�|_dSra)r�r��rgr�rArArBr�scCr�)zK
  87          Base URL to use when sending requests with relative URLs.
  88          )r�r�rArArBr��zBaseClient.base_urlcCs|�t|��|_dSra)r�r,r�r�rArArBr�&srcCr�)z@
  89          HTTP headers to include when sending requests.
  90          )�_headersr�rArArBr�*r�zBaseClient.headersr#cCs2tdt�d�dt�d�d��}|�|�||_dS)Ns*/*�asciis
  91  keep-alive)sAcceptsAccept-Encodings
  92  Connections
  93  User-Agent)r�ACCEPT_ENCODING�encode�
  94  USER_AGENT�updater�)rgr�Zclient_headersrArArBr�1s��
  95  
  96  rcCr�)zA
  97          Cookie values to include when sending requests.
  98          )r�r�rArArBr�>r�zBaseClient.cookiesr"cCr�ra)rr�)rgr�rArArBr�Er�r-cCr�)zO
  99          Query parameters to include in the URL when sending requests.
 100          )r�r�rArArBr�Ir�zBaseClient.paramsr%cCr�ra)r-r�)rgr�rArArBr�Pr�)	�content�data�files�jsonr�r�r�r��
 101  extensions�methodr�r��RequestContent | Noner��RequestData | Noner��RequestFiles | Noner��typing.Any | None�TimeoutTypes | UseClientDefaultr��RequestExtensions | Nonerc	Cs�|�|�}|�|�}|�|	�}	|�|�}|durin|}d|vr9t|
 102  t�r(|jnt|
 103  �}
 104  tdi|�d|
 105  �	�i��}t
 106  |||||||||	|d�
 107  S)aR
 108          Build and return a request instance.
 109  
 110          * The `params`, `headers` and `cookies` arguments
 111          are merged with any values set on the client.
 112          * The `url` argument is merged with any `base_url` set on the client.
 113  
 114          See also: [Request instances][0]
 115  
 116          [0]: /advanced/clients/#request-instances
 117          Nr�)r�r�r�r�r�r�r�r�rA)�
 118  _merge_url�_merge_headers�_merge_cookies�_merge_queryparamsr�rJr�r�dict�as_dictr)rgr�r6r�r�r�r�r�r�r�r�r�rArArB�
 119  build_requestTs.
 120  
 121  
 122  
 123  ���zBaseClient.build_requestcCs4t|�}|jr|jj|j�d�}|jj|d�S|S)z�
 124          Merge a URL argument together with any 'base_url' on the client,
 125          to create the URL used for the outgoing request.
 126          r�r�)r,�is_relative_urlr�r��lstripr�)rgr6Z	merge_urlZmerge_raw_pathrArArBr��s
 127  zBaseClient._merge_urlcCs&|s|jrt|j�}|�|�|S|S)z�
 128          Merge a cookies argument together with any cookies on the client,
 129          to create the cookies used for the outgoing request.
 130          )r�rr�)rgr��merged_cookiesrArArBr��s
 131  
 132  
 133  
 134  zBaseClient._merge_cookiescCst|j�}|�|�|S)z�
 135          Merge a headers argument together with any headers on the client,
 136          to create the headers used for the outgoing request.
 137          )rr�r�)rgr�Zmerged_headersrArArBr��s
 138  
 139  zBaseClient._merge_headerscCs"|s|jrt|j�}|�|�S|S)z�
 140          Merge a queryparams argument together with any queryparams on the client,
 141          to create the queryparams used for the outgoing request.
 142          )r�r-�merge)rgr�Zmerged_queryparamsrArArBr��s
 143  
 144  
 145  zBaseClient._merge_queryparamscCsX|durdSt|t�rt|d|dd�St|t�r|St|�r%t|d�Std|����)Nrr��username�password)�funczInvalid "auth" argument: )r��tupler	r�callabler
 146  �	TypeErrorr�rArArBr��s
 147  
 148  
 149  zBaseClient._build_authr��#AuthTypes | UseClientDefault | NonercCsRt|t�r|jn|�|�}|dur|S|jj|jj}}|s |r&t||d�St�S)Nr�)	r�rJr�r�r6r�r�r	r)rgr�r�r�r�rArArB�_build_request_auth�s�zBaseClient._build_request_authr\rcCsR|�||�}|�||�}|�|||�}|�||�}t|j�}t||||||jd�S)z�
 150          Given a request and a redirect response, return a new request that
 151          should be used to effect the redirect.
 152          )r�r6r�r�r[r�)�_redirect_method�
 153  _redirect_url�_redirect_headers�_redirect_streamrr�rr�)rgr�r\r�r6r�r[r�rArArB�_build_redirect_request�s
 154  �z"BaseClient._build_redirect_requestcCsR|j}|jtjkr|dkrd}|jtjkr|dkrd}|jtjkr'|dkr'd}|S)z�
 155          When being redirected we may want to change the method of the request
 156          based on certain specs or browser behavior.
 157          �HEAD�GET�POST)r��status_coder�	SEE_OTHER�FOUND�MOVED_PERMANENTLY)rgr�r\r�rArArBr��szBaseClient._redirect_methodc
 158  Cs�|jd}zt|�}Wnty"}ztd|�d�|d�d�d}~ww|jr1|js1|j|jjd�}|jr:|j�	|�}|jj
 159  rI|j
 160  sI|j|jj
 161  d�}|S)z<
 162          Return the URL for the redirect to follow.
 163          ZLocationz Invalid URL in location header: �.�r�N)r>)�fragment)r�r,rrr?r>r�r6r��joinr�)rgr�r\r7r6�excrArArBr�s$
 164  ����zBaseClient._redirect_urlcCsxt|j�}t||j�st|j|�s|�dd�|j�d�|d<||jkr4|dkr4|�dd�|�dd�|�dd�|S)	zR
 165          Return the headers that should be used for the redirect request.
 166          �
 167  AuthorizationNr��Hostr�zContent-LengthzTransfer-Encoding�Cookie)	rr�rIr6rC�pop�netloc�decoder�)rgr�r6r�r�rArArBr�"s
 168  zBaseClient._redirect_headers�'SyncByteStream | AsyncByteStream | NonecCs||jkr|dkrdS|jS)zO
 169          Return the body that should be used for the redirect request.
 170          r�N)r�r[)rgr�r�rArArBr�=szBaseClient._redirect_streamcCsLd|jvr$t|jt�r|jnt|j�}tdi|j�d|��i��|_dSdS)Nr�rA)r�r�r�rJrr�r�)rgr�r�rArArB�_set_timeoutHs
 171  
 172  ��"�zBaseClient._set_timeout)r�r�r�r�r�r�r�r�r�r+r�r9r�r�r�r�r�r�r�r9r�r�r8r_)r8r9)r6r,r8r,)r�r�r�r9r8r�)r8r)r�r+r8r_)r8r�)r�r�r8r_)r8r�)r�r r8r_)r8r,)r6r�r8r_)r8r)r�r#r8r_)r8r)r�r"r8r_)r8r-)r�r%r8r_)r�r�r6r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r8r)r6r�r8r,ra)r�r�r8r�)r�r�r8r�)r�r�r8r�)r�r�r8r�)r�rr�r�r8r)r�rr\rr8r)r�rr\rr8r�)r�rr\rr8r,)r�rr6r,r�r�r8r)r�rr�r�r8r�)r�rr8r_)!rKrLrMr
 173  rrh�propertyr�r�r�r�r��setterr�r�r�r�r�r�r0r�r�r�r�r�r�r�r�r�r�r�r�r�rArArArBr~�s��"
 174  
 175  
 176  �
 177  3
 178  �
 179  �
 180  
 181  
 182  
 183  
 184  r~cseZdZdZdddddddddddedeeddddd�d|�fd-d.�Zdddddedfd}d0d1�Zdddddefd~d3d4�Z	dd7d8�Z
 185  dddddddeeedd9�d�dJdK�Ze
 186  dddddddeeedd9�d�dMdN��ZdeedO�d�dSdT�Zd�dXdY�Zd�dZd[�Zd�d\d]�Zdddeeedd^�d�d_d`�Zdddeeedd^�d�dbdc�Zdddeeedd^�d�ddde�Zdddddddeeedd9�d�dfdg�Zdddddddeeedd9�d�dhdi�Zdddddddeeedd9�d�djdk�Zdddeeedd^�d�dldm�Zd�dndo�Zd�drds�Z			d�d�dzd{�Z�ZS)�r2av
 187      An HTTP client, with connection pooling, HTTP/2, redirects, cookie persistence, etc.
 188  
 189      It can be shared between threads.
 190  
 191      Usage:
 192  
 193      ```python
 194      >>> client = httpx.Client()
 195      >>> response = client.get('https://example.org')
 196      ```
 197  
 198      **Parameters:**
 199  
 200      * **auth** - *(optional)* An authentication class to use when sending
 201      requests.
 202      * **params** - *(optional)* Query parameters to include in request URLs, as
 203      a string, dictionary, or sequence of two-tuples.
 204      * **headers** - *(optional)* Dictionary of HTTP headers to include when
 205      sending requests.
 206      * **cookies** - *(optional)* Dictionary of Cookie items to include when
 207      sending requests.
 208      * **verify** - *(optional)* Either `True` to use an SSL context with the
 209      default CA bundle, `False` to disable verification, or an instance of
 210      `ssl.SSLContext` to use a custom context.
 211      * **http2** - *(optional)* A boolean indicating if HTTP/2 support should be
 212      enabled. Defaults to `False`.
 213      * **proxy** - *(optional)* A proxy URL where all the traffic should be routed.
 214      * **timeout** - *(optional)* The timeout configuration to use when sending
 215      requests.
 216      * **limits** - *(optional)* The limits configuration to use.
 217      * **max_redirects** - *(optional)* The maximum number of redirect responses
 218      that should be followed.
 219      * **base_url** - *(optional)* A URL to use as the base when building
 220      request URLs.
 221      * **transport** - *(optional)* A transport class to use for sending requests
 222      over the network.
 223      * **trust_env** - *(optional)* Enables or disables usage of environment
 224      variables for configuration.
 225      * **default_encoding** - *(optional)* The default encoding to use for decoding
 226      response text, if no charset information is included in a response Content-Type
 227      header. Set to a callable for automatic character set detection. Default: "utf-8".
 228      NTFrr�)r�r�r�r��verify�certr��http1�http2r��mountsr�r��limitsr�r�r��	transportr�r�r�r�r�r�r�r�r�r��ssl.SSLContext | str | boolr��CertTypes | Noner�r9r�rr�r�r�0None | typing.Mapping[str, BaseTransport | None]r�r+r�rrr�r�r�r�r�r�r�BaseTransport | Noner�r�r8r_c
 229  s�t�j||||||
 230  |||�|d��r&zddl}Wnty%td�d�w�o+|du}��|
 231  |�}�j������|d��_�������fdd�|��D��_|durb�j�	dd�|��D��t
 232  t�j�����_dS)Nr�r�uUsing http2=True, but the 'h2' package is not installed. Make sure to install httpx using `pip install httpx[http2]`.�r�r�r�r�rrrc�:i|]\}}t|�|durdn�j|������d��qS�N)r�r�r�r�rr�r.�_init_proxy_transport�rPrQr��r�r�rrrgr�r�rArBr�������z#Client.__init__.<locals>.<dictcomp>cS�i|]	\}}t|�|�qSrA�r.�rPrQrrArArBr�����superrh�h2�ImportErrorr��_init_transport�
 233  _transportr��_mountsr�r��sorted)rgr�r�r�r�r�r�r�r�rr�rr�r�rr�r�r�rr�rr��	proxy_map��	__class__rrBrhsT�����	��zClient.__init__rcC� |dur|St||||||d�Sr�r�rgr�r�r�r�rrrrArArBr��
 234  �zClient._init_transportrc	C�t|||||||d�S�N)r�r�r�r�rrr�r!�rgr�r�r�r�r�rrrArArBr
 235  ��
 236  �zClient._init_proxy_transportr6r,cC�>|j��D]\}}|�|�r|dur|jS|Sq|jS�z�
 237          Returns the transport instance that should be used for a given URL.
 238          This will either be the standard connection pool, or a proxy.
 239          N�rr��matchesr�rgr6�patternrrArArB�_transport_for_url��
 240  
 241  �zClient._transport_for_url�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r��bool | UseClientDefaultr�r�r�rc
 242  CsL|	durd}tj|tdd�|j|||||||||	||
 243  d�}|j||
 244  |d�S)a�
 245          Build and send a request.
 246  
 247          Equivalent to:
 248  
 249          ```python
 250          request = client.build_request(...)
 251          response = client.send(request, ...)
 252          ```
 253  
 254          See `Client.build_request()`, `Client.send()` and
 255          [Merging of configuration][0] for how the various parameters
 256          are merged with client-level configuration.
 257  
 258          [0]: /advanced/clients/#merging-of-configuration
 259          N��Setting per-request cookies=<...> is being deprecated, because the expected behaviour on cookie persistence is ambiguous. Set cookies directly on the client instance instead.rT��
 260  stacklevel�r�r6r�r�r�r�r�r�r�r�r��r�r���warnings�warn�DeprecationWarningr��send�rgr�r6r�r�r�r�r�r�r�r�r�r�r��messager�rArArBr�s$!��
 261  zClient.request�typing.Iterator[Response]c
 262  csT�|j|||||||||	||
 263  d�}|j||
 264  |dd�}z
 265  |VW|��dS|��w�a
 266          Alternative to `httpx.request()` that streams the response body
 267          instead of loading it into memory at once.
 268  
 269          **Parameters**: See `httpx.request`.
 270  
 271          See also: [Streaming Responses][0]
 272  
 273          [0]: /quickstart#streaming-responses
 274          r5T)r�r�r�r[N)r�r;rv�rgr�r6r�r�r�r�r�r�r�r�r�r�r�r�r\rArArBr[;s.��
 275  �z
 276  Client.stream�r[r�r�r�rr[c
 277  Cs�|jtjkr
 278  td��tj|_t|t�r|jn|}|�|�|�	||�}|j
 279  |||gd�}z	|s3|��|WStyG}z|�
 280  �|�d}~ww)a�
 281          Send a request.
 282  
 283          The request is sent as-is, unmodified.
 284  
 285          Typically you'll want to build one with `Client.build_request()`
 286          so that any client-level configuration is merged into the request,
 287          but passing an explicit `httpx.Request()` is supported as well.
 288  
 289          See also: [Request instances][0]
 290  
 291          [0]: /advanced/clients/#request-instances
 292          �5Cannot send a request, as the client has been closed.�r�r��historyN)r�rSrX�RuntimeErrorrWr�rJr�r�r��_send_handling_auth�read�
 293  BaseExceptionrv�rgr�r[r�r�r\r�rArArBr;os0��
 294  ���zClient.sendrrD�list[Response]c	
 295  Cs�|�|�}zLt|�}	|j|||d�}z+z|�|�}Wnty,|YWW|��Swt|�|_|��|}|�	|�Wnt
 296  yP}z|��|�d}~wwq|��w�NT)r�rD)Zsync_auth_flow�next�_send_handling_redirectsr;�
 297  StopIterationrvr�rDrG�appendrH�	rgr�r�r�rDZ	auth_flowr\�next_requestr�rArArBrF�s6
 298  �
 299  
 300  �
 301  ���
 302  zClient._send_handling_authc
 303  Cs�	t|�|jkrtd|d��|jdD]}||�q|�|�}z1|jdD]}||�q%t|�|_|js7|WS|�||�}||g}|rI|�	�n||_
 304  |WSWntyb}z|��|�d}~wwq�NTz#Exceeded maximum allowed redirects.r�r�r\)
 305  �lenr�rr��_send_single_requestr�rD�has_redirect_locationr�rGrQrHrv�rgr�r�rD�hookr\r�rArArBrM�s6�
 306  
 307  
 308  
 309  
 310  
 311  ����zClient._send_handling_redirectscCs�|�|j�}t��}t|jt�std��t|d��
 312  |�	|�}Wd�n1s)wYt|jt�s6J�||_
 313  t|j||d�|_|j�
 314  |�|j|_t�d|j|j|j|j|j�|S)�L
 315          Sends a single request, without handling any redirections.
 316          z?Attempted to send an async request with a sync Client instance.r�N�r\r]�HTTP Request: %s %s "%s %d %s")r.r6rqrrr�r[r*rEr�handle_requestr�rZr��extract_cookiesr�r��logger�infor��http_versionr��
 317  reason_phrase�rgr�rr]r\rArArBrT�s2����	zClient._send_single_request�r�r�r�r�r�r�r�c	C�|jd||||||||d�	S)�U
 318          Send a `GET` request.
 319  
 320          **Parameters**: See `httpx.request`.
 321          r�rbr��	rgr6r�r�r�r�r�r�r�rArArBrF��z
 322  Client.get�AuthTypes | UseClientDefaultc	Crc)�Z
 323          Send an `OPTIONS` request.
 324  
 325          **Parameters**: See `httpx.request`.
 326          �OPTIONSrbr�rerArArB�options)rfzClient.optionsc	Crc)�V
 327          Send a `HEAD` request.
 328  
 329          **Parameters**: See `httpx.request`.
 330          r�rbr�rerArArB�headFrfzClient.headc
 331  C�$|jd|||||||||	|
 332  ||d�
 333  S)�V
 334          Send a `POST` request.
 335  
 336          **Parameters**: See `httpx.request`.
 337          r�r0r��
 338  rgr6r�r�r�r�r�r�r�r�r�r�r�rArArB�postc��zClient.postc
 339  Crm)�U
 340          Send a `PUT` request.
 341  
 342          **Parameters**: See `httpx.request`.
 343          �PUTr0r�rorArArB�put�rqz
 344  Client.putc
 345  Crm)�W
 346          Send a `PATCH` request.
 347  
 348          **Parameters**: See `httpx.request`.
 349          �PATCHr0r�rorArArB�patch�rqzClient.patchc	Crc)�X
 350          Send a `DELETE` request.
 351  
 352          **Parameters**: See `httpx.request`.
 353          �DELETErbr�rerArArB�delete�rfz
 354  Client.deletecCsF|jtjkrtj|_|j��|j��D]}|dur|��qdSdS�z.
 355          Close transport and proxies.
 356          N)r�rSrXrrvr�values)rgrrArArBrv�s
 357  ��zClient.closergr3cCs`|jtjkrtjdtjdi|j}t|��tj|_|j��|j�	�D]
 358  }|dur-|��q#|S�Nz-Cannot open a client instance more than once.z9Cannot reopen a client instance, once it has been closed.)
 359  r�rSrVrWrXrEr�	__enter__rr|)rg�msgrrArArBr~�s��
 360  �zClient.__enter__�exc_type�type[BaseException] | None�	exc_value�BaseException | None�	traceback�TracebackType | NonecCsBtj|_|j�|||�|j��D]
 361  }|dur|�|||�qdSra)rSrXr�r�__exit__rr|)rgr�r�r�rrArArBr�
 362  s��zClient.__exit__)(r�r�r�r�r�r�r�r�r�rr�rr�r9r�r9rr9r�r�rrr�r+r�r9rrr�r�r�r�r�r�rrr�r�r8r_)r�rr�rr�r9r�r9rr9rrrrr8r)r�rr�rr�rr�r9r�r9rr9rrr8r)r6r,r8r�r�r�r6r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r1r�r�r�r�r8r)r�r�r6r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r1r�r�r�r�r8r>�
 363  r�rr[r9r�r�r�r1r8r�
 364  r�rr�rr�r9rDrJr8r�r�rr�r9rDrJr8r�r�rr8r�r6r�r�r�r�r�r�r�r�r�r�r1r�r�r�r�r8r�r6r�r�r�r�r�r�r�r�rgr�r1r�r�r�r�r8r�r6r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rgr�r1r�r�r�r�r8rrx)rgr3r8r3�NNN�r�r�r�r�r�r�r8r_)rKrLrMrNr
 365  rrrhrr
 366  r.r0r�rr[r;rFrMrTrFrjrlrprtrwrzrvr~r��
 367  __classcell__rArArrBr2Rs /�Q��
 368  �8�7�
 369  3
 370  "
 371  %'�!�!�!�)�)�)�
 372  
 373  �cseZdZdZddddddddddedeedddddd�d|�fd-d.�Zdddddedfd}d0d1�Zdddddefd~d3d4�Z	dd7d8�Z
 374  dddddddeeedd9�d�dJdK�Ze
 375  dddddddeeedd9�d�dMdN��ZdeedO�d�dSdT�Zd�dXdY�Zd�dZd[�Zd�d\d]�Zdddeeedd^�d�d_d`�Zdddeeedd^�d�dbdc�Zdddeeedd^�d�ddde�Zdddddddeeedd9�d�dfdg�Zdddddddeeedd9�d�dhdi�Zdddddddeeedd9�d�djdk�Zdddeeedd^�d�dldm�Zd�dndo�Zd�drds�Z			d�d�dzd{�Z�ZS)�r1a�
 376      An asynchronous HTTP client, with connection pooling, HTTP/2, redirects,
 377      cookie persistence, etc.
 378  
 379      It can be shared between tasks.
 380  
 381      Usage:
 382  
 383      ```python
 384      >>> async with httpx.AsyncClient() as client:
 385      >>>     response = await client.get('https://example.org')
 386      ```
 387  
 388      **Parameters:**
 389  
 390      * **auth** - *(optional)* An authentication class to use when sending
 391      requests.
 392      * **params** - *(optional)* Query parameters to include in request URLs, as
 393      a string, dictionary, or sequence of two-tuples.
 394      * **headers** - *(optional)* Dictionary of HTTP headers to include when
 395      sending requests.
 396      * **cookies** - *(optional)* Dictionary of Cookie items to include when
 397      sending requests.
 398      * **verify** - *(optional)* Either `True` to use an SSL context with the
 399      default CA bundle, `False` to disable verification, or an instance of
 400      `ssl.SSLContext` to use a custom context.
 401      * **http2** - *(optional)* A boolean indicating if HTTP/2 support should be
 402      enabled. Defaults to `False`.
 403      * **proxy** - *(optional)* A proxy URL where all the traffic should be routed.
 404      * **timeout** - *(optional)* The timeout configuration to use when sending
 405      requests.
 406      * **limits** - *(optional)* The limits configuration to use.
 407      * **max_redirects** - *(optional)* The maximum number of redirect responses
 408      that should be followed.
 409      * **base_url** - *(optional)* A URL to use as the base when building
 410      request URLs.
 411      * **transport** - *(optional)* A transport class to use for sending requests
 412      over the network.
 413      * **trust_env** - *(optional)* Enables or disables usage of environment
 414      variables for configuration.
 415      * **default_encoding** - *(optional)* The default encoding to use for decoding
 416      response text, if no charset information is included in a response Content-Type
 417      header. Set to a callable for automatic character set detection. Default: "utf-8".
 418      NTFrr�)r�r�r�r�r�r�r�rr�rr�r�rr�r�r�rr�r�r�r�r�r�r�r�r�r�r�rr�rr�r9rr�r�r�5None | typing.Mapping[str, AsyncBaseTransport | None]r�r+r�rrr�r�r�r�r�r�r�AsyncBaseTransport | Noner�r�r�r8r_c
 419  s�t�j|||||||||�|d��r&zddl}Wnty%td�d�w�o+|du}��|	|�}�j������|d��_�������fdd�|��D��_|
 420  durb�j�	dd�|
 421  ��D��t
 422  t�j�����_dS)Nr�rrr	cr
 423  rrrrrArBr��rz(AsyncClient.__init__.<locals>.<dictcomp>cSrrArrrArArBr��rr)rgr�r�r�r�r�r�r�rr�rr�r�rr�r�r�rr�r�rr�rrrrBrhIsT�����
 424  ��zAsyncClient.__init__rcCr r�rr"rArArBr�r#zAsyncClient._init_transportrc	Cr$r%r�r&rArArBr
 425  �r'z!AsyncClient._init_proxy_transportr6r,cCr(r)r*r,rArArBr.�r/zAsyncClient._transport_for_urlr0r�r�r�r�r�r�r�r�r�r�r�r1r�r�r�rc
 426  �sT�|	durd}tj|tdd�|j|||||||||	||
 427  d�}|j||
 428  |d�IdHS)a�
 429          Build and send a request.
 430  
 431          Equivalent to:
 432  
 433          ```python
 434          request = client.build_request(...)
 435          response = await client.send(request, ...)
 436          ```
 437  
 438          See `AsyncClient.build_request()`, `AsyncClient.send()`
 439          and [Merging of configuration][0] for how the various parameters
 440          are merged with client-level configuration.
 441  
 442          [0]: /advanced/clients/#merging-of-configuration
 443          Nr2rTr3r5r6r7r<rArArBr��s&�"��
 444  zAsyncClient.request�typing.AsyncIterator[Response]c
 445  Csf�|j|||||||||	||
 446  d�}|j||
 447  |dd�IdH}z
 448  |VW|��IdHdS|��IdHwr?)r�r;r}r@rArArBr[s.��
 449  �"zAsyncClient.streamrAr�rr[c
 450  �s��|jtjkrtd��tj|_t|t�r|jn|}|�|�|�	||�}|j
 451  |||gd�IdH}z|s:|��IdH|WStyQ}z	|�
 452  �IdH|�d}~ww)a�
 453          Send a request.
 454  
 455          The request is sent as-is, unmodified.
 456  
 457          Typically you'll want to build one with `AsyncClient.build_request()`
 458          so that any client-level configuration is merged into the request,
 459          but passing an explicit `httpx.Request()` is supported as well.
 460  
 461          See also: [Request instances][0]
 462  
 463          [0]: /advanced/clients/#request-instances
 464          rBrCN)r�rSrXrErWr�rJr�r�r�rF�areadrHr}rIrArArBr;:s2���
 465  ���zAsyncClient.sendrrDrJc	
 466  �s��|�|�}z^|��IdH}	|j|||d�IdH}z4z
 467  |�|�IdH}Wnty9|YWW|��IdHSwt|�|_|��IdH|}|�	|�Wnt
 468  yc}z	|��IdH|�d}~wwq|��IdHwrK)Zasync_auth_flow�	__anext__rM�asend�StopAsyncIterationr}r�rDr�rOrHrPrArArBrFms8�
 469  �
 470  �
 471  ���zAsyncClient._send_handling_authc
 472  �s��	t|�|jkrtd|d��|jdD]	}||�IdHq|�|�IdH}z7|jdD]	}||�IdHq,t|�|_|jsA|WS|�||�}||g}|rV|�	�IdHn||_
 473  |WSWntyr}z	|��IdH|�d}~wwqrR)
 474  rSr�rr�rTr�rDrUr�r�rQrHr}rVrArArBrM�s8��
 475  
 476  ����z$AsyncClient._send_handling_redirectsc�s��|�|j�}t��}t|jt�std��t|d��|�	|�IdH}Wd�n1s-wYt|jt�s:J�||_
 477  t|j||d�|_|j�
 478  |�|j|_t�d|j|j|j|j|j�|S)rXz?Attempted to send an sync request with an AsyncClient instance.r�NrYrZ)r.r6rqrrr�r[rrErZhandle_async_requestr�rzr�r\r�r�r]r^r�r_r�r`rarArArBrT�s4�����	z AsyncClient._send_single_requestrbc	��$�|jd||||||||d�	IdHS)rdr�rbNr�rerArArBrF����zAsyncClient.getrgc	�r�)rhrirbNr�rerArArBrj�r�zAsyncClient.optionsc	�r�)rkr�rbNr�rerArArBrlr�zAsyncClient.headc
 479  ��,�|jd|||||||||	|
 480  ||d�
 481  IdHS)rnr�r0Nr�rorArArBrp.� ��zAsyncClient.postc
 482  �r�)rrrsr0Nr�rorArArBrtSr�zAsyncClient.putc
 483  �r�)rurvr0Nr�rorArArBrwxr�zAsyncClient.patchc	�r�)rxryrbNr�rerArArBrz�r�zAsyncClient.deletec�sT�|jtjkr&tj|_|j��IdH|j��D]}|dur%|��IdHqdSdSr{)r�rSrXrr}rr|)rgr�rArArBr}�s���zAsyncClient.aclosergr5c�sn�|jtjkrtjdtjdi|j}t|��tj|_|j��IdH|j�	�D]
 484  }|dur4|��IdHq'|Sr})
 485  r�rSrVrWrXrEr�
 486  __aenter__rr|)rgrr�rArArBr��s ����zAsyncClient.__aenter__r�r�r�r�r�r�c�sP�tj|_|j�|||�IdH|j��D]}|dur%|�|||�IdHqdSra)rSrXr�r�	__aexit__rr|)rgr�r�r�r�rArArBr��s���zAsyncClient.__aexit__)(r�r�r�r�r�r�r�r�r�rr�rr�r9rr9r�r�rr�r�r+r�r9rrr�r�r�r�r�r�rr�r�r9r�r�r8r_)r�rr�rr�r9r�r9rr9rrrr�r8r)r�rr�rr�rr�r9r�r9rr9rrr8r)r6r,r8rr�)r�r�r6r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r1r�r�r�r�r8r�r�r�r�r�r�r�r�rx)rgr5r8r5r�r�)rKrLrMrNr
 487  rrrhrr
 488  r.r0r�rr[r;rFrMrTrFrjrlrprtrwrzr}r�r�r�rArArrBr1s 0�Q��
 489  �9�7�
 490  3
 491  "
 492  &&�!�!�!�)�)�)�
 493  
 494  �)r6r,r7r,r8r9)r6r,r8rD)r6r,rHr,r8r9)\�
 495  __future__rrs�enum�loggingrq�typingr8�
 496  contextlibrr�typesrrr�rr	r
 497  �_configrrr
 498  rrr�	_decodersr�_exceptionsrrrrZ_modelsrrrrZ
 499  _status_codesrZ_transports.baserrZ_transports.defaultrr�_typesrr r!r"r#r$r%r&r'r(r)r*r+Z_urlsr,r-�_utilsr.r/�
 500  TYPE_CHECKING�ssl�__all__�TypeVarr3r5rCr@rIrJr0�	getLoggerr]r�r��keysr��EnumrSrZrz�Callable�AnyZ	EventHookr~r2r1rArArArB�<module>sf <
 501  
 502  
 503  
 504  
 505  �N