U
    	f                    @  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   P/var/www/html/apigroqsegura/apigroq/lib/python3.8/site-packages/httpx/_client.pyr=   C   s   r=   httpxzpython-httpx/z, c                 C  s   g | ]}|d kr|qS )identityrB   ).0keyrB   rB   rC   
<listcomp>^   s      rH   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   rI   b   s   rI   c                   @  s@   e Zd ZdZdddddddZd	d
ddZd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.
    r-   r   r3   Nonestreamresponsetimerreturnc                 C  s   || _ || _|| _d S N_stream	_response_timerselfrR   rS   rT   rB   rB   rC   __init__v   s    zBoundSyncStream.__init__ztyping.Iterator[bytes]rU   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\   rd   rB   rB   rC   rh      s    
zBoundSyncStream.closeN)r>   r?   r@   rA   r]   rb   rh   rB   rB   rB   rC   rO   p   s   rO   c                   @  s@   e Zd ZdZdddddddZd	d
ddZdd
ddZdS )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.
    r!   r   r3   rP   rQ   c                 C  s   || _ || _|| _d S rV   rW   r[   rB   rB   rC   r]      s    zBoundAsyncStream.__init__ztyping.AsyncIterator[bytes]r^   c                 C s    | j 2 z3 d H W }|V  q6 d S rV   r_   r`   rB   rB   rC   	__aiter__   s    zBoundAsyncStream.__aiter__c                   s4   | j  I d H }tj|d| j_| j I d H  d S rc   )rZ   Zasync_elapsedre   rf   rY   rg   rX   acloseri   rB   rB   rC   rl      s    zBoundAsyncStream.acloseN)r>   r?   r@   rA   r]   rk   rl   rB   rB   rB   rC   rj      s   rj   .c                   @  s  e Zd Zddddededddddddd	d
dddddddddddZeddddZeddddZdddddZ	dddd d!d"Z
ed#dd$d%Zejddd&d'd%Zed(dd)d*Zejd(dd+d,d*Zed-dd.d/Zejd0dd1d2d/Zeddd3d4Zejdddd5d4Zed6dd7d8Zejd9dd:d;d8Zed<dd=d>Zejd?dd@dAd>ZedBddCdDZejdEddFdGdDZdddddddeddH	dIddJdKdLdMdd	d
dNdOdPdQdRdSZddddTdUZdrd
d
d@dVdWZdsd	d	d:dXdYZdtdddFdZd[Zdd-d1d\d]ZefdPd^d_d`dadbZdPdcdPdddedfZdPdcdIdddgdhZdPdcddddidjZdPddId6dkdldmZdPdIdndodpdqZdS )u
BaseClientNF Tutf-8authparamsheaderscookiestimeoutfollow_redirectsmax_redirectsevent_hooksbase_url	trust_envdefault_encodingAuthTypes | NoneQueryParamTypes | NoneHeaderTypes | NoneCookieTypes | Noner.   boolint+None | typing.Mapping[str, list[EventHook]]r/   #str | typing.Callable[[bytes], str]rP   )rq   rr   rs   rt   ru   rv   rw   rx   ry   rz   r{   rU   c                C  s   |d kri n|}|  t|	| _| || _t|| _t|| _t	|| _
t|| _|| _|| _t|dg t|dg d| _|
| _|| _tj| _d S NrequestrS   )r   rS   )_enforce_trailing_slashr1   	_base_url_build_auth_authr2   _paramsr   rs   r   _cookiesr   _timeoutrv   rw   listget_event_hooks
_trust_env_default_encodingrI   rL   _state)r\   rq   rr   rs   rt   ru   rv   rw   rx   ry   rz   r{   rB   rB   rC   r]      s    



zBaseClient.__init__r^   c                 C  s   | j tjkS )z2
        Check if the client being closed
        )r   rI   rN   r\   rB   rB   rC   	is_closed   s    zBaseClient.is_closedc                 C  s   | j S rV   )r   r   rB   rB   rC   rz      s    zBaseClient.trust_envr1   urlrU   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ProxiesTypes | Nonezdict[str, Proxy | None])proxiesallow_env_proxiesrU   c                 C  s   |d kr$|r dd t   D S i S t|trpi }| D ]0\}}t|ttfrZt|dn|}||t|< q:|S t|ttfrt|dn|}d|iS d S )Nc                 S  s(   i | ] \}}||d krd nt |dqS )Nr   )r   )rF   rG   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   Znew_proxiesrG   valueproxyrB   rB   rC   _get_proxy_map   s    
zBaseClient._get_proxy_mapr   c                 C  s   | j S rV   )r   r   rB   rB   rC   ru      s    zBaseClient.timeout)ru   rU   c                 C  s   t || _d S rV   )r   r   )r\   ru   rB   rB   rC   ru      s    zdict[str, list[EventHook]]c                 C  s   | j S rV   )r   r   rB   rB   rC   rx      s    zBaseClient.event_hooks)rx   rU   c                 C  s(   t |dg t |dg d| _d S r   )r   r   r   )r\   rx   rB   rB   rC   rx      s    zAuth | Nonec                 C  s   | j S )z
        Authentication class used when none is passed at the request-level.

        See also [Authentication][0].

        [0]: /quickstart/#authentication
        )r   r   rB   rB   rC   rq      s    	zBaseClient.authr"   )rq   rU   c                 C  s   |  || _d S rV   )r   r   r\   rq   rB   rB   rC   rq     s    c                 C  s   | j S )zK
        Base URL to use when sending requests with relative URLs.
        )r   r   rB   rB   rC   ry   
  s    zBaseClient.base_urlc                 C  s   |  t|| _d S rV   )r   r1   r   r   rB   rB   rC   ry     s    r   c                 C  s   | j S )z@
        HTTP headers to include when sending requests.
        )_headersr   rB   rB   rC   rs     s    zBaseClient.headersr%   )rs   rU   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\   rs   Zclient_headersrB   rB   rC   rs     s    
r   c                 C  s   | j S )zA
        Cookie values to include when sending requests.
        )r   r   rB   rB   rC   rt   )  s    zBaseClient.cookiesr$   )rt   rU   c                 C  s   t || _d S rV   )r   r   )r\   rt   rB   rB   rC   rt   0  s    r2   c                 C  s   | j S )zO
        Query parameters to include in the URL when sending requests.
        )r   r   rB   rB   rC   rr   4  s    zBaseClient.paramsr(   )rr   rU   c                 C  s   t || _d S rV   )r2   r   )r\   rr   rB   rB   rC   rr   ;  s    )	contentdatafilesjsonrr   rs   rt   ru   
extensionsr   RequestContent | NoneRequestData | NoneRequestFiles | Nonetyping.Any | NoneTimeoutTypes | UseClientDefaultRequestExtensions | Noner   )methodr   r   r   r   r   rr   rs   rt   ru   r   rU   c       	         C  s   |  |}| |}| |	}	| |}|dkr4i n|}d|krnt|
trP| jnt|
}
tf |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
        Nru   )r   r   r   r   rr   rs   rt   r   )
_merge_url_merge_headers_merge_cookies_merge_queryparamsr   r=   ru   r   r   as_dictr   )r\   r   r   r   r   r   r   rr   rs   rt   ru   r   rB   rB   rC   build_request?  s.    



zBaseClient.build_requestc                 C  s4   t |}|jr0| 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_urlry   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.
        )rt   r   r   )r\   rt   Z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   rs   r   )r\   rs   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.
        )rr   r2   merge)r\   rr   Zmerged_queryparamsrB   rB   rC   r     s    


zBaseClient._merge_queryparamsc                 C  s\   |d krd S t |tr*t|d |d dS t |tr8|S t|rJt|dS td|d S )Nr   r   usernamepassword)funczInvalid "auth" argument: )r   tupler	   r   callabler
   	TypeErrorr   rB   rB   rC   r     s    


zBaseClient._build_auth#AuthTypes | UseClientDefault | Noner   )r   rq   rU   c                 C  sR   t |tr| jn| |}|d k	r&|S |jj|jj }}|s@|rLt||dS t S )Nr   )	r   r=   r   r   r   r   r   r	   r   )r\   r   rq   r   r   rB   rB   rC   _build_request_auth  s    zBaseClient._build_request_authr   )r   rS   rU   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   rs   rt   rR   r   )_redirect_method_redirect_url_redirect_headers_redirect_streamr   rt   r   r   )r\   r   rS   r   r   rs   rR   rt   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r6|dkr6d}|jtjkrN|dkrNd}|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   rS   r   rB   rB   rC   r     s    zBaseClient._redirect_methodc              
   C  s   |j d }zt|}W n8 tk
rN } ztd| d|ddW 5 d}~X Y nX |jrl|jsl|j|jjd}|jr~|j	|}|jj
r|j
s|j|jj
d}|S )z<
        Return the URL for the redirect to follow.
        Locationz Invalid URL in location header: .r   N)host)fragment)rs   r1   r   r   schemer   r   r   r   joinr   )r\   r   rS   locationr   excrB   rB   rC   r     s"    

 zBaseClient._redirect_url)r   r   r   rU   c                 C  sx   t |j}t||js>t|j|s.|dd |jd|d< ||jkrh|dkrh|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   rs   r7   r   r6   popnetlocdecoder   )r\   r   r   r   rs   rB   rB   rC   r     s    
zBaseClient._redirect_headersz'SyncByteStream | AsyncByteStream | None)r   r   rU   c                 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   rR   )r\   r   r   rB   rB   rC   r   (  s    zBaseClient._redirect_stream)N)N)N) r>   r?   r@   r   r   r]   propertyr   rz   r   r   ru   setterrx   rq   ry   rs   rt   rr   USE_CLIENT_DEFAULTr   r   r   r   r   r   r   r   r   r   r   r   rB   rB   rB   rC   rm      s   ("
(3
 rm   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d	d
dddddddddddddddddddd fddZddddedddfdddddddddd	d d!Zddddedfd"dddddddd#d$d%Z	d&dd'd(d)Z
dddddddeeedd*d+dd,d-d.d/d	d
dd0d1d2d3d4d5d6d7Zedddddddeeedd*d+dd,d-d.d/d	d
dd0d1d2d3d8d5d9d:Zdeed;d<dd0d1d4d=d>d?Zd<d@ddAd4dBdCdDZd<ddAd4dEdFdGZd<d4dHdIdJZdddeeeddKdd	d
ddLd1d2d3d4dM	dNdOZdddeeeddKdd	d
ddLd1d2d3d4dM	dPdQZdddeeeddKdd	d
ddLd1d2d3d4dM	dRdSZdddddddeeedd*dd,d-d.d/d	d
ddLd1d2d3d4dTdUdVZdddddddeeedd*dd,d-d.d/d	d
ddLd1d2d3d4dTdWdXZdddddddeeedd*dd,d-d.d/d	d
ddLd1d2d3d4dTdYdZZdddeeeddKdd	d
ddLd1d2d3d4dM	d[d\Zdd]d^d_Zd`d`dadbdcZdjdddedfddgdhdiZ  ZS )kr9   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".
    NTFrn   ro   rq   rr   rs   rt   verifycerthttp1http2r   r   mountsru   rv   limitsrw   rx   ry   	transportapprz   r{   r|   r}   r~   r   r0   CertTypes | Noner   ProxyTypes | Noner   z0None | typing.Mapping[str, BaseTransport | None]r.   r   r   r   r/   zBaseTransport | None'typing.Callable[..., typing.Any] | Noner   rP   rq   rr   rs   rt   r   r   r   r   r   r   r   ru   rv   r   rw   rx   ry   r   r   rz   r{   rU   c                  s&  t  j||||||||||d rRzdd l}W n tk
rP   tdd Y nX |
rrd}t|t |	rrtd|rd}t|t o|d ko|d k}|
p|	|}j	 ||d_
 fdd	| D _|d k	rjd
d	 | D  ttj _d S )Nrp   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   rz   c                   s:   i | ]2\}}t ||d krd nj| dqS Nr   r   r   r   r   rz   r4   _init_proxy_transportrF   rG   r   r   r   r   r   r\   rz   r   rB   rC   r     s   z#Client.__init__.<locals>.<dictcomp>c                 S  s   i | ]\}}t ||qS rB   r4   rF   rG   r   rB   rB   rC   r     s      superr]   h2ImportErrorwarningswarnDeprecationWarningRuntimeErrorr   _init_transport
_transportr   _mountsr   r   sortedr\   rq   rr   rs   rt   r   r   r   r   r   r   r   ru   rv   r   rw   rx   ry   r   r   rz   r{   r  messager   Z	proxy_map	__class__r  rC   r]   j  sh    

zClient.__init__r   	r   r   r   r   r   r   r   rz   rU   c	           	      C  s2   |d k	r|S |d k	rt |dS t||||||dS N)r   r   )r    r   	r\   r   r   r   r   r   r   r   rz   rB   rB   rC   r    s    
zClient._init_transportr   r   r   r   r   r   r   rz   rU   c              	   C  s   t |||||||dS N)r   r   r   r   r   rz   r   )r   r\   r   r   r   r   r   r   rz   rB   rB   rC   r     s    
zClient._init_proxy_transportr1   r   c                 C  s:   | j  D ](\}}||r
|dkr*| jn|  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  s    
zClient._transport_for_urlr   r   r   r   rr   rs   rt   rq   rv   ru   r   r   r   r   r   r   r   bool | UseClientDefaultr   r   r   r   r   r   r   r   r   rr   rs   rt   rq   rv   ru   r   rU   c                C  sH   |	dk	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   rr   rs   rt   ru   r   rq   rv   r	  r
  r  r   sendr\   r   r   r   r   r   r   rr   rs   rt   rq   rv   ru   r   r  r   rB   rB   rC   r     s$    !zClient.requestztyping.Iterator[Response]c                c  sL   | j |||||||||	||d}| j||
|dd}z
|V  W 5 |  X dS 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   rq   rv   rR   N)r   r(  rh   r\   r   r   r   r   r   r   rr   rs   rt   rq   rv   ru   r   r   rS   rB   rB   rC   rR   =  s,    
zClient.streamrR   rq   rv   r   r   rR   rq   rv   rU   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k
r } z|  |W 5 d}~X Y nX dS )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.rq   rv   historyN)r   rI   rN   r  rM   r   r=   rv   r   _send_handling_authreadBaseExceptionrh   r\   r   rR   rq   rv   rS   r   rB   rB   rC   r(  q  s*    zClient.sendr   list[Response]r   rq   rv   r0  rU   c           	   
   C  s   | |}zt|}| j|||d}zRz||}W n tk
rR   | Y W W \S X t||_|  |}|	| W q t
k
r } z|  |W 5 d }~X Y qX qW 5 |  X d S N)rv   r0  )Zsync_auth_flowrh   next_send_handling_redirectsr(  StopIterationr   r0  r2  appendr3  	r\   r   rq   rv   r0  Z	auth_flowrS   next_requestr   rB   rB   rC   r1    s*    

zClient._send_handling_authr   rv   r0  rU   c              
   C  s   t || jkrtd|d| jd D ]}|| q$| |}zb| jd D ]}|| qHt||_|jsl|W S | ||}||g }|r|	  n||_
|W S W q  tk
r } z|  |W 5 d }~X Y q X q d S Nz#Exceeded maximum allowed redirects.r   r   rS   )lenrw   r   r   _send_single_requestr   r0  has_redirect_locationr   r2  r=  r3  rh   r\   r   rv   r0  hookrS   r   rB   rB   rC   r9    s.     






zClient._send_handling_redirectsr   rU   c              	   C  s   |  |j}t }|  t|jts.tdt|d |	|}W 5 Q R X t|jts^t
||_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   rS   rT   HTTP Request: %s %s "%s %d %s")r   r   r3   Z
sync_startr   rR   r-   r  r   handle_requestAssertionErrorr   rO   rt   extract_cookiesr   r{   loggerinfor   http_versionr   reason_phraser\   r   r   rT   rS   rB   rB   rC   rA    s6      	zClient._send_single_requestrr   rs   rt   rq   rv   ru   r   AuthTypes | UseClientDefault	r   rr   rs   rt   rq   rv   ru   r   rU   c          	      C  s   | j d||||||||d	S )U
        Send a `GET` request.

        **Parameters**: See `httpx.request`.
        r   rQ  r   	r\   r   rr   rs   rt   rq   rv   ru   r   rB   rB   rC   r     s    z
Client.getc          	      C  s   | j d||||||||d	S )Z
        Send an `OPTIONS` request.

        **Parameters**: See `httpx.request`.
        OPTIONSrQ  r   rU  rB   rB   rC   options*  s    zClient.optionsc          	      C  s   | j d||||||||d	S )V
        Send a `HEAD` request.

        **Parameters**: See `httpx.request`.
        r   rQ  r   rU  rB   rB   rC   headG  s    zClient.headr   r   r   r   r   rr   rs   rt   rq   rv   ru   r   rU   c                C  s$   | j d|||||||||	|
||dS )V
        Send a `POST` request.

        **Parameters**: See `httpx.request`.
        r   r!  r   r\   r   r   r   r   r   rr   rs   rt   rq   rv   ru   r   rB   rB   rC   postd  s    zClient.postc                C  s$   | j d|||||||||	|
||dS )U
        Send a `PUT` request.

        **Parameters**: See `httpx.request`.
        PUTr!  r   r]  rB   rB   rC   put  s    z
Client.putc                C  s$   | j d|||||||||	|
||dS )W
        Send a `PATCH` request.

        **Parameters**: See `httpx.request`.
        PATCHr!  r   r]  rB   rB   rC   patch  s    zClient.patchc          	      C  s   | j d||||||||d	S )X
        Send a `DELETE` request.

        **Parameters**: See `httpx.request`.
        DELETErQ  r   rU  rB   rB   rC   delete  s    zClient.deleter^   c                 C  sB   | j tjkr>tj| _ | j  | j D ]}|dk	r(|  q(dS z.
        Close transport and proxies.
        N)r   rI   rN   r  rh   r  values)r\   r   rB   rB   rC   rh     s    
zClient.closer8   r\   rU   c                 C  s`   | j tjkr*tjdtjdi| j  }t|tj| _ | j  | j	 D ]}|d k	rF|  qF| S Nz-Cannot open a client instance more than once.z9Cannot reopen a client instance, once it has been closed.)
r   rI   rL   rM   rN   r  r  	__enter__r  ri  )r\   msgr   rB   rB   rC   rl    s     

zClient.__enter__type[BaseException] | NoneBaseException | NoneTracebackType | Noneexc_type	exc_value	tracebackrU   c                 C  sB   t j| _| j||| | j D ]}|d k	r"|||| q"d S rV   )rI   rN   r   r  __exit__r  ri  )r\   rr  rs  rt  r   rB   rB   rC   ru    s
    zClient.__exit__)NNN)r>   r?   r@   rA   r   r   r   r]   r  r   r   r   r   r   rR   r(  r1  r9  rA  r   rX  rZ  r^  ra  rd  rg  rh   rl  ru  __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d	d
dddddddddddddddddddd fddZddddedddfdddddddddd	d d!Zddddedfd"dddddddd#d$d%Z	d&dd'd(d)Z
dddddddeeedd*d+dd,d-d.d/d	d
dd0d1d2d3d4d5d6d7Zedddddddeeedd*d+dd,d-d.d/d	d
dd8d1d2d3d9d5d:d;Zdeed<d=dd0d1d4d>d?d@Zd=dAddBd4dCdDdEZd=ddBd4dFdGdHZd=d4dIdJdKZdddeeeddLdd	d
dd0d1d2d3d4dM	dNdOZdddeeeddLdd	d
dd8d1d2d3d4dM	dPdQZdddeeeddLdd	d
dd8d1d2d3d4dM	dRdSZdddddddeeedd*dd,d-d.d/d	d
dd8d1d2d3d4dTdUdVZdddddddeeedd*dd,d-d.d/d	d
dd8d1d2d3d4dTdWdXZdddddddeeedd*dd,d-d.d/d	d
dd8d1d2d3d4dTdYdZZdddeeeddLdd	d
dd8d1d2d3d4dM	d[d\Zdd]d^d_Zd`d`dadbdcZdjdddedfddgdhdiZ  ZS )kr<   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".
    NTFrn   ro   r   r|   r}   r~   r   r0   r   r   r   r   z5None | typing.Mapping[str, AsyncBaseTransport | None]r.   r   r   zBNone | typing.Mapping[str, list[typing.Callable[..., typing.Any]]]r/   zAsyncBaseTransport | Noner   r   rP   r   c                  s  t  j||||||||||d rRzdd l}W n tk
rP   tdd Y nX |
rrd}t|t |	rrtd|rd}t|t o|d k}|
p|	|}j	 ||d_
 fdd	| D _|d k	rjd
d	 | D  ttj _d S )Nrp   r   r   r   r   zhThe 'app' shortcut is now deprecated. Use the explicit style 'transport=ASGITransport(app=...)' instead.r   c                   s:   i | ]2\}}t ||d krd nj| dqS r   r   r  r  rB   rC   r     s   z(AsyncClient.__init__.<locals>.<dictcomp>c                 S  s   i | ]\}}t ||qS rB   r  r  rB   rB   rC   r     s      r  r  r  r  rC   r]   S  sh    
zAsyncClient.__init__r   r  c	           	      C  s2   |d k	r|S |d k	rt |dS t||||||dS r  )r   r   r  rB   rB   rC   r    s    
zAsyncClient._init_transportr   r  c              	   C  s   t |||||||dS r  )r   r  rB   rB   rC   r     s    
z!AsyncClient._init_proxy_transportr1   r   c                 C  s:   | j  D ](\}}||r
|dkr*| jn|  S q
| jS r  r  r  rB   rB   rC   r     s    
zAsyncClient._transport_for_urlr!  r   r   r   r   r   r   r"  r   r   r   r#  c                  sN   |	dk	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
        Nr$  r%  r&  r'  r)  rB   rB   rC   r     s$    "zAsyncClient.requestrR  ztyping.AsyncIterator[Response]c                C sX   | j |||||||||	||d}| j||
|ddI dH }z
|V  W 5 | I dH  X dS r*  )r   r(  rl   r+  rB   rB   rC   rR   (  s,    
zAsyncClient.streamr,  r   r-  c             
     s   | j tjkrtdtj| _ t|tr,| jn|}| ||}| j	|||g dI dH }z|sh|
 I dH  |W S  tk
r } z| I dH  |W 5 d}~X Y nX dS )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
        r.  r/  N)r   rI   rN   r  rM   r   r=   rv   r   r1  areadr3  rl   r4  rB   rB   rC   r(  \  s*    zAsyncClient.sendr   r5  r6  c           	   
     s   | |}z| I d H }| j|||dI d H }z^z||I d H }W n tk
rd   | Y W W hS X t||_| I d H  |}|	| W q t
k
r } z| I d H  |W 5 d }~X Y qX qW 5 | I d H  X d S r7  )Zasync_auth_flowrl   	__anext__r9  asendStopAsyncIterationr   r0  rw  r;  r3  r<  rB   rB   rC   r1    s*    

zAsyncClient._send_handling_authr>  c              
     s   t || jkrtd|d| jd D ]}||I d H  q$| |I d H }zn| jd D ]}||I d H  qTt||_|js~|W S | ||}||g }|r|	 I d H  n||_
|W S W q  tk
r } z| I d H  |W 5 d }~X Y q X q d S r?  )r@  rw   r   r   rA  r   r0  rB  r   rw  r=  r3  rl   rC  rB   rB   rC   r9    s.     


z$AsyncClient._send_handling_redirectsrE  c              	     s   |  |j}t }| I dH  t|jts4tdt|d |	|I dH }W 5 Q R X t|jtsjt
||_t|j||d|_| j| | j|_td|j|j|j|j|j |S )rF  Nz?Attempted to send an sync request with an AsyncClient instance.r   rG  rH  )r   r   r3   Zasync_startr   rR   r!   r  r   Zhandle_async_requestrJ  r   rj   rt   rK  r   r{   rL  rM  r   rN  r   rO  rP  rB   rB   rC   rA    s6      	z AsyncClient._send_single_requestrQ  rS  c          	        s"   | j d||||||||d	I dH S )rT  r   rQ  Nr   rU  rB   rB   rC   r     s    zAsyncClient.getc          	        s"   | j d||||||||d	I dH S )rV  rW  rQ  Nr   rU  rB   rB   rC   rX    s    zAsyncClient.optionsc          	        s"   | j d||||||||d	I dH S )rY  r   rQ  Nr   rU  rB   rB   rC   rZ  2  s    zAsyncClient.headr[  c                  s*   | j d|||||||||	|
||dI dH S )r\  r   r!  Nr   r]  rB   rB   rC   r^  O  s    zAsyncClient.postc                  s*   | j d|||||||||	|
||dI dH S )r_  r`  r!  Nr   r]  rB   rB   rC   ra  t  s    zAsyncClient.putc                  s*   | j d|||||||||	|
||dI dH S )rb  rc  r!  Nr   r]  rB   rB   rC   rd    s    zAsyncClient.patchc          	        s"   | j d||||||||d	I dH S )re  rf  rQ  Nr   rU  rB   rB   rC   rg    s    zAsyncClient.deleter^   c                   sN   | j tjkrJtj| _ | j I dH  | j D ]}|dk	r.| I dH  q.dS rh  )r   rI   rN   r  rl   r  ri  )r\   r   rB   rB   rC   rl     s    zAsyncClient.acloser;   rj  c                   sl   | j tjkr*tjdtjdi| j  }t|tj| _ | j I d H  | j	 D ]}|d k	rL| I d H  qL| S rk  )
r   rI   rL   rM   rN   r  r  
__aenter__r  ri  )r\   rm  r   rB   rB   rC   r{    s     zAsyncClient.__aenter__rn  ro  rp  rq  c                   sN   t j| _| j|||I d H  | j D ] }|d k	r(||||I d H  q(d S rV   )rI   rN   r   r  	__aexit__r  ri  )r\   rr  rs  rt  r   rB   rB   rC   r|    s
    zAsyncClient.__aexit__)NNN)r>   r?   r@   rA   r   r   r   r]   r  r   r   r   r   r   rR   r(  r1  r9  rA  r   rX  rZ  r^  ra  rd  rg  rl   r{  r|  rv  rB   rB   r  rC   r<     s$  9@e ,9.71"&'"!"!"!*)*)*)"   )_
__future__r   re   enumloggingtypingr	  
contextlibr   r   typesr   r   r   r   r	   r
   _configr   r   r   r   r   r   Z	_decodersr   _exceptionsr   r   r   r   _modelsr   r   r   r   _status_codesr   _transports.asgir   _transports.baser   r   _transports.defaultr   r   _transports.wsgir    _typesr!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   _urlsr1   r2   _utilsr3   r4   r5   r6   r7   TypeVarr8   r;   r=   r   	getLoggerrL  r   r   keysr   EnumrI   rO   rj   CallableAnyZ	EventHookrm   r9   r<   rB   rB   rB   rC   <module>   sZ    H


        m