o
    CZcm1                     @   s  d Z ddlZddlZddlmZ ddlZddlmZmZm	Z	m
Z
 ddlmZmZmZmZmZmZmZmZmZmZmZmZmZmZ ddlmZmZ ddlmZmZm Z m!Z! d	d
l"m#Z#m$Z$ ej%dddZ&ej%dddZ'ej(dej)d fddZ*ejeejeejeejeejeejeejeejeejeejeejeejeejeejeiZ+G dd de Z,G dd de$Z-G dd deZ.G dd de#Z/dS )a  
Custom transports, with nicely configured defaults.

The following additional keyword arguments are currently supported by httpcore...

* uds: str
* local_address: str
* retries: int

Example usages...

# Disable HTTP/2 on a single specific domain.
mounts = {
    "all://": httpx.HTTPTransport(http2=True),
    "all://*example.org": httpx.HTTPTransport()
}

# Using advanced httpcore configuration, with connection retries.
transport = httpx.HTTPTransport(retries=1)
client = httpx.Client(transport=transport)

# Using advanced httpcore configuration, with unix domain sockets.
transport = httpx.HTTPTransport(uds="socket.uds")
client = httpx.Client(transport=transport)
    N)TracebackType   )DEFAULT_LIMITSLimitsProxycreate_ssl_context)ConnectErrorConnectTimeoutLocalProtocolErrorNetworkErrorPoolTimeoutProtocolError
ProxyError	ReadErrorReadTimeoutRemoteProtocolErrorTimeoutExceptionUnsupportedProtocol
WriteErrorWriteTimeout)RequestResponse)AsyncByteStream	CertTypesSyncByteStreamVerifyTypes   )AsyncBaseTransportBaseTransportTHTTPTransport)boundAAsyncHTTPTransportreturnc               
   c   s|    zd V  W d S  t y= }  z*d }t D ]\}}t| |sq|d u s(t||r*|}q|d u r0 t| }||| d } ~ ww N)	ExceptionHTTPCORE_EXC_MAPitems
isinstance
issubclassstr)exc
mapped_excfrom_excto_excmessage r1   O/var/www/chikooza/env/lib/python3.10/site-packages/httpx/_transports/default.pymap_httpcore_exceptions9   s"   

r3   c                   @   >   e Zd Zdeje fddZdeje fddZd
dd	Z	dS )ResponseStreamhttpcore_streamc                 C   
   || _ d S r%   _httpcore_streamselfr6   r1   r1   r2   __init__c      
zResponseStream.__init__r$   c                 c   s@    t   | jD ]}|V  qW d    d S 1 sw   Y  d S r%   r3   r9   r;   partr1   r1   r2   __iter__f   s   
"zResponseStream.__iter__Nc                 C   s   t | jdr| j  d S d S )Nclose)hasattrr9   rB   r;   r1   r1   r2   rB   k   s   zResponseStream.closer$   N)
__name__
__module____qualname__typingIterablebytesr<   IteratorrA   rB   r1   r1   r1   r2   r5   b       r5   c                   @      e Zd Zddddedddddf
dedeje deded	e	d
edeje
 deje deje deddfddZdedefddZ			ddejeje  deje deje ddfddZdedefddZd ddZdS )!r    TNFr   verifycerthttp1http2limits	trust_envproxyudslocal_addressretriesr$   c                 C   "  t |||d}|d u rtj||j|j|j||||	|
d	| _d S |jjdv rKtj	tj
|jj|jj|jj|jjd|j|jj||j|j|j||d	| _d S |jjdkrzdd l}W n tyc   tdd w tjtj
|jj|jj|jj|jjd|j||j|j|j||d	| _d S td
|jjdN)rO   rP   rT   )	ssl_contextmax_connectionsmax_keepalive_connectionskeepalive_expiryrQ   rR   rV   rW   rX   )httphttpsschemehostporttarget)		proxy_url
proxy_authproxy_headersr[   r\   r]   r^   rQ   rR   socks5r   z{Using SOCKS proxy, but the 'socksio' package is not installed. Make sure to install httpx using `pip install httpx[socks]`.)rf   rg   r[   r\   r]   r^   rQ   rR   zDProxy protocol must be either 'http', 'https', or 'socks5', but got .)r   httpcoreConnectionPoolr\   r]   r^   _poolurlrb   	HTTPProxyURL
raw_schemeraw_hostrd   raw_pathraw_authheadersrawsocksioImportError
SOCKSProxy
ValueErrorr;   rO   rP   rQ   rR   rS   rT   rU   rV   rW   rX   r[   rw   r1   r1   r2   r<   q   t   zHTTPTransport.__init__r;   c                 C   s   | j   | S r%   )rm   	__enter__rD   r1   r1   r2   r}      s   
zHTTPTransport.__enter__exc_type	exc_value	tracebackc                 C   s<   t   | j||| W d    d S 1 sw   Y  d S r%   )r3   rm   __exit__r;   r~   r   r   r1   r1   r2   r      s   "zHTTPTransport.__exit__requestc                 C   s   t |jtsJ tj|jtj|jj|jj	|jj
|jjd|jj|j|jd}t  | j|}W d    n1 s:w   Y  t |jtjsHJ t|j|jt|j|jdS Nra   )methodrn   ru   content
extensions)status_coderu   streamr   )r)   r   r   rk   r   r   rp   rn   rq   rr   rd   rs   ru   rv   r   r3   rm   handle_requestrI   rJ   r   statusr5   r;   r   reqrespr1   r1   r2   r      s.   zHTTPTransport.handle_requestc                 C   s   | j   d S r%   )rm   rB   rD   r1   r1   r2   rB      s   zHTTPTransport.closeNNNrE   )rF   rG   rH   r   r   rI   Optionalr   boolr   r   r+   intr<   r   r}   TypeBaseExceptionr   r   r   r   r   rB   r1   r1   r1   r2   r    p   j    	

I
	
c                   @   r4   )AsyncResponseStreamr6   c                 C   r7   r%   r8   r:   r1   r1   r2   r<      r=   zAsyncResponseStream.__init__r$   c                 C  sJ   t   | j2 z	3 d H W }|V  q6 W d    d S 1 sw   Y  d S r%   r>   r?   r1   r1   r2   	__aiter__   s   "zAsyncResponseStream.__aiter__Nc                    s&   t | jdr| j I d H  d S d S )Naclose)rC   r9   r   rD   r1   r1   r2   r      s   zAsyncResponseStream.acloserE   )
rF   rG   rH   rI   AsyncIterablerK   r<   AsyncIteratorr   r   r1   r1   r1   r2   r      rM   r   c                   @   rN   )!r#   TNFr   rO   rP   rQ   rR   rS   rT   rU   rV   rW   rX   r$   c                 C   rY   rZ   )r   rk   AsyncConnectionPoolr\   r]   r^   rm   rn   rb   AsyncHTTPProxyrp   rq   rr   rd   rs   rt   ru   rv   rw   rx   AsyncSOCKSProxyrz   r{   r1   r1   r2   r<      r|   zAsyncHTTPTransport.__init__r;   c                    s   | j  I d H  | S r%   )rm   
__aenter__rD   r1   r1   r2   r   A  s   zAsyncHTTPTransport.__aenter__r~   r   r   c                    sD   t   | j|||I d H  W d    d S 1 sw   Y  d S r%   )r3   rm   	__aexit__r   r1   r1   r2   r   E  s   "zAsyncHTTPTransport.__aexit__r   c                    s   t |jts	J tj|jtj|jj|jj	|jj
|jjd|jj|j|jd}t  | j|I d H }W d    n1 s>w   Y  t |jtjsLJ t|j|jt|j|jdS r   )r)   r   r   rk   r   r   rp   rn   rq   rr   rd   rs   ru   rv   r   r3   rm   handle_async_requestrI   r   r   r   r   r   r1   r1   r2   r   N  s0   z'AsyncHTTPTransport.handle_async_requestc                    s   | j  I d H  d S r%   )rm   r   rD   r1   r1   r2   r   l  s   zAsyncHTTPTransport.acloser   rE   )rF   rG   rH   r   r   rI   r   r   r   r   r   r+   r   r<   r"   r   r   r   r   r   r   r   r   r   r1   r1   r1   r2   r#      r   )0__doc__
contextlibrI   typesr   rk   _configr   r   r   r   _exceptionsr   r	   r
   r   r   r   r   r   r   r   r   r   r   r   _modelsr   r   _typesr   r   r   r   baser   r   TypeVarr   r"   contextmanagerrL   r3   r'   r5   r    r   r#   r1   r1   r1   r2   <module>   sB    @y