o
    Zh                    @  sT  d dl mZ d dlZd dlZd dlZd dlZd dlZd dlmZm	Z	 d dl
mZ ddlmZ ddlmZmZmZ ddlmZmZmZmZmZmZ dd	lmZ dd
lmZmZmZmZ ddlm Z m!Z!m"Z"m#Z# ddl$m%Z% ddl&m'Z' ddl(m)Z)m*Z* ddl+m,Z,m-Z- ddl.m/Z/ ddl0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@ ddlAmBZBmCZC ddlDmEZEmFZFmGZGmHZHmIZI ejJdddZKejJdddZLG dd dZMeM ZNeOdZPde ZQdRdd eS D ZTG d d! d!ejUZVG d"d# d#e=ZWG d$d% d%e1ZXejYd&ejZf Z[G d'd( d(Z\G d)d de\Z]G d*d de\Z^dS )+    )annotationsN)asynccontextmanagercontextmanager)TracebackType   )__version__)Auth	BasicAuthFunctionAuth)DEFAULT_LIMITSDEFAULT_MAX_REDIRECTSDEFAULT_TIMEOUT_CONFIGLimitsProxyTimeout)SUPPORTED_DECODERS)
InvalidURLRemoteProtocolErrorTooManyRedirectsrequest_context)CookiesHeadersRequestResponse)codes)ASGITransport)AsyncBaseTransportBaseTransport)AsyncHTTPTransportHTTPTransport)WSGITransport)AsyncByteStream	AuthTypes	CertTypesCookieTypesHeaderTypesProxiesTypes
ProxyTypesQueryParamTypesRequestContentRequestDataRequestExtensionsRequestFilesSyncByteStreamTimeoutTypesURLTypesVerifyTypes)URLQueryParams)Timer
URLPatternget_environment_proxiesis_https_redirectsame_originTClient)boundUAsyncClientc                   @  s   e Zd ZdZdS )UseClientDefaulta<  
    For some parameters such as `auth=...` and `timeout=...` we need to be able
    to indicate the default "unset" state, in a way that is distinctly different
    to using `None`.

    The default "unset" state indicates that whatever default is set on the
    client should be used. This is different to setting `None`, which
    explicitly disables the parameter, possibly overriding a client default.

    For example we use `timeout=USE_CLIENT_DEFAULT` in the `request()` signature.
    Omitting the `timeout` parameter will send a request using whatever default
    timeout has been configured on the client. Including `timeout=None` will
    ensure no timeout is used.

    Note that user code shouldn't need to use the `USE_CLIENT_DEFAULT` constant,
    but it is used internally when a parameter is not included.
    N)__name__
__module____qualname____doc__ rB   rB   D/var/www/html/lang_env/lib/python3.10/site-packages/httpx/_client.pyr=   C   s    r=   Zhttpxzpython-httpx/z, c                 C  s   g | ]}|d kr|qS )identityrB   ).0keyrB   rB   rC   
<listcomp>^   s    rG   c                   @  s   e Zd ZdZdZdZdS )ClientStater         N)r>   r?   r@   UNOPENEDOPENEDCLOSEDrB   rB   rB   rC   rH   b   s    rH   c                   @  .   e Zd ZdZdd
dZdddZdddZdS )BoundSyncStreamz
    A byte stream that is bound to a given response instance, and that
    ensures the `response.elapsed` is set once the response is closed.
    streamr-   responser   timerr3   returnNonec                 C     || _ || _|| _d S N_stream	_response_timerselfrP   rQ   rR   rB   rB   rC   __init__v      
zBoundSyncStream.__init__typing.Iterator[bytes]c                 c  s    | j D ]}|V  qd S rV   rX   r\   chunkrB   rB   rC   __iter__}   s   
zBoundSyncStream.__iter__c                 C  s(   | j  }tj|d| j_| j  d S N)seconds)rZ   Zsync_elapseddatetime	timedeltarY   elapsedrX   closer\   re   rB   rB   rC   ri      s   
zBoundSyncStream.closeN)rP   r-   rQ   r   rR   r3   rS   rT   )rS   r_   rS   rT   )r>   r?   r@   rA   r]   rc   ri   rB   rB   rB   rC   rO   p   
    

rO   c                   @  rN   )BoundAsyncStreamz
    An async byte stream that is bound to a given response instance, and that
    ensures the `response.elapsed` is set once the response is closed.
    rP   r!   rQ   r   rR   r3   rS   rT   c                 C  rU   rV   rW   r[   rB   rB   rC   r]      r^   zBoundAsyncStream.__init__typing.AsyncIterator[bytes]c                 C s"   | j 2 z	3 d H W }|V  q6 d S rV   r`   ra   rB   rB   rC   	__aiter__   s   zBoundAsyncStream.__aiter__c                   s6   | j  I d H }tj|d| j_| j I d H  d S rd   )rZ   Zasync_elapsedrf   rg   rY   rh   rX   acloserj   rB   rB   rC   rp      s   zBoundAsyncStream.acloseN)rP   r!   rQ   r   rR   r3   rS   rT   )rS   rn   rk   )r>   r?   r@   rA   r]   ro   rp   rB   rB   rB   rC   rm      rl   rm   .c                   @  s  e Zd ZddddededdddddzddZed{d d!Zed{d"d#Zd|d&d'Z	d}d,d-Z
ed~d/d0Zejdd1d0Zedd3d4Zejdd5d4Zedd7d8Zejdd:d8Zedd;d<Zejdd=d<Zedd?d@ZejddBd@ZeddDdEZejddGdEZeddIdJZejddLdJZdddddddeddM	dd\d]Zdd^d_Zddd`daZdddbdcZ	dddddeZddfdgZefddkdlZddodpZddqdrZddsdtZddudvZddxdyZdS )
BaseClientNF Tutf-8authparamsheaderscookiestimeoutfollow_redirectsmax_redirectsevent_hooksbase_url	trust_envdefault_encodingru   AuthTypes | Nonerv   QueryParamTypes | Nonerw   HeaderTypes | Nonerx   CookieTypes | Nonery   r.   rz   boolr{   intr|   +None | typing.Mapping[str, list[EventHook]]r}   r/   r~   r   #str | typing.Callable[[bytes], str]rS   rT   c                C  s   |d u ri n|}|  t|	| _| || _t|| _t|| _t	|| _
t|| _|| _|| _t|dg t|dg d| _|
| _|| _tj| _d S NrequestrQ   )r   rQ   )_enforce_trailing_slashr1   	_base_url_build_auth_authr2   _paramsr   rw   r   _cookiesr   _timeoutrz   r{   listget_event_hooks
_trust_env_default_encodingrH   rK   _state)r\   ru   rv   rw   rx   ry   rz   r{   r|   r}   r~   r   rB   rB   rC   r]      s   



zBaseClient.__init__c                 C  s   | j tjkS )z2
        Check if the client being closed
        )r   rH   rM   r\   rB   rB   rC   	is_closed   s   zBaseClient.is_closedc                 C     | j S rV   )r   r   rB   rB   rC   r~         zBaseClient.trust_envurlr1   c                 C  s"   |j dr|S |j|j d dS )N   /raw_path)r   endswith	copy_withr\   r   rB   rB   rC   r      s   z"BaseClient._enforce_trailing_slashproxiesProxiesTypes | Noneallow_env_proxiesdict[str, Proxy | None]c                 C  s   |d u r|rdd t   D S i S t|tr8i }| D ]\}}t|ttfr-t|dn|}||t|< q|S t|ttfrDt|dn|}d|iS )Nc                 S  s(   i | ]\}}||d u rd nt |dqS )Nr   )r   )rE   rF   r   rB   rB   rC   
<dictcomp>   s    z-BaseClient._get_proxy_map.<locals>.<dictcomp>r   zall://)r5   items
isinstancedictstrr1   r   )r\   r   r   new_proxiesrF   valueproxyrB   rB   rC   _get_proxy_map   s   
zBaseClient._get_proxy_mapr   c                 C  r   rV   )r   r   rB   rB   rC   ry      r   zBaseClient.timeoutc                 C     t || _d S rV   )r   r   )r\   ry   rB   rB   rC   ry         dict[str, list[EventHook]]c                 C  r   rV   )r   r   rB   rB   rC   r|      r   zBaseClient.event_hooksc                 C  s(   t |dg t |dg d| _d S r   )r   r   r   )r\   r|   rB   rB   rC   r|      s   Auth | Nonec                 C  r   )z
        Authentication class used when none is passed at the request-level.

        See also [Authentication][0].

        [0]: /quickstart/#authentication
        )r   r   rB   rB   rC   ru      s   	zBaseClient.authr"   c                 C  s   |  || _d S rV   )r   r   r\   ru   rB   rB   rC   ru     s   c                 C  r   )zK
        Base URL to use when sending requests with relative URLs.
        )r   r   rB   rB   rC   r}   
     zBaseClient.base_urlc                 C  s   |  t|| _d S rV   )r   r1   r   r   rB   rB   rC   r}     s   r   c                 C  r   )z@
        HTTP headers to include when sending requests.
        )_headersr   rB   rB   rC   rw     r   zBaseClient.headersr%   c                 C  s2   t dtddtdd}|| || _d S )Ns   */*asciis
   keep-alive)s   Accepts   Accept-Encodings
   Connections
   User-Agent)r   ACCEPT_ENCODINGencode
USER_AGENTupdater   )r\   rw   Zclient_headersrB   rB   rC   rw     s   

r   c                 C  r   )zA
        Cookie values to include when sending requests.
        )r   r   rB   rB   rC   rx   )  r   zBaseClient.cookiesr$   c                 C  r   rV   )r   r   )r\   rx   rB   rB   rC   rx   0  r   r2   c                 C  r   )zO
        Query parameters to include in the URL when sending requests.
        )r   r   rB   rB   rC   rv   4  r   zBaseClient.paramsr(   c                 C  r   rV   )r2   r   )r\   rv   rB   rB   rC   rv   ;  r   )	contentdatafilesjsonrv   rw   rx   ry   
extensionsmethodr   r   RequestContent | Noner   RequestData | Noner   RequestFiles | Noner   typing.Any | NoneTimeoutTypes | UseClientDefaultr   RequestExtensions | Noner   c       	         C  s   |  |}| |}| |	}	| |}|du ri n|}d|vr9t|
tr(| jnt|
}
tdi |d|
	 i}t
|||||||||	|d
S )aJ  
        Build and return a request instance.

        * The `params`, `headers` and `cookies` arguments
        are merged with any values set on the client.
        * The `url` argument is merged with any `base_url` set on the client.

        See also: [Request instances][0]

        [0]: /advanced/#request-instances
        Nry   )r   r   r   r   rv   rw   rx   r   rB   )
_merge_url_merge_headers_merge_cookies_merge_queryparamsr   r=   ry   r   r   as_dictr   )r\   r   r   r   r   r   r   rv   rw   rx   ry   r   rB   rB   rC   build_request?  s.   



zBaseClient.build_requestc                 C  s4   t |}|jr| jj|jd }| jj|dS |S )z
        Merge a URL argument together with any 'base_url' on the client,
        to create the URL used for the outgoing request.
        r   r   )r1   is_relative_urlr}   r   lstripr   )r\   r   Z	merge_urlZmerge_raw_pathrB   rB   rC   r   r  s
   zBaseClient._merge_urlc                 C  s&   |s| j rt| j }|| |S |S )z
        Merge a cookies argument together with any cookies on the client,
        to create the cookies used for the outgoing request.
        )rx   r   r   )r\   rx   merged_cookiesrB   rB   rC   r     s
   


zBaseClient._merge_cookiesc                 C  s   t | j}|| |S )z
        Merge a headers argument together with any headers on the client,
        to create the headers used for the outgoing request.
        )r   rw   r   )r\   rw   Zmerged_headersrB   rB   rC   r     s   

zBaseClient._merge_headersc                 C  s"   |s| j rt| j }||S |S )z
        Merge a queryparams argument together with any queryparams on the client,
        to create the queryparams used for the outgoing request.
        )rv   r2   merge)r\   rv   Zmerged_queryparamsrB   rB   rC   r     s   


zBaseClient._merge_queryparamsc                 C  sX   |d u rd S t |trt|d |d dS t |tr|S t|r%t|dS td|)Nr   r   usernamepassword)funczInvalid "auth" argument: )r   tupler	   r   callabler
   	TypeErrorr   rB   rB   rC   r     s   


zBaseClient._build_authr   #AuthTypes | UseClientDefault | Noner   c                 C  sR   t |tr| jn| |}|d ur|S |jj|jj}}|s |r&t||dS t S )Nr   )	r   r=   r   r   r   r   r   r	   r   )r\   r   ru   r   r   rB   rB   rC   _build_request_auth  s   zBaseClient._build_request_authrQ   r   c                 C  sR   |  ||}| ||}| |||}| ||}t| j}t||||||jdS )z
        Given a request and a redirect response, return a new request that
        should be used to effect the redirect.
        )r   r   rw   rx   rP   r   )_redirect_method_redirect_url_redirect_headers_redirect_streamr   rx   r   r   )r\   r   rQ   r   r   rw   rP   rx   rB   rB   rC   _build_redirect_request  s   
z"BaseClient._build_redirect_requestc                 C  sR   |j }|jtjkr|dkrd}|jtjkr|dkrd}|jtjkr'|dkr'd}|S )z
        When being redirected we may want to change the method of the request
        based on certain specs or browser behavior.
        HEADGETPOST)r   status_coder   	SEE_OTHERFOUNDMOVED_PERMANENTLY)r\   r   rQ   r   rB   rB   rC   r     s   zBaseClient._redirect_methodc              
   C  s   |j d }zt|}W n ty" } ztd| d|ddd}~ww |jr1|js1|j|jjd}|jr:|j	|}|jj
rI|j
sI|j|jj
d}|S )z<
        Return the URL for the redirect to follow.
        ZLocationz Invalid URL in location header: .r   N)host)fragment)rw   r1   r   r   schemer   r   r   r   joinr   )r\   r   rQ   locationr   excrB   rB   rC   r     s$   
zBaseClient._redirect_urlc                 C  sx   t |j}t||jst|j|s|dd |jd|d< ||jkr4|dkr4|dd |dd |dd |S )	zR
        Return the headers that should be used for the redirect request.
        AuthorizationNr   Hostr   zContent-LengthzTransfer-EncodingCookie)	r   rw   r7   r   r6   popnetlocdecoder   )r\   r   r   r   rw   rB   rB   rC   r     s   
zBaseClient._redirect_headers'SyncByteStream | AsyncByteStream | Nonec                 C  s   ||j kr|dkrdS |jS )zO
        Return the body that should be used for the redirect request.
        r   N)r   rP   )r\   r   r   rB   rB   rC   r   (  s   zBaseClient._redirect_stream)ru   r   rv   r   rw   r   rx   r   ry   r.   rz   r   r{   r   r|   r   r}   r/   r~   r   r   r   rS   rT   )rS   r   )r   r1   rS   r1   )r   r   r   r   rS   r   )rS   r   )ry   r.   rS   rT   )rS   r   )r|   r   rS   rT   )rS   r   )ru   r"   rS   rT   )rS   r1   )r   r/   rS   rT   )rS   r   )rw   r%   rS   rT   )rS   r   )rx   r$   rS   rT   )rS   r2   )rv   r(   rS   rT   )r   r   r   r/   r   r   r   r   r   r   r   r   rv   r   rw   r   rx   r   ry   r   r   r   rS   r   )r   r/   rS   r1   rV   )rx   r   rS   r   )rw   r   rS   r   )rv   r   rS   r   )ru   r   rS   r   )r   r   ru   r   rS   r   )r   r   rQ   r   rS   r   )r   r   rQ   r   rS   r   )r   r   rQ   r   rS   r1   )r   r   r   r1   r   r   rS   r   )r   r   r   r   rS   r   ) r>   r?   r@   r   r   r]   propertyr   r~   r   r   ry   setterr|   ru   r}   rw   rx   rv   USE_CLIENT_DEFAULTr   r   r   r   r   r   r   r   r   r   r   r   rB   rB   rB   rC   rq      s    "



3





rq   c                      s  e Zd ZdZdddddddddddedeedddddddd fd1d2Zddddedddfdd4d5Zddddedfdd7d8Z	dd;d<Z
dddddddeeedd=ddNdOZedddddddeeedd=ddQdRZdeedSddWdXZdd\d]Zdd^d_Zdd`daZdddeeeddbddddeZdddeeeddbddfdgZdddeeeddbddhdiZdddddddeeedd=ddjdkZdddddddeeedd=ddldmZdddddddeeedd=ddndoZdddeeeddbddpdqZddrdsZddvdwZ			ddd~dZ  ZS )r9   a	  
    An HTTP client, with connection pooling, HTTP/2, redirects, cookie persistence, etc.

    It can be shared between threads.

    Usage:

    ```python
    >>> client = httpx.Client()
    >>> response = client.get('https://example.org')
    ```

    **Parameters:**

    * **auth** - *(optional)* An authentication class to use when sending
    requests.
    * **params** - *(optional)* Query parameters to include in request URLs, as
    a string, dictionary, or sequence of two-tuples.
    * **headers** - *(optional)* Dictionary of HTTP headers to include when
    sending requests.
    * **cookies** - *(optional)* Dictionary of Cookie items to include when
    sending requests.
    * **verify** - *(optional)* SSL certificates (a.k.a CA bundle) used to
    verify the identity of requested hosts. Either `True` (default CA bundle),
    a path to an SSL certificate file, an `ssl.SSLContext`, or `False`
    (which will disable verification).
    * **cert** - *(optional)* An SSL certificate used by the requested host
    to authenticate the client. Either a path to an SSL certificate file, or
    two-tuple of (certificate file, key file), or a three-tuple of (certificate
    file, key file, password).
    * **http2** - *(optional)* A boolean indicating if HTTP/2 support should be
    enabled. Defaults to `False`.
    * **proxy** - *(optional)* A proxy URL where all the traffic should be routed.
    * **proxies** - *(optional)* A dictionary mapping proxy keys to proxy
    URLs.
    * **timeout** - *(optional)* The timeout configuration to use when sending
    requests.
    * **limits** - *(optional)* The limits configuration to use.
    * **max_redirects** - *(optional)* The maximum number of redirect responses
    that should be followed.
    * **base_url** - *(optional)* A URL to use as the base when building
    request URLs.
    * **transport** - *(optional)* A transport class to use for sending requests
    over the network.
    * **app** - *(optional)* An WSGI application to send requests to,
    rather than sending actual network requests.
    * **trust_env** - *(optional)* Enables or disables usage of environment
    variables for configuration.
    * **default_encoding** - *(optional)* The default encoding to use for decoding
    response text, if no charset information is included in a response Content-Type
    header. Set to a callable for automatic character set detection. Default: "utf-8".
    NTFrr   rs   ru   rv   rw   rx   verifycerthttp1http2r   r   mountsry   rz   limitsr{   r|   r}   	transportappr~   r   ru   r   rv   r   rw   r   rx   r   r   r0   r   CertTypes | Noner   r   r   r   ProxyTypes | Noner   r   r   0None | typing.Mapping[str, BaseTransport | None]ry   r.   rz   r   r   r{   r   r|   r   r}   r/   r   BaseTransport | Noner  'typing.Callable[..., typing.Any] | Noner~   r   r   rS   rT   c                  s  t  j||||||||||d r&zdd l}W n ty%   tdd w |
r6d}t|t |	r6td|r@d}t|t oI|d u oI|d u }|
pO|	|}j	 ||d_
 fdd	| D _|d urjd
d	 | D  ttj _d S )Nrt   r   uUsing http2=True, but the 'h2' package is not installed. Make sure to install httpx using `pip install httpx[http2]`.JThe 'proxies' argument is now deprecated. Use 'proxy' or 'mounts' instead.*Use either `proxy` or 'proxies', not both.zhThe 'app' shortcut is now deprecated. Use the explicit style 'transport=WSGITransport(app=...)' instead.r   r   r   r   r   r   r  r~   c                   :   i | ]\}}t ||d u rd nj| dqS Nr   r   r   r   r   r~   r4   _init_proxy_transportrE   rF   r   r   r   r   r   r\   r~   r   rB   rC   r         z#Client.__init__.<locals>.<dictcomp>c                 S     i | ]	\}}t ||qS rB   r4   rE   rF   r   rB   rB   rC   r         superr]   h2ImportErrorwarningswarnDeprecationWarningRuntimeErrorr   _init_transport
_transportr   _mountsr   r   sortedr\   ru   rv   rw   rx   r   r   r   r   r   r   r   ry   rz   r   r{   r|   r}   r   r  r~   r   r  messager   Z	proxy_map	__class__r  rC   r]   j  sj   
zClient.__init__r   c	           	      C  2   |d ur|S |d urt |dS t||||||dS N)r  r  )r    r   	r\   r   r   r   r   r   r   r  r~   rB   rB   rC   r       
zClient._init_transportr   c              	   C     t |||||||dS N)r   r   r   r   r   r~   r   )r   r\   r   r   r   r   r   r   r~   rB   rB   rC   r       
zClient._init_proxy_transportr   r1   c                 C  >   | j  D ]\}}||r|du r| j  S |  S q| jS z
        Returns the transport instance that should be used for a given URL.
        This will either be the standard connection pool, or a proxy.
        Nr!  r   matchesr   r\   r   patternr   rB   rB   rC   _transport_for_url  
   
zClient._transport_for_urlr   r   r   r   rv   rw   rx   ru   rz   ry   r   r   r   r   r   r   r   r   r   r   r   r   bool | UseClientDefaultr   r   r   r   c                C  sH   |	durd}t |t | j|||||||||	||d}| j||
|dS )a  
        Build and send a request.

        Equivalent to:

        ```python
        request = client.build_request(...)
        response = client.send(request, ...)
        ```

        See `Client.build_request()`, `Client.send()` and
        [Merging of configuration][0] for how the various parameters
        are merged with client-level configuration.

        [0]: /advanced/#merging-of-configuration
        NSetting per-request cookies=<...> is being deprecated, because the expected behaviour on cookie persistence is ambiguous. Set cookies directly on the client instance instead.r   r   r   r   r   r   rv   rw   rx   ry   r   ru   rz   r  r  r  r   sendr\   r   r   r   r   r   r   rv   rw   rx   ru   rz   ry   r   r$  r   rB   rB   rC   r     s$   !zClient.requesttyping.Iterator[Response]c                c  sT    | j |||||||||	||d}| j||
|dd}z
|V  W |  dS |  w a  
        Alternative to `httpx.request()` that streams the response body
        instead of loading it into memory at once.

        **Parameters**: See `httpx.request`.

        See also: [Streaming Responses][0]

        [0]: /quickstart#streaming-responses
        r:  T)r   ru   rz   rP   N)r   r=  ri   r\   r   r   r   r   r   r   rv   rw   rx   ru   rz   ry   r   r   rQ   rB   rB   rC   rP   =  s.   zClient.streamrP   ru   rz   r   r   rP   c             
   C  s   | j tjkr
tdtj| _ t|tr| jn|}| ||}| j	|||g d}z	|s.|
  |W S  tyB } z|  |d}~ww )a  
        Send a request.

        The request is sent as-is, unmodified.

        Typically you'll want to build one with `Client.build_request()`
        so that any client-level configuration is merged into the request,
        but passing an explicit `httpx.Request()` is supported as well.

        See also: [Request instances][0]

        [0]: /advanced/#request-instances
        5Cannot send a request, as the client has been closed.ru   rz   historyN)r   rH   rM   r  rL   r   r=   rz   r   _send_handling_authreadBaseExceptionri   r\   r   rP   ru   rz   rQ   r   rB   rB   rC   r=  q  s.   zClient.sendr   rE  list[Response]c           	   
   C  s   | |}zLt|}	 | j|||d}z+z||}W n ty,   | Y W W |  S w t||_|  |}|	| W n t
yP } z|  |d }~ww q|  w NT)rz   rE  )Zsync_auth_flownext_send_handling_redirectsr=  StopIterationri   r   rE  rG  appendrH  	r\   r   ru   rz   rE  Z	auth_flowrQ   next_requestr   rB   rB   rC   rF    s6   




zClient._send_handling_authc              
   C  s   	 t || jkrtd|d| jd D ]}|| q| |}z1| jd D ]}|| q%t||_|js7|W S | ||}||g }|rI|	  n||_
|W S W n tyb } z|  |d }~ww qNTz#Exceeded maximum allowed redirects.r   r   rQ   )lenr{   r   r   _send_single_requestr   rE  has_redirect_locationr   rG  rQ  rH  ri   r\   r   rz   rE  hookrQ   r   rB   rB   rC   rM    s6   





zClient._send_handling_redirectsc                 C  s   |  |j}t }|  t|jtstdt|d |	|}W d   n1 s,w   Y  t|jts9J ||_
t|j||d|_| j| | j|_td|j|j|j|j|j |S )L
        Sends a single request, without handling any redirections.
        z?Attempted to send an async request with a sync Client instance.r   NrQ   rR   HTTP Request: %s %s "%s %d %s")r5  r   r3   Z
sync_startr   rP   r-   r  r   handle_requestr   rO   rx   extract_cookiesr   r   loggerinfor   http_versionr   reason_phraser\   r   r   rR   rQ   rB   rB   rC   rT    s4   	zClient._send_single_requestrv   rw   rx   ru   rz   ry   r   AuthTypes | UseClientDefaultc          	      C     | j d||||||||d	S )U
        Send a `GET` request.

        **Parameters**: See `httpx.request`.
        r   rb  r   	r\   r   rv   rw   rx   ru   rz   ry   r   rB   rB   rC   r        z
Client.getc          	      C  rd  )Z
        Send an `OPTIONS` request.

        **Parameters**: See `httpx.request`.
        OPTIONSrb  r   rf  rB   rB   rC   options*  rg  zClient.optionsc          	      C  rd  )V
        Send a `HEAD` request.

        **Parameters**: See `httpx.request`.
        r   rb  r   rf  rB   rB   rC   headG  rg  zClient.headc                C  $   | j d|||||||||	|
||dS )V
        Send a `POST` request.

        **Parameters**: See `httpx.request`.
        r   r7  r   r\   r   r   r   r   r   rv   rw   rx   ru   rz   ry   r   rB   rB   rC   postd     zClient.postc                C  rm  )U
        Send a `PUT` request.

        **Parameters**: See `httpx.request`.
        PUTr7  r   ro  rB   rB   rC   put  rq  z
Client.putc                C  rm  )W
        Send a `PATCH` request.

        **Parameters**: See `httpx.request`.
        PATCHr7  r   ro  rB   rB   rC   patch  rq  zClient.patchc          	      C  rd  )X
        Send a `DELETE` request.

        **Parameters**: See `httpx.request`.
        DELETErb  r   rf  rB   rB   rC   delete  rg  zClient.deletec                 C  sF   | j tjkrtj| _ | j  | j D ]}|dur|  qdS dS z.
        Close transport and proxies.
        N)r   rH   rM   r   ri   r!  values)r\   r   rB   rB   rC   ri     s   
zClient.closer\   r8   c                 C  s`   | j tjkrtjdtjdi| j  }t|tj| _ | j  | j	 D ]
}|d ur-|  q#| S Nz-Cannot open a client instance more than once.z9Cannot reopen a client instance, once it has been closed.)
r   rH   rK   rL   rM   r  r   	__enter__r!  r|  )r\   msgr   rB   rB   rC   r~    s   
zClient.__enter__exc_typetype[BaseException] | None	exc_valueBaseException | None	tracebackTracebackType | Nonec                 C  sB   t j| _| j||| | j D ]}|d ur|||| qd S rV   )rH   rM   r   r   __exit__r!  r|  )r\   r  r  r  r   rB   rB   rC   r    s   zClient.__exit__),ru   r   rv   r   rw   r   rx   r   r   r0   r   r  r   r   r   r   r   r  r   r   r   r  ry   r.   rz   r   r   r   r{   r   r|   r   r}   r/   r   r  r  r  r~   r   r   r   rS   rT   )r   r0   r   r  r   r   r   r   r   r   r   r  r  r  r~   r   rS   r   )r   r   r   r0   r   r  r   r   r   r   r   r   r~   r   rS   r   )r   r1   rS   r   r   r   r   r/   r   r   r   r   r   r   r   r   rv   r   rw   r   rx   r   ru   r   rz   r8  ry   r   r   r   rS   r   )r   r   r   r/   r   r   r   r   r   r   r   r   rv   r   rw   r   rx   r   ru   r   rz   r8  ry   r   r   r   rS   r?  
r   r   rP   r   ru   r   rz   r8  rS   r   
r   r   ru   r   rz   r   rE  rJ  rS   r   r   r   rz   r   rE  rJ  rS   r   r   r   rS   r   r   r/   rv   r   rw   r   rx   r   ru   rc  rz   r8  ry   r   r   r   rS   r   r   r/   r   r   r   r   r   r   r   r   rv   r   rw   r   rx   r   ru   rc  rz   r8  ry   r   r   r   rS   r   rk   )r\   r8   rS   r8   NNNr  r  r  r  r  r  rS   rT   )r>   r?   r@   rA   r   r   r   r]   r  r  r5  r   r   r   rP   r=  rF  rM  rT  r   rj  rl  rp  rt  rw  rz  ri   r~  r  __classcell__rB   rB   r%  rC   r9   4  s&   8d
87
1
"
%(!!!)))

c                      s  e Zd ZdZdddddddddddedeedddddddd fd1d2Zddddedddfdd4d5Zddddedfdd7d8Z	dd;d<Z
dddddddeeedd=ddNdOZedddddddeeedd=ddRdSZdeedTddXdYZdd]d^Zdd_d`ZddadbZdddeeeddcddddeZdddeeeddcddfdgZdddeeeddcddhdiZdddddddeeedd=ddjdkZdddddddeeedd=ddldmZdddddddeeedd=ddndoZdddeeeddcddpdqZddrdsZddvdwZ			ddd~dZ  ZS )r<   a	  
    An asynchronous HTTP client, with connection pooling, HTTP/2, redirects,
    cookie persistence, etc.

    It can be shared between tasks.

    Usage:

    ```python
    >>> async with httpx.AsyncClient() as client:
    >>>     response = await client.get('https://example.org')
    ```

    **Parameters:**

    * **auth** - *(optional)* An authentication class to use when sending
    requests.
    * **params** - *(optional)* Query parameters to include in request URLs, as
    a string, dictionary, or sequence of two-tuples.
    * **headers** - *(optional)* Dictionary of HTTP headers to include when
    sending requests.
    * **cookies** - *(optional)* Dictionary of Cookie items to include when
    sending requests.
    * **verify** - *(optional)* SSL certificates (a.k.a CA bundle) used to
    verify the identity of requested hosts. Either `True` (default CA bundle),
    a path to an SSL certificate file, an `ssl.SSLContext`, or `False`
    (which will disable verification).
    * **cert** - *(optional)* An SSL certificate used by the requested host
    to authenticate the client. Either a path to an SSL certificate file, or
    two-tuple of (certificate file, key file), or a three-tuple of (certificate
    file, key file, password).
    * **http2** - *(optional)* A boolean indicating if HTTP/2 support should be
    enabled. Defaults to `False`.
    * **proxy** - *(optional)* A proxy URL where all the traffic should be routed.
    * **proxies** - *(optional)* A dictionary mapping HTTP protocols to proxy
    URLs.
    * **timeout** - *(optional)* The timeout configuration to use when sending
    requests.
    * **limits** - *(optional)* The limits configuration to use.
    * **max_redirects** - *(optional)* The maximum number of redirect responses
    that should be followed.
    * **base_url** - *(optional)* A URL to use as the base when building
    request URLs.
    * **transport** - *(optional)* A transport class to use for sending requests
    over the network.
    * **app** - *(optional)* An ASGI application to send requests to,
    rather than sending actual network requests.
    * **trust_env** - *(optional)* Enables or disables usage of environment
    variables for configuration.
    * **default_encoding** - *(optional)* The default encoding to use for decoding
    response text, if no charset information is included in a response Content-Type
    header. Set to a callable for automatic character set detection. Default: "utf-8".
    NTFrr   rs   r   ru   r   rv   r   rw   r   rx   r   r   r0   r   r  r   r   r   r   r  r   r   r   5None | typing.Mapping[str, AsyncBaseTransport | None]ry   r.   rz   r   r   r{   r   r|   BNone | typing.Mapping[str, list[typing.Callable[..., typing.Any]]]r}   r/   r   AsyncBaseTransport | Noner  r  r~   r   r   rS   rT   c                  s  t  j||||||||||d r&zdd l}W n ty%   tdd w |
r6d}t|t |	r6td|r@d}t|t oE|d u }|
pK|	|}j	 ||d_
 fdd	| D _|d urjd
d	 | D  ttj _d S )Nrt   r   r  r  r	  zhThe 'app' shortcut is now deprecated. Use the explicit style 'transport=ASGITransport(app=...)' instead.r
  c                   r  r  r  r  r  rB   rC   r     r  z(AsyncClient.__init__.<locals>.<dictcomp>c                 S  r  rB   r  r  rB   rB   rC   r     r  r  r#  r%  r  rC   r]   S  sj   zAsyncClient.__init__r   c	           	      C  r'  r(  )r   r   r)  rB   rB   rC   r    r*  zAsyncClient._init_transportr   c              	   C  r+  r,  )r   r-  rB   rB   rC   r    r.  z!AsyncClient._init_proxy_transportr   r1   c                 C  r/  r0  r1  r3  rB   rB   rC   r5    r6  zAsyncClient._transport_for_urlr7  r   r   r   r   r   r   r   r   r   r   r   r8  r   r   r   r   c                  sP   |	durd}t |t | j|||||||||	||d}| j||
|dI dH S )a  
        Build and send a request.

        Equivalent to:

        ```python
        request = client.build_request(...)
        response = await client.send(request, ...)
        ```

        See `AsyncClient.build_request()`, `AsyncClient.send()`
        and [Merging of configuration][0] for how the various parameters
        are merged with client-level configuration.

        [0]: /advanced/#merging-of-configuration
        Nr9  r:  r;  r<  r>  rB   rB   rC   r     s&   "zAsyncClient.requestrc  typing.AsyncIterator[Response]c                C sf   | j |||||||||	||d}| j||
|ddI dH }z|V  W | I dH  dS | I dH  w r@  )r   r=  rp   rA  rB   rB   rC   rP   (  s.   "zAsyncClient.streamrB  r   r   rP   c             
     s   | j tjkrtdtj| _ t|tr| jn|}| ||}| j	|||g dI dH }z|s5|
 I dH  |W S  tyL } z	| I dH  |d}~ww )a  
        Send a request.

        The request is sent as-is, unmodified.

        Typically you'll want to build one with `AsyncClient.build_request()`
        so that any client-level configuration is merged into the request,
        but passing an explicit `httpx.Request()` is supported as well.

        See also: [Request instances][0]

        [0]: /advanced/#request-instances
        rC  rD  N)r   rH   rM   r  rL   r   r=   rz   r   rF  areadrH  rp   rI  rB   rB   rC   r=  \  s0   zAsyncClient.sendr   rE  rJ  c           	   
     s   | |}z^| I d H }	 | j|||dI d H }z4z
||I d H }W n ty9   | Y W W | I d H  S w t||_| I d H  |}|	| W n t
yc } z	| I d H  |d }~ww q| I d H  w rK  )Zasync_auth_flow	__anext__rM  asendStopAsyncIterationrp   r   rE  r  rO  rH  rP  rB   rB   rC   rF    s8   


zAsyncClient._send_handling_authc              
     s   	 t || jkrtd|d| jd D ]	}||I d H  q| |I d H }z7| jd D ]	}||I d H  q,t||_|jsA|W S | ||}||g }|rV|	 I d H  n||_
|W S W n tyr } z	| I d H  |d }~ww qrR  )rS  r{   r   r   rT  r   rE  rU  r   r  rQ  rH  rp   rV  rB   rB   rC   rM    s8   

z$AsyncClient._send_handling_redirectsc                   s   |  |j}t }| I dH  t|jtstdt|d |	|I dH }W d   n1 s3w   Y  t|jts@J ||_
t|j||d|_| j| | j|_td|j|j|j|j|j |S )rX  Nz?Attempted to send an sync request with an AsyncClient instance.r   rY  rZ  )r5  r   r3   Zasync_startr   rP   r!   r  r   Zhandle_async_requestr   rm   rx   r\  r   r   r]  r^  r   r_  r   r`  ra  rB   rB   rC   rT    s6   	z AsyncClient._send_single_requestrb  c          	        $   | j d||||||||d	I dH S )re  r   rb  Nr   rf  rB   rB   rC   r        zAsyncClient.getc          	        r  )rh  ri  rb  Nr   rf  rB   rB   rC   rj    r  zAsyncClient.optionsc          	        r  )rk  r   rb  Nr   rf  rB   rB   rC   rl  2  r  zAsyncClient.headc                  ,   | j d|||||||||	|
||dI dH S )rn  r   r7  Nr   ro  rB   rB   rC   rp  O      zAsyncClient.postc                  r  )rr  rs  r7  Nr   ro  rB   rB   rC   rt  t  r  zAsyncClient.putc                  r  )ru  rv  r7  Nr   ro  rB   rB   rC   rw    r  zAsyncClient.patchc          	        r  )rx  ry  rb  Nr   rf  rB   rB   rC   rz    r  zAsyncClient.deletec                   sT   | j tjkr&tj| _ | j I dH  | j D ]}|dur%| I dH  qdS dS r{  )r   rH   rM   r   rp   r!  r|  )r\   r   rB   rB   rC   rp     s   zAsyncClient.acloser\   r;   c                   sn   | j tjkrtjdtjdi| j  }t|tj| _ | j I d H  | j	 D ]}|d ur4| I d H  q'| S r}  )
r   rH   rK   rL   rM   r  r   
__aenter__r!  r|  )r\   r  r   rB   rB   rC   r    s    zAsyncClient.__aenter__r  r  r  r  r  r  c                   sP   t j| _| j|||I d H  | j D ]}|d ur%||||I d H  qd S rV   )rH   rM   r   r   	__aexit__r!  r|  )r\   r  r  r  r   rB   rB   rC   r    s   zAsyncClient.__aexit__),ru   r   rv   r   rw   r   rx   r   r   r0   r   r  r   r   r   r   r   r  r   r   r   r  ry   r.   rz   r   r   r   r{   r   r|   r  r}   r/   r   r  r  r  r~   r   r   r   rS   rT   )r   r0   r   r  r   r   r   r   r   r   r   r  r  r  r~   r   rS   r   )r   r   r   r0   r   r  r   r   r   r   r   r   r~   r   rS   r   )r   r1   rS   r   r  )r   r   r   r/   r   r   r   r   r   r   r   r   rv   r   rw   r   rx   r   ru   rc  rz   r8  ry   r   r   r   rS   r  r  r  r  r  )r   r/   rv   r   rw   r   rx   r   ru   r   rz   r8  ry   r   r   r   rS   r   r  r  rk   )r\   r;   rS   r;   r  r  )r>   r?   r@   rA   r   r   r   r]   r  r  r5  r   r   r   rP   r=  rF  rM  rT  r   rj  rl  rp  rt  rw  rz  rp   r  r  r  rB   rB   r%  rC   r<     s&   9e
97
1
"
&'!!!)))

)_
__future__r   rf   enumloggingtypingr  
contextlibr   r   typesr   r   r   r   r	   r
   _configr   r   r   r   r   r   	_decodersr   _exceptionsr   r   r   r   Z_modelsr   r   r   r   Z_status_codesr   Z_transports.asgir   Z_transports.baser   r   Z_transports.defaultr   r   Z_transports.wsgir    _typesr!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   Z_urlsr1   r2   _utilsr3   r4   r5   r6   r7   TypeVarr8   r;   r=   r   	getLoggerr]  r   r   keysr   EnumrH   rO   rm   CallableAnyZ	EventHookrq   r9   r<   rB   rB   rB   rC   <module>   s\     H


        m