o
    h6                     @  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+   m/var/www/html/construction_image-detection-poc/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)exc
mapped_excfrom_excto_excmessager+   r+   r,   map_httpcore_exceptions_   s&   

r:   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 rA   r:   rC   rE   partr+   r+   r,   __iter__}   s   
"zResponseStream.__iter__c                 C  s   t | jdr| j  d S d S )Nclose)hasattrrC   rM   rE   r+   r+   r,   rM      s   zResponseStream.closeN)r=   r>   r(   r?   )r(   rH   r(   r?   )__name__
__module____qualname__rF   rL   rM   r+   r+   r+   r,   r<   y       

r<   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rV   rX   rZ   
ssl_contextmax_connectionsmax_keepalive_connectionskeepalive_expiryr\   r]   ra   rc   rd   rf   httphttpsschemehostporttarget)	proxy_url
proxy_authproxy_headersrl   proxy_ssl_contextrm   rn   ro   r\   r]   rf   socks5socks5h{Using SOCKS proxy, but the 'socksio' package is not installed. Make sure to install httpx using `pip install httpx[socks]`.rx   ry   rl   rm   rn   ro   r\   r]   zOProxy protocol must be either 'http', 'https', 'socks5', or 'socks5h', but got .)r*   r2   r4   r   r   r   ConnectionPoolrm   rn   ro   _poolri   rt   	HTTPProxy
raw_schemeraw_hostrv   raw_pathraw_authheadersrawrl   socksioImportError
SOCKSProxy
ValueErrorrE   rV   rX   rZ   r\   r]   r^   r_   ra   rc   rd   rf   r*   rl   r   r+   r+   r,   rF      s   zHTTPTransport.__init__rE   r!   c                 C  s   | j   | S rA   )r   	__enter__rO   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 rA   )r:   r   __exit__rE   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   rs   )methodri   r   content
extensions)status_coder   streamr   )r2   r   r   r*   r   r   r   ri   r   r   rv   r   r   r   r   r:   r   handle_requesttypingIterabler   statusr<   rE   r   r*   reqrespr+   r+   r,   r      s0   zHTTPTransport.handle_requestc                 C  s   | j   d S rA   )r   rM   rO   r+   r+   r,   rM     s   zHTTPTransport.closerV   rW   rX   rY   rZ   r[   r\   r[   r]   r[   r^   r   r_   r`   ra   rb   rc   rb   rd   re   rf   rg   r(   r?   )rE   r!   r(   r!   NNNr   r   r   r   r   r   r(   r?   r   r   r(   r   rP   )	rQ   rR   rS   r   rF   r   r   r   rM   r+   r+   r+   r,   r"      (    
Q
	c                   @  r;   )AsyncResponseStreamr=   typing.AsyncIterable[bytes]r(   r?   c                 C  r@   rA   rB   rD   r+   r+   r,   rF   
  rG   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 rA   rI   rJ   r+   r+   r,   	__aiter__  s   "zAsyncResponseStream.__aiter__c                   s&   t | jdr| j I d H  d S d S )Naclose)rN   rC   r   rO   r+   r+   r,   r     s   zAsyncResponseStream.acloseN)r=   r   r(   r?   )r(   r   rP   )rQ   rR   rS   rF   r   r   r+   r+   r+   r,   r   	  rT   r   c                   @  rU   )5r%   TNFr   rV   rW   rX   rY   rZ   r[   r\   r]   r^   r   r_   r`   ra   rb   rc   rd   re   rf   rg   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   rh   rj   rk   rp   rs   )rx   ry   rz   r{   rl   rm   rn   ro   r\   r]   rf   r|   r   r   zdProxy protocol must be either 'http', 'https', 'socks5', or 'socks5h', but got {proxy.url.scheme!r}.)r*   r2   r4   r   r   r   AsyncConnectionPoolrm   rn   ro   r   ri   rt   AsyncHTTPProxyr   r   rv   r   r   r   r   rl   r   r   AsyncSOCKSProxyr   r   r+   r+   r,   rF     s~   zAsyncHTTPTransport.__init__rE   r$   c                   s   | j  I d H  | S rA   )r   
__aenter__rO   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 rA   )r:   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   ri   r   r   rv   r   r   r   r   r:   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 rA   )r   r   rO   r+   r+   r,   r     s   zAsyncHTTPTransport.acloser   )rE   r$   r(   r$   r   r   r   rP   )	rQ   rR   rS   r   rF   r   r   r   r   r+   r+   r+   r,   r%     r   )r(   r&   )r(   r.   )>__doc__
__future__r   
contextlibr   typesr   TYPE_CHECKINGsslhttpx_configr   r   r   r   _exceptionsr	   r
   r   r   r   r   r   r   r   r   r   r   r   r   _modelsr   r   _typesr   r   r   r   _urlsr   baser   r    TypeVarr!   r$   UnionTuplere   bytes	bytearraySOCKET_OPTION__all__r'   __annotations__r-   contextmanagerr:   r<   r"   r   r%   r+   r+   r+   r,   <module>   s@    @
 