o
    i6                     @  s  U d Z ddlmZ ddlZddlZddlmZ ejr"ddl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' ddl(m)Z)m*Z* ej+dddZ,ej+dddZ-ej.ej/e0e0e0f ej/e0e0ej.e1e2f f ej/e0e0de0f f Z3ddgZ4i a5de6d< d ddZ7ej8d!ddZ9G 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)
    )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)URL   )AsyncBaseTransportBaseTransportTHTTPTransport)boundAAsyncHTTPTransport,dict[type[Exception], type[httpx.HTTPError]]HTTPCORE_EXC_MAPreturnc                  C  s`   dd l } | jt| jt| jt| jt| jt| jt| jt| jt| j	t	| j
t
| jt| jt| jt| jtiS Nr   )httpcorer   r
   r   r   r   r   r	   r   r   r   r   r   r   r   )r*    r+   S/home/kim/smarthome/.venv/lib/python3.10/site-packages/httpx/_transports/default.py_load_httpcore_exceptionsJ   s    r-   typing.Iterator[None]c               
   c  s    t tdkr
t azd V  W d S  tyF }  z*d }t D ]\}}t| |s(q|d u s1t||r3|}q|d u r9 t| }||| d } ~ ww r)   )lenr'   r-   	Exceptionitems
isinstance
issubclassstr)excZ
mapped_excZfrom_excZto_excmessager+   r+   r,   map_httpcore_exceptions_   s&   

r7   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 N_httpcore_streamselfr:   r+   r+   r,   __init__z      
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>   r7   r@   rB   partr+   r+   r,   __iter__}   s   
"zResponseStream.__iter__c                 C  s   t | jdr| j  d S d S )Nclose)hasattrr@   rJ   rB   r+   r+   r,   rJ      s   zResponseStream.closeN)r:   r;   r(   r<   )r(   rE   r(   r<   )__name__
__module____qualname__rC   rI   rJ   r+   r+   r+   r,   r9   y       

r9   c                   @  ^   e Zd Zddddde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   verifyssl.SSLContext | str | boolcertCertTypes | None	trust_envboolhttp1http2limitsr   proxyProxyTypes | Noneuds
str | Nonelocal_addressretriesintsocket_options%typing.Iterable[SOCKET_OPTION] | Noner(   r<   c                 C  sN  dd l }t|ttfrt|dn|}t|||d}|d u r2|j||j|j|j	||||	|
|d
| _
d S |jjdv ra|j|j|jj|jj|jj|jjd|j|jj||j|j|j|j	|||d| _
d S |jjdv rzdd l}W n tyy   td	d w |j|j|jj|jj|jj|jjd|j||j|j|j	||d
| _
d S td|jjd)Nr   urlrS   rU   rW   
ssl_contextmax_connectionsmax_keepalive_connectionskeepalive_expiryrY   rZ   r^   r`   ra   rc   httphttpsschemehostporttarget)	proxy_url
proxy_authproxy_headersri   proxy_ssl_contextrj   rk   rl   rY   rZ   rc   Zsocks5Zsocks5h{Using SOCKS proxy, but the 'socksio' package is not installed. Make sure to install httpx using `pip install httpx[socks]`.ru   rv   ri   rj   rk   rl   rY   rZ   zOProxy protocol must be either 'http', 'https', 'socks5', or 'socks5h', but got .)r*   r2   r4   r   r   r   ConnectionPoolrj   rk   rl   _poolrf   rq   Z	HTTPProxy
raw_schemeraw_hostrs   raw_pathraw_authheadersrawri   socksioImportErrorZ
SOCKSProxy
ValueErrorrB   rS   rU   rW   rY   rZ   r[   r\   r^   r`   ra   rc   r*   ri   r   r+   r+   r,   rC      s   zHTTPTransport.__init__rB   r!   c                 C  s   | j   | S r>   )r~   	__enter__rL   r+   r+   r,   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>   )r7   r~   __exit__rB   r   r   r   r+   r+   r,   r      s   "zHTTPTransport.__exit__requestr   r   c                 C  s   t |jtsJ dd l}|j|j|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sLJ t|j|jt|j|jdS Nr   rp   )methodrf   r   content
extensions)status_coder   streamr   )r2   r   r   r*   r   r   r   rf   r   r   rs   r   r   r   r   r7   r~   handle_requesttypingIterabler   statusr9   rB   r   r*   reqrespr+   r+   r,   r      s0   zHTTPTransport.handle_requestc                 C  s   | j   d S r>   )r~   rJ   rL   r+   r+   r,   rJ     s   zHTTPTransport.closerS   rT   rU   rV   rW   rX   rY   rX   rZ   rX   r[   r   r\   r]   r^   r_   r`   r_   ra   rb   rc   rd   r(   r<   )rB   r!   r(   r!   NNNr   r   r   r   r   r   r(   r<   r   r   r(   r   rM   )	rN   rO   rP   r   rC   r   r   r   rJ   r+   r+   r+   r,   r"      (    
Q
	c                   @  r8   )AsyncResponseStreamr:   typing.AsyncIterable[bytes]r(   r<   c                 C  r=   r>   r?   rA   r+   r+   r,   rC   
  rD   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>   rF   rG   r+   r+   r,   	__aiter__  s   "zAsyncResponseStream.__aiter__c                   s&   t | jdr| j I d H  d S d S )Naclose)rK   r@   r   rL   r+   r+   r,   r     s   zAsyncResponseStream.acloseN)r:   r   r(   r<   )r(   r   rM   )rN   rO   rP   rC   r   r   r+   r+   r+   r,   r   	  rQ   r   c                   @  rR   )5r%   TNFr   rS   rT   rU   rV   rW   rX   rY   rZ   r[   r   r\   r]   r^   r_   r`   ra   rb   rc   rd   r(   r<   c                 C  sB  dd l }t|ttfrt|dn|}t|||d}|d u r2|j||j|j|j	||||	|
|d
| _
d S |jjdv ra|j|j|jj|jj|jj|jjd|j|jj|j||j|j|j	|||d| _
d S |jjdv rzdd l}W n tyy   td	d w |j|j|jj|jj|jj|jjd|j||j|j|j	||d
| _
d S td)Nr   re   rg   rh   rm   rp   )ru   rv   rw   rx   ri   rj   rk   rl   rY   rZ   rc   ry   rz   r{   zdProxy protocol must be either 'http', 'https', 'socks5', or 'socks5h', but got {proxy.url.scheme!r}.)r*   r2   r4   r   r   r   ZAsyncConnectionPoolrj   rk   rl   r~   rf   rq   ZAsyncHTTPProxyr   r   rs   r   r   r   r   ri   r   r   ZAsyncSOCKSProxyr   r   r+   r+   r,   rC     s~   zAsyncHTTPTransport.__init__rB   r$   c                   s   | j  I d H  | S r>   )r~   
__aenter__rL   r+   r+   r,   r   i  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>   )r7   r~   	__aexit__r   r+   r+   r,   r   m  s   "zAsyncHTTPTransport.__aexit__r   r   r   c                   s   t |jts	J dd l}|j|j|j|jj|jj	|jj
|jjd|jj|j|jd}t  | j|I d H }W d    n1 sBw   Y  t |jtjsPJ t|j|jt|j|jdS r   )r2   r   r   r*   r   r   r   rf   r   r   rs   r   r   r   r   r7   r~   handle_async_requestr   AsyncIterabler   r   r   r   r+   r+   r,   r   v  s2   z'AsyncHTTPTransport.handle_async_requestc                   s   | j  I d H  d S r>   )r~   r   rL   r+   r+   r,   r     s   zAsyncHTTPTransport.acloser   )rB   r$   r(   r$   r   r   r   rM   )	rN   rO   rP   r   rC   r   r   r   r   r+   r+   r+   r,   r%     r   )r(   r&   )r(   r.   )>__doc__
__future__r   
contextlibr   typesr   TYPE_CHECKINGsslZhttpx_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   Z_urlsr   baser   r    TypeVarr!   r$   UnionTuplerb   bytes	bytearrayZSOCKET_OPTION__all__r'   __annotations__r-   contextmanagerr7   r9   r"   r   r%   r+   r+   r+   r,   <module>   s@    @
 