o
    h                     @  s`  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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(m)Z) ddl*m+Z+m,Z, ddl-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z: ddl;m<Z<m=Z= ddl>m?Z?m@Z@ ejArd dlBZBg dZCejDdddZEejDdddZFd7ddZGd8d d!ZHd9d#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/e9ZTG d0d1 d1e.ZUejVd2ejWf ZXG d3d4 d4ZYG d5d deYZZG d6d deY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)AsyncBaseTransportBaseTransport)AsyncHTTPTransportHTTPTransport)AsyncByteStream	AuthTypes	CertTypesCookieTypesHeaderTypes
ProxyTypesQueryParamTypesRequestContentRequestDataRequestExtensionsRequestFilesSyncByteStreamTimeoutTypes)URLQueryParams)
URLPatternget_environment_proxies)USE_CLIENT_DEFAULTAsyncClientClientTr2   )boundUr1   urlr,   locationreturnboolc                 C  s<   | j |j krdS | jdkot| dko|jdkot|dkS )zA
    Return 'True' if 'location' is a HTTPS upgrade of 'url'
    FhttpP   https  )hostscheme_port_or_default)r6   r7    rA   a/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/httpx/_client.py_is_https_redirect>   s   


rC   
int | Nonec                 C  s"   | j d ur| j S ddd| jS )Nr;   r=   )r:   r<   )portgetr?   r6   rA   rA   rB   r@   M   s   
r@   otherc                 C  s(   | j |j ko| j|jkot| t|kS )z@
    Return 'True' if the given URLs share the same origin.
    )r?   r>   r@   )r6   rH   rA   rA   rB   _same_originS   s
   
rI   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__rA   rA   rA   rB   rJ   ^   s    rJ   httpxzpython-httpx/z, c                 C  s   g | ]}|d kr|qS )identityrA   ).0keyrA   rA   rB   
<listcomp>y   s    rS   c                   @  s   e Zd ZdZdZdZdS )ClientStater         N)rK   rL   rM   UNOPENEDOPENEDCLOSEDrA   rA   rA   rB   rT   }   s    rT   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   startfloatr8   Nonec                 C     || _ || _|| _d S N_stream	_response_startselfr\   r]   r^   rA   rA   rB   __init__      
zBoundSyncStream.__init__typing.Iterator[bytes]c                 c  s    | j D ]}|V  qd S rb   rd   rh   chunkrA   rA   rB   __iter__   s   
zBoundSyncStream.__iter__c                 C  s,   t  | j }tj|d| j_| j  d S N)seconds)	timeperf_counterrf   datetime	timedeltare   elapsedrd   closerh   rv   rA   rA   rB   rw      s   zBoundSyncStream.closeN)r\   r*   r]   r   r^   r_   r8   r`   )r8   rk   r8   r`   )rK   rL   rM   rN   ri   ro   rw   rA   rA   rA   rB   r[      
    

r[   c                   @  rZ   )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   r]   r   r^   r_   r8   r`   c                 C  ra   rb   rc   rg   rA   rA   rB   ri      rj   zBoundAsyncStream.__init__typing.AsyncIterator[bytes]c                 C s"   | j 2 z	3 d H W }|V  q6 d S rb   rl   rm   rA   rA   rB   	__aiter__   s   zBoundAsyncStream.__aiter__c                   s4   t  | j }tj|d| j_| j I d H  d S rp   )	rr   rs   rf   rt   ru   re   rv   rd   acloserx   rA   rA   rB   r~      s   zBoundAsyncStream.acloseN)r\   r   r]   r   r^   r_   r8   r`   )r8   r|   ry   )rK   rL   rM   rN   ri   r}   r~   rA   rA   rA   rB   r{      rz   r{   .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_encodingr   AuthTypes | Noner   QueryParamTypes | Noner   HeaderTypes | Noner   CookieTypes | Noner   r+   r   r9   r   intr   +None | typing.Mapping[str, list[EventHook]]r   	URL | strr   r   #str | typing.Callable[[bytes], str]r8   r`   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requestr]   )r   r]   )_enforce_trailing_slashr,   	_base_url_build_auth_authr-   _paramsr   r   r   _cookiesr   _timeoutr   r   listrF   _event_hooks
_trust_env_default_encodingrT   rW   _state)rh   r   r   r   r   r   r   r   r   r   r   r   rA   rA   rB   ri      s   



zBaseClient.__init__c                 C  s   | j tjkS )z2
        Check if the client being closed
        )r   rT   rY   rh   rA   rA   rB   	is_closed   s   zBaseClient.is_closedc                 C     | j S rb   )r   r   rA   rA   rB   r         zBaseClient.trust_envr6   r,   c                 C  s"   |j dr|S |j|j d dS )N   /raw_path)r   endswith	copy_withrh   r6   rA   rA   rB   r      s   z"BaseClient._enforce_trailing_slashproxyProxyTypes | Noneallow_env_proxiesdict[str, Proxy | None]c                 C  sH   |d u r|rdd t   D S i S t|ttfrt|dn|}d|iS )Nc                 S  s(   i | ]\}}||d u rd nt |dqS )NrG   )r   )rQ   rR   r6   rA   rA   rB   
<dictcomp>   s    z-BaseClient._get_proxy_map.<locals>.<dictcomp>rG   zall://)r/   items
isinstancestrr,   r   )rh   r   r   rA   rA   rB   _get_proxy_map   s   zBaseClient._get_proxy_mapr   c                 C  r   rb   )r   r   rA   rA   rB   r      r   zBaseClient.timeoutc                 C     t || _d S rb   )r   r   )rh   r   rA   rA   rB   r        dict[str, list[EventHook]]c                 C  r   rb   )r   r   rA   rA   rB   r     r   zBaseClient.event_hooksc                 C  s(   t |dg t |dg d| _d S r   )r   rF   r   )rh   r   rA   rA   rB   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   rA   rA   rB   r     s   	zBaseClient.authr    c                 C  s   |  || _d S rb   )r   r   rh   r   rA   rA   rB   r     s   c                 C  r   )zK
        Base URL to use when sending requests with relative URLs.
        )r   r   rA   rA   rB   r        zBaseClient.base_urlc                 C  s   |  t|| _d S rb   )r   r,   r   r   rA   rA   rB   r   &  s   r   c                 C  r   )z@
        HTTP headers to include when sending requests.
        )_headersr   rA   rA   rB   r   *  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   )rh   r   client_headersrA   rA   rB   r   1  s   

r   c                 C  r   )zA
        Cookie values to include when sending requests.
        )r   r   rA   rA   rB   r   >  r   zBaseClient.cookiesr"   c                 C  r   rb   )r   r   )rh   r   rA   rA   rB   r   E  r   r-   c                 C  r   )zO
        Query parameters to include in the URL when sending requests.
        )r   r   rA   rA   rB   r   I  r   zBaseClient.paramsr%   c                 C  r   rb   )r-   r   )rh   r   rA   rA   rB   r   P  r   )	contentdatafilesjsonr   r   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   r   r   r   r   rA   )
_merge_url_merge_headers_merge_cookies_merge_queryparamsr   rJ   r   r   dictas_dictr   )rh   r   r6   r   r   r   r   r   r   r   r   r   rA   rA   rB   build_requestT  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   )rh   r6   	merge_urlmerge_raw_pathrA   rA   rB   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.
        )r   r   r   )rh   r   merged_cookiesrA   rA   rB   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   r   r   )rh   r   merged_headersrA   rA   rB   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.
        )r   r-   merge)rh   r   merged_queryparamsrA   rA   rB   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   rA   rA   rB   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   rJ   r   r   r6   r   r   r	   r   )rh   r   r   r   r   rA   rA   rB   _build_request_auth  s   zBaseClient._build_request_authr]   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   r6   r   r   r\   r   )_redirect_method_redirect_url_redirect_headers_redirect_streamr   r   r   r   )rh   r   r]   r   r6   r   r\   r   rA   rA   rB   _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)rh   r   r]   r   rA   rA   rB   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)r>   )fragment)r   r,   r   r   r?   r>   r   r6   r   joinr   )rh   r   r]   r7   r6   excrA   rA   rB   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   r   rI   r6   rC   popnetlocdecoder   )rh   r   r6   r   r   rA   rA   rB   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   r\   )rh   r   r   rA   rA   rB   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   rA   )r   r   r   rJ   r   r   r   )rh   r   r   rA   rA   rB   _set_timeoutH  s   

"zBaseClient._set_timeout)r   r   r   r   r   r   r   r   r   r+   r   r9   r   r   r   r   r   r   r   r9   r   r   r8   r`   )r8   r9   )r6   r,   r8   r,   )r   r   r   r9   r8   r   )r8   r   )r   r+   r8   r`   )r8   r   )r   r   r8   r`   )r8   r   )r   r    r8   r`   )r8   r,   )r6   r   r8   r`   )r8   r   )r   r#   r8   r`   )r8   r   )r   r"   r8   r`   )r8   r-   )r   r%   r8   r`   )r   r   r6   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r8   r   )r6   r   r8   r,   rb   )r   r   r8   r   )r   r   r8   r   )r   r   r8   r   )r   r   r8   r   )r   r   r   r   r8   r   )r   r   r]   r   r8   r   )r   r   r]   r   r8   r   )r   r   r]   r   r8   r,   )r   r   r6   r,   r   r   r8   r   )r   r   r   r   r8   r   )r   r   r8   r`   )!rK   rL   rM   r   r   ri   propertyr   r   r   r   r   setterr   r   r   r   r   r   r0   r   r   r   r   r   r   r   r   r   r   r   r   r  rA   rA   rA   rB   r      s    "



3






r   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| fd-d.Zdddddedfd}d0d1Zdddddefd~d3d4Z	dd7d8Z
dddddddeeedd9ddJdKZedddddddeeedd9ddMdNZdeedOddSdTZddXdYZddZd[Zdd\d]Zdddeeedd^dd_d`Zdddeeedd^ddbdcZdddeeedd^ddddeZdddddddeeedd9ddfdgZdddddddeeedd9ddhdiZdddddddeeedd9ddjdkZdddeeedd^ddldmZddndoZddrdsZ			dddzd{Z  ZS )r2   av  
    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)* Either `True` to use an SSL context with the
    default CA bundle, `False` to disable verification, or an instance of
    `ssl.SSLContext` to use a custom context.
    * **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.
    * **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.
    * **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".
    NTFr   r   )r   r   r   r   verifycertr   http1http2r   mountsr   r   limitsr   r   r   	transportr   r   r   r   r   r   r   r   r   r  ssl.SSLContext | str | boolr  CertTypes | Noner   r9   r  r  r   r   r  0None | typing.Mapping[str, BaseTransport | None]r   r+   r   r	  r   r   r   r   r   r   r   r
  BaseTransport | Noner   r   r8   r`   c                  s   t  j||||||||||d r&zdd l}W n ty%   tdd w o+|d u }|
|}j |d_ fdd| D _|d urbj	dd | D  t
tj _d S )Nr   r   uUsing http2=True, but the 'h2' package is not installed. Make sure to install httpx using `pip install httpx[http2]`.r  r  r   r  r  r	  r
  c                   :   i | ]\}}t ||d u rd nj| dqS N)r  r  r   r  r  r	  r.   _init_proxy_transportrQ   rR   r   r  r  r  r	  rh   r   r  rA   rB   r         z#Client.__init__.<locals>.<dictcomp>c                 S     i | ]	\}}t ||qS rA   r.   rQ   rR   r
  rA   rA   rB   r         superri   h2ImportErrorr   _init_transport
_transportr   _mountsr   r   sorted)rh   r   r   r   r   r  r  r   r  r  r   r  r   r   r	  r   r   r   r
  r   r  r   	proxy_map	__class__r  rB   ri     sT   	zClient.__init__r   c                 C      |d ur|S t ||||||dS r  r   rh   r  r  r   r  r  r	  r
  rA   rA   rB   r        
zClient._init_transportr   c              	   C     t |||||||dS N)r  r  r   r  r  r	  r   r(  rh   r   r  r  r   r  r  r	  rA   rA   rB   r       
zClient._init_proxy_transportr6   r,   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!  rh   r6   patternr
  rA   rA   rB   _transport_for_url  
   
zClient._transport_for_urlr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   bool | UseClientDefaultr   r   r   r   c                C  sL   |	durd}t j|tdd | 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.rU   
stacklevelr   r6   r   r   r   r   r   r   r   r   r   r   r   warningswarnDeprecationWarningr   sendrh   r   r6   r   r   r   r   r   r   r   r   r   r   r   messager   rA   rA   rB   r     s$   !zClient.requesttyping.Iterator[Response]c                c  sT    | j |||||||||	||d}| j||
|dd}z
|V  W |  dS |  w a  
        Alternative to `httpx.request()` that streams the response body
        instead of loading it into memory at once.

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

        See also: [Streaming Responses][0]

        [0]: /quickstart#streaming-responses
        r<  T)r   r   r   r\   N)r   rB  rw   rh   r   r6   r   r   r   r   r   r   r   r   r   r   r   r   r]   rA   rA   rB   r\   ;  s.   zClient.streamr\   r   r   r   r   r\   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.r   r   historyN)r   rT   rY   RuntimeErrorrX   r   rJ   r   r  r   _send_handling_authreadBaseExceptionrw   rh   r   r\   r   r   r]   r   rA   rA   rB   rB  o  s0   
zClient.sendr   rK  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   rK  )sync_auth_flownext_send_handling_redirectsrB  StopIterationrw   r   rK  rN  appendrO  	rh   r   r   r   rK  	auth_flowr]   next_requestr   rA   rA   rB   rM    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   r]   )lenr   r   r   _send_single_requestr   rK  has_redirect_locationr   rN  rZ  rO  rw   rh   r   r   rK  hookr]   r   rA   rA   rB   rU    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s6J ||_
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r]   r^   HTTP Request: %s %s "%s %d %s")r5  r6   rr   rs   r   r\   r*   rL  r   handle_requestr   r[   r   extract_cookiesr   r   loggerinfor   http_versionr   reason_phraserh   r   r
  r^   r]   rA   rA   rB   r]    s2   	zClient._send_single_requestr   r   r   r   r   r   r   c          	      C     | j d||||||||d	S )U
        Send a `GET` request.

        **Parameters**: See `httpx.request`.
        r   rk  r   	rh   r6   r   r   r   r   r   r   r   rA   rA   rB   rF        z
Client.getAuthTypes | UseClientDefaultc          	      C  rl  )Z
        Send an `OPTIONS` request.

        **Parameters**: See `httpx.request`.
        OPTIONSrk  r   rn  rA   rA   rB   options)  ro  zClient.optionsc          	      C  rl  )V
        Send a `HEAD` request.

        **Parameters**: See `httpx.request`.
        r   rk  r   rn  rA   rA   rB   headF  ro  zClient.headc                C  $   | j d|||||||||	|
||dS )V
        Send a `POST` request.

        **Parameters**: See `httpx.request`.
        r   r7  r   rh   r6   r   r   r   r   r   r   r   r   r   r   r   rA   rA   rB   postc     zClient.postc                C  rv  )U
        Send a `PUT` request.

        **Parameters**: See `httpx.request`.
        PUTr7  r   rx  rA   rA   rB   put  rz  z
Client.putc                C  rv  )W
        Send a `PATCH` request.

        **Parameters**: See `httpx.request`.
        PATCHr7  r   rx  rA   rA   rB   patch  rz  zClient.patchc          	      C  rl  )X
        Send a `DELETE` request.

        **Parameters**: See `httpx.request`.
        DELETErk  r   rn  rA   rA   rB   delete  ro  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   rT   rY   r!  rw   r"  values)rh   r
  rA   rA   rB   rw     s   
zClient.closerh   r3   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   rT   rW   rX   rY   rL  r!  	__enter__r"  r  )rh   msgr
  rA   rA   rB   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 rb   )rT   rY   r   r!  __exit__r"  r  )rh   r  r  r  r
  rA   rA   rB   r    s   zClient.__exit__)(r   r   r   r   r   r   r   r   r  r  r  r  r   r9   r  r9   r  r9   r   r   r  r  r   r+   r   r9   r	  r   r   r   r   r   r   r   r
  r  r   r   r8   r`   )r  r  r  r  r   r9   r  r9   r  r9   r	  r   r
  r  r8   r   )r   r   r  r  r  r  r   r9   r  r9   r  r9   r	  r   r8   r   )r6   r,   r8   r   r   r   r6   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r8  r   r   r   r   r8   r   )r   r   r6   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r8  r   r   r   r   r8   rE  
r   r   r\   r9   r   r   r   r8  r8   r   
r   r   r   r   r   r9   rK  rQ  r8   r   r   r   r   r9   rK  rQ  r8   r   r   r   r8   r   r6   r   r   r   r   r   r   r   r   r   r   r8  r   r   r   r   r8   r   r6   r   r   r   r   r   r   r   r   rp  r   r8  r   r   r   r   r8   r   r6   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rp  r   r8  r   r   r   r   r8   r   ry   )rh   r3   r8   r3   NNNr  r  r  r  r  r  r8   r`   )rK   rL   rM   rN   r   r   r   ri   r   r  r5  r0   r   r   r\   rB  rM  rU  r]  rF   rs  ru  ry  r}  r  r  rw   r  r  __classcell__rA   rA   r%  rB   r2   R  s    /Q
87
3
"
%'!!!)))

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| fd-d.Zdddddedfd}d0d1Zdddddefd~d3d4Z	dd7d8Z
dddddddeeedd9ddJdKZedddddddeeedd9ddMdNZdeedOddSdTZddXdYZddZd[Zdd\d]Zdddeeedd^dd_d`Zdddeeedd^ddbdcZdddeeedd^ddddeZdddddddeeedd9ddfdgZdddddddeeedd9ddhdiZdddddddeeedd9ddjdkZdddeeedd^ddldmZddndoZddrdsZ			dddzd{Z  ZS )r1   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)* Either `True` to use an SSL context with the
    default CA bundle, `False` to disable verification, or an instance of
    `ssl.SSLContext` to use a custom context.
    * **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.
    * **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.
    * **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".
    NTFr   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  r9   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   r8   r`   c                  s   t  j||||||||||d r&zdd l}W n ty%   tdd w o+|d u }|	|}j |d_ fdd| D _|
d urbj	dd |
 D  t
tj _d S )Nr   r   r  r  c                   r  r  r  r  r  rA   rB   r     r  z(AsyncClient.__init__.<locals>.<dictcomp>c                 S  r  rA   r  r  rA   rA   rB   r     r  r  )rh   r   r   r   r   r  r  r  r  r   r  r   r   r	  r   r   r   r
  r   r   r  r   r$  r%  r  rB   ri   I  sT   
zAsyncClient.__init__r   c                 C  r'  r  r   r)  rA   rA   rB   r     r*  zAsyncClient._init_transportr   c              	   C  r+  r,  r  r-  rA   rA   rB   r    r.  z!AsyncClient._init_proxy_transportr6   r,   c                 C  r/  r0  r1  r3  rA   rA   rB   r5    r6  zAsyncClient._transport_for_urlr7  r   r   r   r   r   r   r   r   r   r   r   r8  r   r   r   r   c                  sT   |	durd}t j|tdd | 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
        Nr9  rU   r:  r<  r=  r>  rC  rA   rA   rB   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 rF  )r   rB  r~   rG  rA   rA   rB   r\     s.   "zAsyncClient.streamrH  r   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|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
        rI  rJ  N)r   rT   rY   rL  rX   r   rJ   r   r  r   rM  areadrO  r~   rP  rA   rA   rB   rB  :  s2   
zAsyncClient.sendr   rK  rQ  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 rR  )async_auth_flow	__anext__rU  asendStopAsyncIterationr~   r   rK  r  rW  rO  rX  rA   rA   rB   rM  m  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r[  )r\  r   r   r   r]  r   rK  r^  r   r  rZ  rO  r~   r_  rA   rA   rB   rU    s8   

z$AsyncClient._send_handling_redirectsc                   s   |  |j}t }t|jtstdt|d |	|I dH }W d   n1 s-w   Y  t|jts:J ||_
t|j||d|_| j| | j|_td|j|j|j|j|j |S )ra  z?Attempted to send an sync request with an AsyncClient instance.r   Nrb  rc  )r5  r6   rr   rs   r   r\   r   rL  r   handle_async_requestr   r{   r   re  r   r   rf  rg  r   rh  r   ri  rj  rA   rA   rB   r]    s4   	z AsyncClient._send_single_requestrk  c          	        $   | j d||||||||d	I dH S )rm  r   rk  Nr   rn  rA   rA   rB   rF        zAsyncClient.getrp  c          	        r  )rq  rr  rk  Nr   rn  rA   rA   rB   rs    r  zAsyncClient.optionsc          	        r  )rt  r   rk  Nr   rn  rA   rA   rB   ru    r  zAsyncClient.headc                  ,   | j d|||||||||	|
||dI dH S )rw  r   r7  Nr   rx  rA   rA   rB   ry  .      zAsyncClient.postc                  r  )r{  r|  r7  Nr   rx  rA   rA   rB   r}  S  r  zAsyncClient.putc                  r  )r~  r  r7  Nr   rx  rA   rA   rB   r  x  r  zAsyncClient.patchc          	        r  )r  r  rk  Nr   rn  rA   rA   rB   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   rT   rY   r!  r~   r"  r  )rh   r   rA   rA   rB   r~     s   zAsyncClient.acloserh   r5   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   rT   rW   rX   rY   rL  r!  
__aenter__r"  r  )rh   r  r   rA   rA   rB   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 rb   )rT   rY   r   r!  	__aexit__r"  r  )rh   r  r  r  r   rA   rA   rB   r    s   zAsyncClient.__aexit__)(r   r   r   r   r   r   r   r   r  r  r  r  r  r9   r  r9   r   r   r  r  r   r+   r   r9   r	  r   r   r   r   r   r   r   r
  r  r   r9   r   r   r8   r`   )r  r  r  r  r   r9   r  r9   r  r9   r	  r   r
  r  r8   r   )r   r   r  r  r  r  r   r9   r  r9   r  r9   r	  r   r8   r   )r6   r,   r8   r   r  )r   r   r6   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r8  r   r   r   r   r8   r  r  r  r  r  r  r  r  ry   )rh   r5   r8   r5   r  r  )rK   rL   rM   rN   r   r   r   ri   r   r  r5  r0   r   r   r\   rB  rM  rU  r]  rF   rs  ru  ry  r}  r  r  r~   r  r  r  rA   rA   r%  rB   r1     s    0Q
97
3
"
&&!!!)))

)r6   r,   r7   r,   r8   r9   )r6   r,   r8   rD   )r6   r,   rH   r,   r8   r9   )\
__future__r   rt   enumloggingrr   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.baser   r   _transports.defaultr   r   _typesr   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   _urlsr,   r-   _utilsr.   r/   TYPE_CHECKINGssl__all__TypeVarr3   r5   rC   r@   rI   rJ   r0   	getLoggerrf  r   r   keysr   EnumrT   r[   r{   CallableAny	EventHookr   r2   r1   rA   rA   rA   rB   <module>   sf     <




        N