o
    "`^h	                    @  sX  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? ddl@mAZAmBZB ddlCmDZDmEZEmFZFmGZGmHZH g dZIe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VerifyTypes)URLQueryParams)Timer
URLPatternget_environment_proxiesis_https_redirectsame_origin)USE_CLIENT_DEFAULTAsyncClientClientTr9   )boundUr8   c                   @  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   K/home/air/shanriGPT/back/venv/lib/python3.10/site-packages/httpx/_client.pyr=   D   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   c   s    rI   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   timerr2   returnNonec                 C     || _ || _|| _d S N_stream	_response_timerselfrQ   rR   rS   rB   rB   rC   __init__w      
zBoundSyncStream.__init__typing.Iterator[bytes]c                 c  s    | j D ]}|V  qd S rW   rY   r]   chunkrB   rB   rC   __iter__~   s   
zBoundSyncStream.__iter__c                 C  s(   | j  }tj|d| j_| j  d S N)seconds)r[   sync_elapseddatetime	timedeltarZ   elapsedrY   closer]   rf   rB   rB   rC   rk      s   
zBoundSyncStream.closeN)rQ   r-   rR   r   rS   r2   rT   rU   )rT   r`   rT   rU   )r>   r?   r@   rA   r^   rd   rk   rB   rB   rB   rC   rP   q   
    

rP   c                   @  rO   )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.
    rQ   r!   rR   r   rS   r2   rT   rU   c                 C  rV   rW   rX   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 rW   ra   rb   rB   rB   rC   	__aiter__   s   zBoundAsyncStream.__aiter__c                   s6   | j  I d H }tj|d| j_| j I d H  d S re   )r[   async_elapsedrh   ri   rZ   rj   rY   acloserl   rB   rB   rC   rs      s   zBoundAsyncStream.acloseN)rQ   r!   rR   r   rS   r2   rT   rU   )rT   rp   rm   )r>   r?   r@   rA   r^   rq   rs   rB   rB   rB   rC   ro      rn   ro   .c                   @  s  e Zd Zddddededddddd|ddZed}d d!Zed}d"d#Zd~d&d'Z	dd,d-Z
edd/d0Zejdd1d0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ddzd{Z dS )
BaseClientNF Tutf-8authparamsheaderscookiestimeoutfollow_redirectsmax_redirectsevent_hooksbase_url	trust_envdefault_encodingrx   AuthTypes | Nonery   QueryParamTypes | Nonerz   HeaderTypes | Noner{   CookieTypes | Noner|   r.   r}   boolr~   intr   +None | typing.Mapping[str, list[EventHook]]r   	URL | strr   r   #str | typing.Callable[[bytes], str]rT   rU   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requestrR   )r   rR   )_enforce_trailing_slashr0   	_base_url_build_auth_authr1   _paramsr   rz   r   _cookiesr   _timeoutr}   r~   listget_event_hooks
_trust_env_default_encodingrI   rL   _state)r]   rx   ry   rz   r{   r|   r}   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   rI   rN   r]   rB   rB   rC   	is_closed   s   zBaseClient.is_closedc                 C     | j S rW   )r   r   rB   rB   rC   r         zBaseClient.trust_envurlr0   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   )rF   rG   r   rB   rB   rC   
<dictcomp>   s    z-BaseClient._get_proxy_map.<locals>.<dictcomp>r   zall://)r4   items
isinstancedictstrr0   r   )r]   r   r   new_proxiesrG   valueproxyrB   rB   rC   _get_proxy_map   s   
zBaseClient._get_proxy_mapr   c                 C  r   rW   )r   r   rB   rB   rC   r|      r   zBaseClient.timeoutc                 C     t || _d S rW   )r   r   )r]   r|   rB   rB   rC   r|         dict[str, list[EventHook]]c                 C  r   rW   )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   rx      s   	zBaseClient.authr"   c                 C  s   |  || _d S rW   )r   r   r]   rx   rB   rB   rC   rx     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 rW   )r   r0   r   r   rB   rB   rC   r     s   r   c                 C  r   )z@
        HTTP headers to include when sending requests.
        )_headersr   rB   rB   rC   rz     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]   rz   client_headersrB   rB   rC   rz     s   

r   c                 C  r   )zA
        Cookie values to include when sending requests.
        )r   r   rB   rB   rC   r{   *  r   zBaseClient.cookiesr$   c                 C  r   rW   )r   r   )r]   r{   rB   rB   rC   r{   1  r   r1   c                 C  r   )zO
        Query parameters to include in the URL when sending requests.
        )r   r   rB   rB   rC   ry   5  r   zBaseClient.paramsr(   c                 C  r   rW   )r1   r   )r]   ry   rB   rB   rC   ry   <  r   )	contentdatafilesjsonry   rz   r{   r|   
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 )aR  
        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/clients/#request-instances
        Nr|   )r   r   r   r   ry   rz   r{   r   rB   )
_merge_url_merge_headers_merge_cookies_merge_queryparamsr   r=   r|   r   r   as_dictr   )r]   r   r   r   r   r   r   ry   rz   r{   r|   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   )r0   is_relative_urlr   r   lstripr   )r]   r   	merge_urlmerge_raw_pathrB   rB   rC   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.
        )r{   r   r   )r]   r{   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   rz   r   )r]   rz   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.
        )ry   r1   merge)r]   ry   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   rx   r   r   rB   rB   rC   _build_request_auth  s   zBaseClient._build_request_authrR   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   rz   r{   rQ   r   )_redirect_method_redirect_url_redirect_headers_redirect_streamr   r{   r   r   )r]   r   rR   r   r   rz   rQ   r{   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   rR   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.
        Locationz Invalid URL in location header: .r   N)host)fragment)rz   r0   r   r   schemer   r   r   r   joinr   )r]   r   rR   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   rz   r6   r   r5   popnetlocdecoder   )r]   r   r   r   rz   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   rQ   )r]   r   r   rB   rB   rC   r   )  s   zBaseClient._redirect_streamc                 C  sL   d|j vr$t| jtr| jnt| j}tdi |j d| i|_ d S d S )Nr|   rB   )r   r   r|   r=   r   r   r   )r]   r   r|   rB   rB   rC   _set_timeout4  s   

"zBaseClient._set_timeout)rx   r   ry   r   rz   r   r{   r   r|   r.   r}   r   r~   r   r   r   r   r   r   r   r   r   rT   rU   )rT   r   )r   r0   rT   r0   )r   r   r   r   rT   r   )rT   r   )r|   r.   rT   rU   )rT   r   )r   r   rT   rU   )rT   r   )rx   r"   rT   rU   )rT   r0   )r   r   rT   rU   )rT   r   )rz   r%   rT   rU   )rT   r   )r{   r$   rT   rU   )rT   r1   )ry   r(   rT   rU   )r   r   r   r   r   r   r   r   r   r   r   r   ry   r   rz   r   r{   r   r|   r   r   r   rT   r   )r   r   rT   r0   rW   )r{   r   rT   r   )rz   r   rT   r   )ry   r   rT   r   )rx   r   rT   r   )r   r   rx   r   rT   r   )r   r   rR   r   rT   r   )r   r   rR   r   rT   r   )r   r   rR   r   rT   r0   )r   r   r   r0   r   r   rT   r   )r   r   r   r   rT   r   )r   r   rT   rU   )!r>   r?   r@   r   r   r^   propertyr   r   r   r   r|   setterr   rx   r   rz   r{   ry   r7   r   r   r   r   r   r   r   r   r   r   r   r   r   rB   rB   rB   rC   rt      s    "



3






rt   c                        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ddcdd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".
    NTFru   rv   rx   ry   rz   r{   verifycerthttp1http2r   r   mountsr|   r}   limitsr~   r   r   	transportappr   r   rx   r   ry   r   rz   r   r{   r   r  r/   r  CertTypes | Noner  r   r  r   ProxyTypes | Noner   r   r	  0None | typing.Mapping[str, BaseTransport | None]r|   r.   r}   r
  r   r~   r   r   r   r   r   r  BaseTransport | Noner  'typing.Callable[..., typing.Any] | Noner   r   r   rT   rU   c                    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 )Nrw   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   r3   _init_proxy_transportrF   rG   r   r  r  r  r
  r]   r   r  rB   rC   r         z#Client.__init__.<locals>.<dictcomp>c                 S     i | ]	\}}t ||qS rB   r3   rF   rG   r  rB   rB   rC   r         superr^   h2ImportErrorwarningswarnDeprecationWarningRuntimeErrorr   _init_transport
_transportr   _mountsr   r   sortedr]   rx   ry   rz   r{   r  r  r  r  r   r   r	  r|   r}   r
  r~   r   r   r  r  r   r   r%  messager   	proxy_map	__class__r  rC   r^   t  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   r0   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   ry   rz   r{   rx   r}   r|   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/clients/#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   ry   rz   r{   r|   r   rx   r}   r'  r(  r)  r   sendr]   r   r   r   r   r   r   ry   rz   r{   rx   r}   r|   r   r0  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
        rG  T)r   rx   r}   rQ   N)r   rJ  rk   r]   r   r   r   r   r   r   ry   rz   r{   rx   r}   r|   r   r   rR   rB   rB   rC   rQ   G  s.   zClient.streamrQ   rx   r}   r   r   rQ   c             
   C  s   | j tjkr
tdtj| _ t|tr| jn|}| | | 	||}| j
|||g d}z	|s3|  |W S  tyG } 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/clients/#request-instances
        5Cannot send a request, as the client has been closed.rx   r}   historyN)r   rI   rN   r*  rM   r   r=   r}   r   r   _send_handling_authreadBaseExceptionrk   r]   r   rQ   rx   r}   rR   r   rB   rB   rC   rJ  {  s0   
zClient.sendr   rR  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)r}   rR  )sync_auth_flownext_send_handling_redirectsrJ  StopIterationrk   r   rR  rT  appendrU  	r]   r   rx   r}   rR  	auth_flowrR   next_requestr   rB   rB   rC   rS    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   rR   )lenr~   r   r   _send_single_requestr   rR  has_redirect_locationr   rT  r`  rU  rk   r]   r   r}   rR  hookrR   r   rB   rB   rC   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rR   rS   HTTP Request: %s %s "%s %d %s")rB  r   r2   
sync_startr   rQ   r-   r*  r   handle_requestr   rP   r{   extract_cookiesr   r   loggerinfor   http_versionr   reason_phraser]   r   r  rS   rR   rB   rB   rC   rc    s4   	zClient._send_single_requestry   rz   r{   rx   r}   r|   r   c          	      C     | j d||||||||d	S )U
        Send a `GET` request.

        **Parameters**: See `httpx.request`.
        r   rr  r   	r]   r   ry   rz   r{   rx   r}   r|   r   rB   rB   rC   r        z
Client.getAuthTypes | UseClientDefaultc          	      C  rs  )Z
        Send an `OPTIONS` request.

        **Parameters**: See `httpx.request`.
        OPTIONSrr  r   ru  rB   rB   rC   options6  rv  zClient.optionsc          	      C  rs  )V
        Send a `HEAD` request.

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

        **Parameters**: See `httpx.request`.
        r   rD  r   r]   r   r   r   r   r   ry   rz   r{   rx   r}   r|   r   rB   rB   rC   postp     zClient.postc                C  r}  )U
        Send a `PUT` request.

        **Parameters**: See `httpx.request`.
        PUTrD  r   r  rB   rB   rC   put  r  z
Client.putc                C  r}  )W
        Send a `PATCH` request.

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

        **Parameters**: See `httpx.request`.
        DELETErr  r   ru  rB   rB   rC   delete  rv  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   rI   rN   r,  rk   r-  values)r]   r  rB   rB   rC   rk     s   
zClient.closer]   r:   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   rI   rL   rM   rN   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 rW   )rI   rN   r   r,  __exit__r-  r  )r]   r  r  r  r  rB   rB   rC   r    s   zClient.__exit__),rx   r   ry   r   rz   r   r{   r   r  r/   r  r  r  r   r  r   r   r  r   r   r	  r  r|   r.   r}   r   r
  r   r~   r   r   r   r   r   r  r  r  r  r   r   r   r   rT   rU   )r  r/   r  r  r  r   r  r   r
  r   r  r  r  r  r   r   rT   r   )r   r   r  r/   r  r  r  r   r  r   r
  r   r   r   rT   r   )r   r0   rT   r   r   r   r   r   r   r   r   r   r   r   r   r   ry   r   rz   r   r{   r   rx   r   r}   rE  r|   r   r   r   rT   r   )r   r   r   r   r   r   r   r   r   r   r   r   ry   r   rz   r   r{   r   rx   r   r}   rE  r|   r   r   r   rT   rL  
r   r   rQ   r   rx   r   r}   rE  rT   r   
r   r   rx   r   r}   r   rR  rW  rT   r   r   r   r}   r   rR  rW  rT   r   r   r   rT   r   r   r   ry   r   rz   r   r{   r   rx   r   r}   rE  r|   r   r   r   rT   r   r   r   ry   r   rz   r   r{   r   rx   rw  r}   rE  r|   r   r   r   rT   r   r   r   r   r   r   r   r   r   r   r   ry   r   rz   r   r{   r   rx   rw  r}   rE  r|   r   r   r   rT   r   rm   )r]   r:   rT   r:   NNNr  r  r  r  r  r  rT   rU   )r>   r?   r@   rA   r   r   r   r^   r+  r  rB  r7   r   r   rQ   rJ  rS  r[  rc  r   rz  r|  r  r  r  r  rk   r  r  __classcell__rB   rB   r2  rC   r9   >  s&   8d
87
3
"
%(!!!)))

c                      r  )r8   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".
    NTFru   rv   r  rx   r   ry   r   rz   r   r{   r   r  r/   r  r  r  r   r  r   r  r   r   r	  5None | typing.Mapping[str, AsyncBaseTransport | None]r|   r.   r}   r
  r   r~   r   r   r   r   r   r  AsyncBaseTransport | Noner  r  r   r   r   rT   rU   c                  r  )Nrw   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/  r2  r  rC   r^   _  sj   zAsyncClient.__init__r   c	           	      C  r4  r5  )r   r   r6  rB   rB   rC   r+    r7  zAsyncClient._init_transportr   c              	   C  r8  r9  )r   r:  rB   rB   rC   r    r;  z!AsyncClient._init_proxy_transportr   r0   c                 C  r<  r=  r>  r@  rB   rB   rC   rB    rC  zAsyncClient._transport_for_urlrD  r   r   r   r   r   r   r   r   r   r   r   rE  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/clients/#merging-of-configuration
        NrF  rG  rH  rI  rK  rB   rB   rC   r     s&   "zAsyncClient.request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 rM  )r   rJ  rs   rN  rB   rB   rC   rQ   3  s.   "zAsyncClient.streamrO  r   r   rQ   c             
     s   | j tjkrtdtj| _ t|tr| jn|}| | | 	||}| j
|||g dI dH }z|s:| I dH  |W S  tyQ } 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/clients/#request-instances
        rP  rQ  N)r   rI   rN   r*  rM   r   r=   r}   r   r   rS  areadrU  rs   rV  rB   rB   rC   rJ  g  s2   
zAsyncClient.sendr   rR  rW  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 rX  )async_auth_flow	__anext__r[  asendStopAsyncIterationrs   r   rR  r  r]  rU  r^  rB   rB   rC   rS    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ra  )rb  r~   r   r   rc  r   rR  rd  r   r  r`  rU  rs   re  rB   rB   rC   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 )rg  Nz?Attempted to send an sync request with an AsyncClient instance.r   rh  ri  )rB  r   r2   async_startr   rQ   r!   r*  r   handle_async_requestr   ro   r{   rl  r   r   rm  rn  r   ro  r   rp  rq  rB   rB   rC   rc    s6   	z AsyncClient._send_single_requestrr  c          	        $   | j d||||||||d	I dH S )rt  r   rr  Nr   ru  rB   rB   rC   r        zAsyncClient.getrw  c          	        r  )rx  ry  rr  Nr   ru  rB   rB   rC   rz  "  r  zAsyncClient.optionsc          	        r  )r{  r   rr  Nr   ru  rB   rB   rC   r|  ?  r  zAsyncClient.headc                  ,   | j d|||||||||	|
||dI dH S )r~  r   rD  Nr   r  rB   rB   rC   r  \      zAsyncClient.postc                  r  )r  r  rD  Nr   r  rB   rB   rC   r    r  zAsyncClient.putc                  r  )r  r  rD  Nr   r  rB   rB   rC   r    r  zAsyncClient.patchc          	        r  )r  r  rr  Nr   ru  rB   rB   rC   r    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   rI   rN   r,  rs   r-  r  )r]   r   rB   rB   rC   rs     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   rI   rL   rM   rN   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 rW   )rI   rN   r   r,  	__aexit__r-  r  )r]   r  r  r  r   rB   rB   rC   r    s   zAsyncClient.__aexit__),rx   r   ry   r   rz   r   r{   r   r  r/   r  r  r  r   r  r   r   r  r   r   r	  r  r|   r.   r}   r   r
  r   r~   r   r   r   r   r   r  r  r  r  r   r   r   r   rT   rU   )r  r/   r  r  r  r   r  r   r
  r   r  r  r  r  r   r   rT   r   )r   r   r  r/   r  r  r  r   r  r   r
  r   r   r   rT   r   )r   r0   rT   r   r  )r   r   r   r   r   r   r   r   r   r   r   r   ry   r   rz   r   r{   r   rx   r   r}   rE  r|   r   r   r   rT   r  r  r  r  r  r  r  r  rm   )r]   r<   rT   r<   r  r  )r>   r?   r@   rA   r   r   r   r^   r+  r  rB  r7   r   r   rQ   rJ  rS  r[  rc  r   rz  r|  r  r  r  r  rs   r  r  r  rB   rB   r2  rC   r8   (  s&   9d
97
3
"
&'!!!)))

)_
__future__r   rh   enumloggingtypingr'  
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/   _urlsr0   r1   _utilsr2   r3   r4   r5   r6   __all__TypeVarr:   r<   r=   r7   	getLoggerrm  r   r   keysr   EnumrI   rP   ro   CallableAny	EventHookrt   r9   r8   rB   rB   rB   rC   <module>   s^     D

        o