o
    h;
                    @   sD  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l.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z= ddl>m?Z?m@Z@ ddlAmBZBmCZCmDZDmEZEmFZF ejGdddZHejGdddZIG dd dZJeJ ZKeLdZMde
 ZNdOdd eP D ZQG dd  d ejRZSG d!d" d"e:ZTG d#d$ d$e/ZUejVd%ejWf ZXG d&d' d'ZYG d(d deYZZG d)d deYZ[dS )*    N)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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__ r@   r@   C/var/www/html/ai/venv/lib/python3.10/site-packages/httpx/_client.pyr;   @   s    r;   httpxzpython-httpx/z, c                 C   s   g | ]}|d kr|qS )identityr@   ).0keyr@   r@   rA   
<listcomp>[   s    rF   c                   @   s   e Zd ZdZdZdZdS )ClientStater         N)r<   r=   r>   UNOPENEDOPENEDCLOSEDr@   r@   r@   rA   rG   _   s    rG   c                   @   H   e Zd ZdZdedededdfddZdej	e
 f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.
    streamresponsetimerreturnNc                 C      || _ || _|| _d S N_stream	_response_timerselfrO   rP   rQ   r@   r@   rA   __init__s      
zBoundSyncStream.__init__c                 c   s    | j D ]}|V  qd S rT   rV   rZ   chunkr@   r@   rA   __iter__z   s   
zBoundSyncStream.__iter__c                 C   s(   | j  }tj|d| j_| j  d S N)seconds)rX   sync_elapseddatetime	timedeltarW   elapsedrV   closerZ   rb   r@   r@   rA   rg   ~   s   
zBoundSyncStream.closerR   N)r<   r=   r>   r?   r+   r   r1   r[   typingIteratorbytesr`   rg   r@   r@   r@   rA   rN   m       
rN   c                   @   rM   )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.
    rO   rP   rQ   rR   Nc                 C   rS   rT   rU   rY   r@   r@   rA   r[      r\   zBoundAsyncStream.__init__c                 C  s"   | j 2 z	3 d H W }|V  q6 d S rT   r]   r^   r@   r@   rA   	__aiter__   s   zBoundAsyncStream.__aiter__c                    s6   | j  I d H }tj|d| j_| j I d H  d S ra   )rX   async_elapsedrd   re   rW   rf   rV   acloserh   r@   r@   rA   rq      s   zBoundAsyncStream.acloseri   )r<   r=   r>   r?   r    r   r1   r[   rj   AsyncIteratorrl   ro   rq   r@   r@   r@   rA   rn      rm   rn   .c                   @   s  e Zd Zddddededdddddeje deje d	eje	 d
eje
 dedededejejeeje f  dededejeejegef f ddfddZedefddZedefddZdedefddZdeje dedejeeje f fddZede fd d!Z!e!j"deddfd"d!Z!edejeeje f fd#d$Z#e#j"dejeeje f ddfd%d$Z#edeje$ fd&d'Z%e%j"deddfd(d'Z%edefd)d*Z&e&j"deddfd+d*Z&ede'fd,d-Z(e(j"d	e	ddfd.d-Z(ede)fd/d0Z*e*j"d
e
ddfd1d0Z*ede+fd2d3Z,e,j"deddfd4d3Z,ddddddde-dd5	d6eded7eje. d8eje/ d9eje0 d:ejej1 deje d	eje	 d
eje
 dejee2f d;eje3 de4fd<d=Z5dedefd>d?Z6	dVd
eje
 deje
 fd@dAZ7	dVd	eje	 deje	 fdBdCZ8	dVdeje deje fdDdEZ9deje deje$ fdFdGZ:e-fdHe4dejee2df de$fdIdJZ;dHe4dKe<de4fdLdMZ=dHe4dKe<defdNdOZ>dHe4dKe<defdPdQZ?dHe4ded6ede'fdRdSZ@dHe4d6edejejeAeBf  fdTdUZCdS )W
BaseClientNF Tutf-8authparamsheaderscookiestimeoutfollow_redirectsmax_redirectsevent_hooksbase_url	trust_envdefault_encodingrw   rx   ry   rz   r{   r|   r}   r~   r   r   r   rR   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requestrP   )r   rP   )_enforce_trailing_slashr/   	_base_url_build_auth_authr0   _paramsr   ry   r   _cookiesr   _timeoutr|   r}   listget_event_hooks
_trust_env_default_encodingrG   rJ   _state)rZ   rw   rx   ry   rz   r{   r|   r}   r~   r   r   r   r@   r@   rA   r[      s   



zBaseClient.__init__c                 C   s   | j tjkS )z2
        Check if the client being closed
        )r   rG   rL   rZ   r@   r@   rA   	is_closed   s   zBaseClient.is_closedc                 C      | j S rT   )r   r   r@   r@   rA   r         zBaseClient.trust_envurlc                 C   s"   |j dr|S |j|j d dS )N   /raw_path)r   endswith	copy_withrZ   r   r@   r@   rA   r      s   z"BaseClient._enforce_trailing_slashproxiesallow_env_proxiesc                 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   )rD   rE   r   r@   r@   rA   
<dictcomp>   s    z-BaseClient._get_proxy_map.<locals>.<dictcomp>r   zall://)r3   items
isinstancedictstrr/   r   )rZ   r   r   new_proxiesrE   valueproxyr@   r@   rA   _get_proxy_map   s   
zBaseClient._get_proxy_mapc                 C   r   rT   )r   r   r@   r@   rA   r{      r   zBaseClient.timeoutc                 C      t || _d S rT   )r   r   )rZ   r{   r@   r@   rA   r{         c                 C   r   rT   )r   r   r@   r@   rA   r~      r   zBaseClient.event_hooksc                 C   s(   t |dg t |dg d| _d S r   )r   r   r   )rZ   r~   r@   r@   rA   r~      s   c                 C   r   )z
        Authentication class used when none is passed at the request-level.

        See also [Authentication][0].

        [0]: /quickstart/#authentication
        )r   r   r@   r@   rA   rw      s   	zBaseClient.authc                 C   s   |  || _d S rT   )r   r   rZ   rw   r@   r@   rA   rw     s   c                 C   r   )zK
        Base URL to use when sending requests with relative URLs.
        )r   r   r@   r@   rA   r        zBaseClient.base_urlc                 C   s   |  t|| _d S rT   )r   r/   r   r   r@   r@   rA   r     s   c                 C   r   )z@
        HTTP headers to include when sending requests.
        )_headersr   r@   r@   rA   ry     r   zBaseClient.headersc                 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   )rZ   ry   client_headersr@   r@   rA   ry     s   

c                 C   r   )zA
        Cookie values to include when sending requests.
        )r   r   r@   r@   rA   rz   *  r   zBaseClient.cookiesc                 C   r   rT   )r   r   )rZ   rz   r@   r@   rA   rz   1  r   c                 C   r   )zO
        Query parameters to include in the URL when sending requests.
        )r   r   r@   r@   rA   rx   5  r   zBaseClient.paramsc                 C   r   rT   )r0   r   )rZ   rx   r@   r@   rA   rx   <  r   )	contentdatafilesjsonrx   ry   rz   r{   
extensionsmethodr   r   r   r   r   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
        Nr{   )r   r   r   r   rx   ry   rz   r   r@   )
_merge_url_merge_headers_merge_cookies_merge_queryparamsr   r;   r{   r   r   as_dictr   )rZ   r   r   r   r   r   r   rx   ry   rz   r{   r   r@   r@   rA   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   )r/   is_relative_urlr   r   lstripr   )rZ   r   	merge_urlmerge_raw_pathr@   r@   rA   r   s  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.
        )rz   r   r   )rZ   rz   merged_cookiesr@   r@   rA   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   ry   r   )rZ   ry   merged_headersr@   r@   rA   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.
        )rx   r0   merge)rZ   rx   merged_queryparamsr@   r@   rA   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   r@   r@   rA   r     s   


zBaseClient._build_authr   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   )rZ   r   rw   r   r   r@   r@   rA   _build_request_auth  s   zBaseClient._build_request_authrP   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   ry   rz   rO   r   )_redirect_method_redirect_url_redirect_headers_redirect_streamr   rz   r   r   )rZ   r   rP   r   r   ry   rO   rz   r@   r@   rA   _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)rZ   r   rP   r   r@   r@   rA   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.
        Locationz Invalid URL in location header: .r   N)host)fragment)ry   r/   r   r   schemer   r   r   r   joinr   )rZ   r   rP   locationr   excr@   r@   rA   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   ry   r5   r   r4   popnetlocdecoder   )rZ   r   r   r   ry   r@   r@   rA   r     s   
zBaseClient._redirect_headersc                 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   rO   )rZ   r   r   r@   r@   rA   r   -  s   zBaseClient._redirect_streamrT   )Dr<   r=   r>   r   r   rj   Optionalr!   r&   r$   r#   r,   boolintMappingr   List	EventHookr-   UnionCallablerl   r[   propertyr   r   r/   r   r%   Dictr   r   r   r{   setterr~   r   rw   r   r   ry   r   rz   r0   rx   USE_CLIENT_DEFAULTr'   r(   r*   Anyr;   r)   r   r   r   r   r   r   r   r   r   r   r   r   r   r+   r    r   r@   r@   r@   rA   rs      s8   	

$
 

	

3



rs   c                -       s  e Zd ZdZddddddddddedeeddddddddeje	 d	eje
 d
eje deje dedeje dededeje dejejeef  dededededejejeeje f  dedeje dejejdejf  dedejeejegef f ddf* fddZddddedddfdedeje dedededeje dejejdejf  dedefd d!Zddddedfd"e dedeje dededededefd#d$Z!d%e"defd&d'Z#ddddddde$e$e$dd(d)ed%ed*eje% d+eje& d,eje' d-ejej d	eje
 d
eje deje deje	e(df dejee(f dejee(f d.eje) de*fd/d0Z+e,ddddddde$e$e$dd(d)ed%ed*eje% d+eje& d,eje' d-ejej d	eje
 d
eje deje deje	e(df dejee(f dejee(f d.eje) dej-e* fd1d2Z.de$e$d3d4e/d5edeje	e(df dejee(f de*f
d6d7Z0d4e/de1ded8eje* de*f
d9d:Z2d4e/ded8eje* de*fd;d<Z3d4e/de*fd=d>Z4ddde$e$e$dd?d%ed	eje
 d
eje deje deje	e(f dejee(f dejee(f d.eje) de*fd@dAZ5ddde$e$e$dd?d%ed	eje
 d
eje deje deje	e(f dejee(f dejee(f d.eje) de*fdBdCZ6ddde$e$e$dd?d%ed	eje
 d
eje deje deje	e(f dejee(f dejee(f d.eje) de*fdDdEZ7ddddddde$e$e$dd(d%ed*eje% d+eje& d,eje' d-ejej d	eje
 d
eje deje deje	e(f dejee(f dejee(f d.eje) de*fdFdGZ8ddddddde$e$e$dd(d%ed*eje% d+eje& d,eje' d-ejej d	eje
 d
eje deje deje	e(f dejee(f dejee(f d.eje) de*fdHdIZ9ddddddde$e$e$dd(d%ed*eje% d+eje& d,eje' d-ejej d	eje
 d
eje deje deje	e(f dejee(f dejee(f d.eje) de*fdJdKZ:ddde$e$e$dd?d%ed	eje
 d
eje deje deje	e(f dejee(f dejee(f d.eje) de*fdLdMZ;dXdNdOZ<dPe=de=fdQdRZ>			dYdSejej?e@  dTeje@ dUejeA ddfdVdWZB  ZCS )Zr7   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).
    * **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".
    NTFrt   ru   rw   rx   ry   rz   verifycerthttp1http2r   mountsr{   r|   limitsr}   r~   r   	transportappr   r   rw   rx   ry   rz   r   r   r   r   r   r   r{   r|   r   r}   r~   r   r   r   .r   r   rR   c                      t  j||||||||||d r&zdd l}W n ty%   tdd w o/|d u o/|d u }|	|}j ||d_ fdd| D _|
d urgj	dd |
 D  t
tj _d S )Nrv   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   r   r   r   r   c                    :   i | ]\}}t ||d u rd nj| dqS Nr   r   r   r   r   r   r2   _init_proxy_transportrD   rE   r   r   r   r   r   rZ   r   r   r@   rA   r         z#Client.__init__.<locals>.<dictcomp>c                 S      i | ]	\}}t ||qS r@   r2   rD   rE   r   r@   r@   rA   r         superr[   h2ImportErrorr   _init_transport
_transportr   _mountsr   r   sortedrZ   rw   rx   ry   rz   r   r   r   r   r   r   r{   r|   r   r}   r~   r   r   r   r   r   r  r   	proxy_map	__class__r	  rA   r[   l  sV   
zClient.__init__c	           	      C   2   |d ur|S |d urt |dS t||||||dS N)r   r  )r   r   	rZ   r   r   r   r   r   r   r   r   r@   r@   rA   r       
zClient._init_transportr   c              	   C   s   t |||||||dS )N)r   r   r   r   r   r   r   )r   rZ   r   r   r   r   r   r   r   r@   r@   rA   r    s   
zClient._init_proxy_transportr   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  rZ   r   patternr   r@   r@   rA   _transport_for_url  
   
zClient._transport_for_urlr   r   r   r   rx   ry   rz   rw   r|   r{   r   r   r   r   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
        NzSetting 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   rx   ry   rz   r{   r   rw   r|   )warningswarnDeprecationWarningr   send)rZ   r   r   r   r   r   r   rx   ry   rz   rw   r|   r{   r   messager   r@   r@   rA   r     s$   !zClient.requestc                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   rw   r|   rO   N)r   r.  rg   rZ   r   r   r   r   r   r   rx   ry   rz   rw   r|   r{   r   r   rP   r@   r@   rA   rO   0  s.   zClient.streamrO   rw   r|   r   rO   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.rw   r|   historyN)r   rG   rL   RuntimeErrorrK   r   r;   r|   r   _send_handling_authreadBaseExceptionrg   rZ   r   rO   rw   r|   rP   r   r@   r@   rA   r.  d  s.   zClient.sendr5  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)r|   r5  )sync_auth_flownext_send_handling_redirectsr.  StopIterationrg   r   r5  r8  appendr9  	rZ   r   rw   r|   r5  	auth_flowrP   next_requestr   r@   r@   rA   r7    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   rP   )lenr}   r   r   _send_single_requestr   r5  has_redirect_locationr   r8  rC  r9  rg   rZ   r   r|   r5  hookrP   r   r@   r@   rA   r>    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rP   rQ   HTTP Request: %s %s "%s %d %s")r&  r   r1   
sync_startr   rO   r+   r6  r   handle_requestr   rN   rz   extract_cookiesr   r   loggerinfor   http_versionr   reason_phraserZ   r   r   rQ   rP   r@   r@   rA   rF    s4   	zClient._send_single_requestrx   ry   rz   rw   r|   r{   r   c          	      C      | j d||||||||d	S )U
        Send a `GET` request.

        **Parameters**: See `httpx.request`.
        r   rU  r   	rZ   r   rx   ry   rz   rw   r|   r{   r   r@   r@   rA   r         z
Client.getc          	      C   rV  )Z
        Send an `OPTIONS` request.

        **Parameters**: See `httpx.request`.
        OPTIONSrU  r   rX  r@   r@   rA   options  rY  zClient.optionsc          	      C   rV  )V
        Send a `HEAD` request.

        **Parameters**: See `httpx.request`.
        r   rU  r   rX  r@   r@   rA   head:  rY  zClient.headc                C   $   | j d|||||||||	|
||dS )V
        Send a `POST` request.

        **Parameters**: See `httpx.request`.
        r   r(  r   rZ   r   r   r   r   r   rx   ry   rz   rw   r|   r{   r   r@   r@   rA   postW     zClient.postc                C   r_  )U
        Send a `PUT` request.

        **Parameters**: See `httpx.request`.
        PUTr(  r   ra  r@   r@   rA   put|  rc  z
Client.putc                C   r_  )W
        Send a `PATCH` request.

        **Parameters**: See `httpx.request`.
        PATCHr(  r   ra  r@   r@   rA   patch  rc  zClient.patchc          	      C   rV  )X
        Send a `DELETE` request.

        **Parameters**: See `httpx.request`.
        DELETErU  r   rX  r@   r@   rA   delete  rY  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   rG   rL   r  rg   r  values)rZ   r   r@   r@   rA   rg     s   
zClient.closerZ   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   rG   rJ   rK   rL   r6  r  	__enter__r  rn  )rZ   msgr   r@   r@   rA   rp    s   
zClient.__enter__exc_type	exc_value	tracebackc                 C   sB   t j| _| j||| | j D ]}|d ur|||| qd S rT   )rG   rL   r   r  __exit__r  rn  )rZ   rr  rs  rt  r   r@   r@   rA   ru    s   zClient.__exit__ri   NNN)Dr<   r=   r>   r?   r   r
   r   rj   r   r!   r&   r$   r#   r.   r"   r   r%   r   r   r   r,   r   r   r   r   r-   r   r   r   rl   r[   r  r   r  r/   r&  r   r'   r(   r*   r;   r)   r   r   r   rk   rO   r   r.  r   r7  r>  rF  r   r\  r^  rb  rf  ri  rl  rg   r6   rp  Typer9  r   ru  __classcell__r@   r@   r  rA   r7   9  s   5	
U	

	

	

8
	
7
1
"
%(	

!	

!	

!
	

)
	

)
	

)	


c                -       s  e Zd ZdZddddddddddedeeddddddddeje	 d	eje
 d
eje deje dedeje dededeje dejejeef  dededededejejeejejdejf  f  dedeje dejejdejf  dedejeejegef f ddf* fddZddddedddfdedeje dedededeje dejejdejf  dedefd d!Zddddedfd"ededeje dededededefd#d$Z d%e!defd&d'Z"ddddddde#e#e#dd(d)ed%ed*eje$ d+eje% d,eje& d-ejej d	eje
 d
eje deje deje	e'df dejee'f dejee'f d.eje( de)fd/d0Z*e+ddddddde#e#e#dd(d)ed%ed*eje$ d+eje% d,eje& d-ejej d	eje
 d
eje deje deje	e'f dejee'f dejee'f d.eje( dej,e) fd1d2Z-de#e#d3d4e.d5edeje	e'df dejee'f de)f
d6d7Z/d4e.de0ded8eje) de)f
d9d:Z1d4e.ded8eje) de)fd;d<Z2d4e.de)fd=d>Z3ddde#e#e#dd?d%ed	eje
 d
eje deje deje	e'df dejee'f dejee'f d.eje( de)fd@dAZ4ddde#e#e#dd?d%ed	eje
 d
eje deje deje	e'f dejee'f dejee'f d.eje( de)fdBdCZ5ddde#e#e#dd?d%ed	eje
 d
eje deje deje	e'f dejee'f dejee'f d.eje( de)fdDdEZ6ddddddde#e#e#dd(d%ed*eje$ d+eje% d,eje& d-ejej d	eje
 d
eje deje deje	e'f dejee'f dejee'f d.eje( de)fdFdGZ7ddddddde#e#e#dd(d%ed*eje$ d+eje% d,eje& d-ejej d	eje
 d
eje deje deje	e'f dejee'f dejee'f d.eje( de)fdHdIZ8ddddddde#e#e#dd(d%ed*eje$ d+eje% d,eje& d-ejej d	eje
 d
eje deje deje	e'f dejee'f dejee'f d.eje( de)fdJdKZ9ddde#e#e#dd?d%ed	eje
 d
eje deje deje	e'f dejee'f dejee'f d.eje( de)fdLdMZ:dXdNdOZ;dPe<de<fdQdRZ=			dYdSejej>e?  dTeje? dUeje@ ddfdVdWZA  ZBS )Zr:   aC	  
    An asynchronous HTTP client, with connection pooling, HTTP/2, redirects,
    cookie persistence, etc.

    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`.
    * **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".
    NTFrt   ru   r   rw   rx   ry   rz   r   r   r   r   r   r   r{   r|   r   r}   r~   .r   r   r   r   r   rR   c                   r   )Nrv   r   r  r  c                    r  r  r  r  r	  r@   rA   r     r
  z(AsyncClient.__init__.<locals>.<dictcomp>c                 S   r  r@   r  r  r@   r@   rA   r     r  r  r  r  r	  rA   r[   A  sV   zAsyncClient.__init__c	           	      C   r  r  )r   r   r  r@   r@   rA   r    r  zAsyncClient._init_transportr   c                 C   s   t ||||||dS )N)r   r   r   r   r   r   )r   r  r@   r@   rA   r    s   
z!AsyncClient._init_proxy_transportr   c                 C   r   r!  r"  r$  r@   r@   rA   r&    r'  zAsyncClient._transport_for_urlr(  r   r   r   r   r   r   c                   s8   | 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
        r)  r*  N)r   r.  )rZ   r   r   r   r   r   r   rx   ry   rz   rw   r|   r{   r   r   r@   r@   rA   r     s   !zAsyncClient.requestc                C  sf   | j |||||||||	||d}| j||
|ddI dH }z|V  W | I dH  dS | I dH  w r0  )r   r.  rq   r1  r@   r@   rA   rO     s.   "zAsyncClient.streamr2  r   rO   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
        r3  r4  N)r   rG   rL   r6  rK   r   r;   r|   r   r7  areadr9  rq   r:  r@   r@   rA   r.  0  s0   zAsyncClient.sendr5  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 r;  )async_auth_flow	__anext__r>  asendStopAsyncIterationrq   r   r5  ry  r@  r9  rA  r@   r@   rA   r7  a  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rD  )rE  r}   r   r   rF  r   r5  rG  r   ry  rC  r9  rq   rH  r@   r@   rA   r>    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 )rJ  Nz?Attempted to send an sync request with an AsyncClient instance.r   rK  rL  )r&  r   r1   async_startr   rO   r    r6  r   handle_async_requestr   rn   rz   rO  r   r   rP  rQ  r   rR  r   rS  rT  r@   r@   rA   rF    s6   	z AsyncClient._send_single_requestrU  c          	         $   | j d||||||||d	I dH S )rW  r   rU  Nr   rX  r@   r@   rA   r        zAsyncClient.getc          	         r  )rZ  r[  rU  Nr   rX  r@   r@   rA   r\    r  zAsyncClient.optionsc          	         r  )r]  r   rU  Nr   rX  r@   r@   rA   r^    r  zAsyncClient.headc                   ,   | j d|||||||||	|
||dI dH S )r`  r   r(  Nr   ra  r@   r@   rA   rb  #      zAsyncClient.postc                   r  )rd  re  r(  Nr   ra  r@   r@   rA   rf  H  r  zAsyncClient.putc                   r  )rg  rh  r(  Nr   ra  r@   r@   rA   ri  m  r  zAsyncClient.patchc          	         r  )rj  rk  rU  Nr   rX  r@   r@   rA   rl    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 rm  )r   rG   rL   r  rq   r  rn  )rZ   r   r@   r@   rA   rq     s   zAsyncClient.acloserZ   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 ro  )
r   rG   rJ   rK   rL   r6  r  
__aenter__r  rn  )rZ   rq  r   r@   r@   rA   r    s   zAsyncClient.__aenter__rr  rs  rt  c                    sP   t j| _| j|||I d H  | j D ]}|d ur%||||I d H  qd S rT   )rG   rL   r   r  	__aexit__r  rn  )rZ   rr  rs  rt  r   r@   r@   rA   r    s   zAsyncClient.__aexit__ri   rv  )Cr<   r=   r>   r?   r   r
   r   rj   r   r!   r&   r$   r#   r.   r"   r   r%   r   r   r   r,   r   r   r   r   r   r-   r   rl   r[   r  r   r  r/   r&  r   r'   r(   r*   r;   r)   r   r   r   rr   rO   r   r.  r   r7  r>  rF  r   r\  r^  rb  rf  ri  rl  rq   r9   r  rw  r9  r   r  rx  r@   r@   r  rA   r:     s   6	
U	

	

	

0
	
7
1
"
&'	

!	

!	

!
	

)
	

)
	

)	


)\rd   enumloggingrj   r+  
contextlibr   r   typesr   r   r   r   r   r	   _configr
   r   r   r   r   r   	_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.   _urlsr/   r0   _utilsr1   r2   r3   r4   r5   TypeVarr6   r9   r;   r   	getLoggerrP  r   r   keysr   EnumrG   rN   rn   r   r   r   rs   r7   r:   r@   r@   r@   rA   <module>   sZ     D


        Y