o
    ùT·jY6  ã                   @  sª  U d Z ddlmZ ddlZddlZddlm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/e0e1e1e1f e0e1e1e2e3B f B e0e1e1de1f B Z4ddgZ5i a6de7d< d!dd„Z8ej9d"dd„ƒ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://": httpx2.HTTPTransport(http2=True),
    "all://*example.org": httpx2.HTTPTransport()
}

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

# Using advanced httpcore configuration, with unix domain sockets.
transport = httpx2.HTTPTransport(uds="socket.uds")
client = httpx2.Client(transport=transport)
é    )ÚannotationsN)Ú	Generator)Ú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[httpx2.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   )Ú	httpcore2r   r   r   r   r   r   r
   r   r   r   r   r   r   r   )r+   © r,   ú]/home/dinkstrade/pdmp-scanner/venv/lib/python3.10/site-packages/httpx2/_transports/default.pyÚ_load_httpcore_exceptionsG   s    òr.   úGenerator[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__w   ó   
zResponseStream.__init__útyping.Iterator[bytes]c                 c  s:   � t ƒ � | jE d H  W d   ƒ d S 1 sw   Y  d S rB   ©r;   rD   ©rF   r,   r,   r-   Ú__iter__z   s   €"ÿzResponseStream.__iter__c                 C  s   t | jdƒr| j ¡  d S d S )NÚclose)ÚhasattrrD   rM   rK   r,   r,   r-   rM   ~   s   ÿzResponseStream.closeN)r>   r?   r)   r@   )r)   rI   ©r)   r@   )Ú__name__Ú
__module__Ú__qualname__rG   rL   rM   r,   r,   r,   r-   r=   v   s    

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 r�z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©rT   rV   rX   ©
Ússl_contextÚmax_connectionsÚmax_keepalive_connectionsÚkeepalive_expiryrZ   r[   r_   ra   rb   rd   ©ÚhttpÚhttps©ÚschemeÚhostÚportÚtarget)Ú	proxy_urlÚ
proxy_authÚproxy_headersrj   Úproxy_ssl_contextrk   rl   rm   rZ   r[   rd   ©Úsocks5Úsocks5hú{Using SOCKS proxy, but the 'socksio' package is not installed. Make sure to install httpx using `pip install httpx[socks]`.©rv   rw   rj   rk   rl   rm   rZ   r[   úOProxy protocol must be either 'http', 'https', 'socks5', or 'socks5h', but got Ú.)r+   r3   r5   r   r   r	   ÚConnectionPoolrk   rl   rm   Ú_poolrg   rr   Ú	HTTPProxyÚ
raw_schemeÚraw_hostrt   Úraw_pathÚraw_authÚheadersÚrawrj   ÚsocksioÚImportErrorÚ
SOCKSProxyÚ
ValueError©rF   rT   rV   rX   rZ   r[   r\   r]   r_   ra   rb   rd   r+   rj   rŠ   r,   r,   r-   rG   „   s~   öüðÿýÿüóÿzHTTPTransport.__init__rF   r"   c                 C  s   | j  ¡  | S rB   )r‚   Ú	__enter__rK   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 rB   )r;   r‚   Ú__exit__©rF   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   rq   )Úmethodrg   rˆ   ÚcontentÚ
extensions)Ústatus_coderˆ   Ústreamrœ   )r3   rž   r   r+   r   rš   r   rg   r„   r…   rt   r†   rˆ   r‰   rœ   r;   r‚   Úhandle_requestÚtypingÚIterabler   Ústatusr=   ©rF   r˜   r+   ÚreqÚrespr,   r,   r-   rŸ   á   s0   üöÿüzHTTPTransport.handle_requestc                 C  s   | j  ¡  d S rB   )r‚   rM   rK   r,   r,   r-   rM      s   zHTTPTransport.close©rT   rU   rV   rW   rX   rY   rZ   rY   r[   rY   r\   r   r]   r^   r_   r`   ra   r`   rb   rc   rd   re   r)   r@   )rF   r"   r)   r"   ©NNN©r�   r‘   r’   r“   r”   r•   r)   r@   ©r˜   r   r)   r   rO   )	rP   rQ   rR   r   rG   r�   r–   rŸ   rM   r,   r,   r,   r-   r#   ƒ   ó(    ô
Pü
	c                   @  r<   )ÚAsyncResponseStreamr>   útyping.AsyncIterable[bytes]r)   r@   c                 C  rA   rB   rC   rE   r,   r,   r-   rG     rH   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 rB   rJ   )rF   Úpartr,   r,   r-   Ú	__aiter__  s   €ÿ"ÿzAsyncResponseStream.__aiter__c                 Ã  s&   �t | jdƒr| j ¡ I d H  d S d S )NÚaclose)rN   rD   r°   rK   r,   r,   r-   r°     s   €ÿzAsyncResponseStream.acloseN)r>   r¬   r)   r@   )r)   r­   rO   )rP   rQ   rR   rG   r¯   r°   r,   r,   r,   r-   r«     s    

r«   c                   @  rS   )5r&   TNFr   rT   rU   rV   rW   rX   rY   rZ   r[   r\   r   r]   r^   r_   r`   ra   rb   rc   rd   re   r)   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 r�z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   rf   rh   ri   rn   rq   )rv   rw   rx   ry   rj   rk   rl   rm   rZ   r[   rd   rz   r}   r~   r   r€   )r+   r3   r5   r   r   r	   ÚAsyncConnectionPoolrk   rl   rm   r‚   rg   rr   ÚAsyncHTTPProxyr„   r…   rt   r†   r‡   rˆ   r‰   rj   rŠ   r‹   ÚAsyncSOCKSProxyr�   rŽ   r,   r,   r-   rG     s~   öüðÿýÿüóÿzAsyncHTTPTransport.__init__rF   r%   c                 Ã  s   �| j  ¡ I d H  | S rB   )r‚   Ú
__aenter__rK   r,   r,   r-   r´   c  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 rB   )r;   r‚   Ú	__aexit__r—   r,   r,   r-   rµ   g  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™   )r3   rž   r   r+   r   rš   r   rg   r„   r…   rt   r†   rˆ   r‰   rœ   r;   r‚   Úhandle_async_requestr    ÚAsyncIterabler   r¢   r«   r£   r,   r,   r-   r¶   p  s2   €üöÿüz'AsyncHTTPTransport.handle_async_requestc                 Ã  s   �| j  ¡ I d H  d S rB   )r‚   r°   rK   r,   r,   r-   r°   �  s   €zAsyncHTTPTransport.acloser¦   )rF   r%   r)   r%   r§   r¨   r©   rO   )	rP   rQ   rR   r   rG   r´   rµ   r¶   r°   r,   r,   r,   r-   r&     rª   )r)   r'   )r)   r/   )?Ú__doc__Ú
__future__r   Ú
contextlibr    Úcollections.abcr   Útypesr   ÚTYPE_CHECKINGÚsslÚhttpx2Ú_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%   Útuplerc   ÚbytesÚ	bytearrayÚSOCKET_OPTIONÚ__all__r(   Ú__annotations__r.   Úcontextmanagerr;   r=   r#   r«   r&   r,   r,   r,   r-   Ú<module>   s8    @0
 