o
    Zh3                     @  s  d Z ddlm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#m$Z$ dd
l%m&Z& ddl'm(Z(m)Z) ej*dddZ+ej*dddZ,ej-ej.e/e/e/f ej.e/e/ej-e0e1f f ej.e/e/de/f f Z2ej3dddZ4e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Z5G dd de#Z6G dd de)Z7G dd de Z8G dd de(Z9d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)
    )annotationsN)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
ProxyTypesSyncByteStreamVerifyTypes)URL   )AsyncBaseTransportBaseTransportTHTTPTransport)boundAAsyncHTTPTransportreturntyping.Iterator[None]c               
   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)excZ
mapped_excZfrom_excZto_excmessage r2   P/var/www/html/lang_env/lib/python3.10/site-packages/httpx/_transports/default.pymap_httpcore_exceptionsB   s"   

r4   c                   @  *   e Zd ZdddZddd	Zdd
dZdS )ResponseStreamhttpcore_streamtyping.Iterable[bytes]r'   Nonec                 C  
   || _ d S r)   _httpcore_streamselfr7   r2   r2   r3   __init__l      
zResponseStream.__init__typing.Iterator[bytes]c                 c  s@    t   | jD ]}|V  qW d    d S 1 sw   Y  d S r)   r4   r<   r>   partr2   r2   r3   __iter__o   s   
"zResponseStream.__iter__c                 C  s   t | jdr| j  d S d S )Nclose)hasattrr<   rF   r>   r2   r2   r3   rF   t   s   zResponseStream.closeN)r7   r8   r'   r9   )r'   rA   r'   r9   )__name__
__module____qualname__r?   rE   rF   r2   r2   r2   r3   r6   k       

r6   c                   @  ^   e Zd Zddddeddddddfd/ddZd0ddZ			d1d2d&d'Zd3d+d,Zd4d-d.ZdS )5r#   TNFr   verifyr   certCertTypes | Nonehttp1boolhttp2limitsr   	trust_envproxyProxyTypes | Noneuds
str | Nonelocal_addressretriesintsocket_options%typing.Iterable[SOCKET_OPTION] | Noner'   r9   c                 C  sF  t |||d}t|ttfrt|dn|}|d u r.tj||j|j|j	||||	|
|d
| _
d S |jjdv r]tjtj|jj|jj|jj|jjd|j|jj||j|j|j|j	|||d| _
d S |jjdkrzdd l}W n tyu   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   rV   url
ssl_contextmax_connectionsmax_keepalive_connectionskeepalive_expiryrR   rT   rY   r[   r\   r^   httphttpsschemehostporttarget)	proxy_url
proxy_authproxy_headersrd   proxy_ssl_contextre   rf   rg   rR   rT   r^   socks5r   {Using SOCKS proxy, but the 'socksio' package is not installed. Make sure to install httpx using `pip install httpx[socks]`.rp   rq   rd   re   rf   rg   rR   rT   zDProxy protocol must be either 'http', 'https', or 'socks5', but got .)r   r-   r/   r   r   httpcoreConnectionPoolre   rf   rg   _poolrb   rl   Z	HTTPProxy
raw_schemeraw_hostrn   raw_pathraw_authheadersrawrd   socksioImportErrorZ
SOCKSProxy
ValueErrorr>   rO   rP   rR   rT   rU   rV   rW   rY   r[   r\   r^   rd   r   r2   r2   r3   r?   z   s   zHTTPTransport.__init__r>   r"   c                 C  s   | j   | S r)   )rz   	__enter__rH   r2   r2   r3   r      s   
zHTTPTransport.__enter__exc_typetype[BaseException] | None	exc_valueBaseException | None	tracebackTracebackType | Nonec                 C  s<   t   | j||| W d    d S 1 sw   Y  d S r)   )r4   rz   __exit__r>   r   r   r   r2   r2   r3   r      s   "zHTTPTransport.__exit__requestr   r   c                 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 Nrk   )methodrb   r   content
extensions)status_coder   streamr   )r-   r   r   rx   r   r   r   rb   r{   r|   rn   r}   r   r   r   r4   rz   handle_requesttypingIterabler   statusr6   r>   r   reqrespr2   r2   r3   r      s.   zHTTPTransport.handle_requestc                 C  s   | j   d S r)   )rz   rF   rH   r2   r2   r3   rF      s   zHTTPTransport.closerO   r   rP   rQ   rR   rS   rT   rS   rU   r   rV   rS   rW   rX   rY   rZ   r[   rZ   r\   r]   r^   r_   r'   r9   )r>   r"   r'   r"   NNNr   r   r   r   r   r   r'   r9   r   r   r'   r   rI   )	rJ   rK   rL   r   r?   r   r   r   rF   r2   r2   r2   r3   r#   y   s(    
O
	c                   @  r5   )AsyncResponseStreamr7   typing.AsyncIterable[bytes]r'   r9   c                 C  r:   r)   r;   r=   r2   r2   r3   r?      r@   zAsyncResponseStream.__init__typing.AsyncIterator[bytes]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)   rB   rC   r2   r2   r3   	__aiter__   s   "zAsyncResponseStream.__aiter__c                   s&   t | jdr| j I d H  d S d S )Naclose)rG   r<   r   rH   r2   r2   r3   r     s   zAsyncResponseStream.acloseN)r7   r   r'   r9   )r'   r   rI   )rJ   rK   rL   r?   r   r   r2   r2   r2   r3   r      rM   r   c                   @  rN   )5r&   TNFr   rO   r   rP   rQ   rR   rS   rT   rU   r   rV   rW   rX   rY   rZ   r[   r\   r]   r^   r_   r'   r9   c                 C  s6  t |||d}t|ttfrt|dn|}|d u r.tj||j|j|j	||||	|
|d
| _
d S |jjdv r[t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ys   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)Nr`   ra   rc   rh   rk   )
rp   rq   rr   rd   re   rf   rg   rR   rT   r^   rt   r   ru   rv   zYProxy protocol must be either 'http', 'https', or 'socks5', but got {proxy.url.scheme!r}.)r   r-   r/   r   r   rx   ZAsyncConnectionPoolre   rf   rg   rz   rb   rl   ZAsyncHTTPProxyr{   r|   rn   r}   r~   r   r   r   r   ZAsyncSOCKSProxyr   r   r2   r2   r3   r?     sz   zAsyncHTTPTransport.__init__r>   r%   c                   s   | j  I d H  | S r)   )rz   
__aenter__rH   r2   r2   r3   r   U  s   zAsyncHTTPTransport.__aenter__r   r   r   r   r   r   c                   sD   t   | j|||I d H  W d    d S 1 sw   Y  d S r)   )r4   rz   	__aexit__r   r2   r2   r3   r   Y  s   "zAsyncHTTPTransport.__aexit__r   r   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   rx   r   r   r   rb   r{   r|   rn   r}   r   r   r   r4   rz   handle_async_requestr   AsyncIterabler   r   r   r   r2   r2   r3   r   b  s0   z'AsyncHTTPTransport.handle_async_requestc                   s   | j  I d H  d S r)   )rz   r   rH   r2   r2   r3   r     s   zAsyncHTTPTransport.acloser   )r>   r%   r'   r%   r   r   r   rI   )	rJ   rK   rL   r   r?   r   r   r   r   r2   r2   r2   r3   r&     s(    
N
	)r'   r(   ):__doc__
__future__r   
contextlibr   typesr   rx   _configr   r   r   r   _exceptionsr	   r
   r   r   r   r   r   r   r   r   r   r   r   r   Z_modelsr   r   _typesr   r   r   r   r   Z_urlsr   baser    r!   TypeVarr"   r%   UnionTupler]   bytes	bytearrayZSOCKET_OPTIONcontextmanagerr4   r+   r6   r#   r   r&   r2   r2   r2   r3   <module>   sR    @