o
    ¨Ý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,   úU/var/www/html/chatgpt/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)ÚexcZ
mapped_excZfrom_excZto_excÚmessager,   r,   r-   Úmap_httpcore_exceptions\   s&   €
€
€ðr8   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 r?   ©r8   rA   ©rC   r,   r,   r-   Ú__iter__z   s   €"ÿzResponseStream.__iter__c                 C  s   t | jdƒr| j ¡  d S d S )NÚclose)ÚhasattrrA   rJ   rH   r,   r,   r-   rJ   ~   s   ÿzResponseStream.closeN)r;   r<   r)   r=   )r)   rF   ©r)   r=   )Ú__name__Ú
__module__Ú__qualname__rD   rI   rJ   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©rQ   rS   rU   ©
Ússl_contextÚmax_connectionsÚmax_keepalive_connectionsÚkeepalive_expiryrW   rX   r\   r^   r_   ra   ©ÚhttpÚhttps©ÚschemeÚhostÚportÚtarget)Ú	proxy_urlÚ
proxy_authÚproxy_headersrg   Úproxy_ssl_contextrh   ri   rj   rW   rX   ra   ©Zsocks5Zsocks5hú{Using SOCKS proxy, but the 'socksio' package is not installed. Make sure to install httpx using `pip install httpx[socks]`.©rs   rt   rg   rh   ri   rj   rW   rX   úOProxy protocol must be either 'http', 'https', 'socks5', or 'socks5h', but got Ú.)r+   r3   r5   r   r   r	   ÚConnectionPoolrh   ri   rj   Ú_poolrd   ro   Z	HTTPProxyÚ
raw_schemeÚraw_hostrq   Úraw_pathÚraw_authÚheadersÚrawrg   ÚsocksioÚImportErrorZ
SOCKSProxyÚ
ValueError©rC   rQ   rS   rU   rW   rX   rY   rZ   r\   r^   r_   ra   r+   rg   r„   r,   r,   r-   rD   „   s~   öüðÿýÿüóÿzHTTPTransport.__init__rC   r"   c                 C  s   | j  ¡  | S r?   )r}   Ú	__enter__rH   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?   )r8   r}   Ú__exit__©rC   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   rn   )Úmethodrd   r‚   ÚcontentÚ
extensions)Ústatus_coder‚   Ústreamr•   )r3   r—   r   r+   r   r“   r   rd   r~   r   rq   r€   r‚   rƒ   r•   r8   r}   Úhandle_requestÚtypingÚIterabler   Ústatusr:   ©rC   r‘   r+   ÚreqÚrespr,   r,   r-   r˜   á   s0   üöÿüzHTTPTransport.handle_requestc                 C  s   | j  ¡  d S r?   )r}   rJ   rH   r,   r,   r-   rJ      s   zHTTPTransport.close©rQ   rR   rS   rT   rU   rV   rW   rV   rX   rV   rY   r   rZ   r[   r\   r]   r^   r]   r_   r`   ra   rb   r)   r=   )rC   r"   r)   r"   ©NNN©r‰   rŠ   r‹   rŒ   r�   rŽ   r)   r=   ©r‘   r   r)   r   rL   )	rM   rN   rO   r   rD   rˆ   r�   r˜   rJ   r,   r,   r,   r-   r#   ƒ   ó(    ô
Pü
	c                   @  r9   )ÚAsyncResponseStreamr;   útyping.AsyncIterable[bytes]r)   r=   c                 C  r>   r?   r@   rB   r,   r,   r-   rD     rE   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?   rG   )rC   Úpartr,   r,   r-   Ú	__aiter__  s   €ÿ"ÿzAsyncResponseStream.__aiter__c                 Ã  s&   �t | jdƒr| j ¡ I d H  d S d S )NÚaclose)rK   rA   r©   rH   r,   r,   r-   r©     s   €ÿzAsyncResponseStream.acloseN)r;   r¥   r)   r=   )r)   r¦   rL   )rM   rN   rO   rD   r¨   r©   r,   r,   r,   r-   r¤     s    

r¤   c                   @  rP   )5r&   TNFr   rQ   rR   rS   rT   rU   rV   rW   rX   rY   r   rZ   r[   r\   r]   r^   r_   r`   ra   rb   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   rc   re   rf   rk   rn   )rs   rt   ru   rv   rg   rh   ri   rj   rW   rX   ra   rw   rx   ry   rz   r{   )r+   r3   r5   r   r   r	   ZAsyncConnectionPoolrh   ri   rj   r}   rd   ro   ZAsyncHTTPProxyr~   r   rq   r€   r�   r‚   rƒ   rg   r„   r…   ZAsyncSOCKSProxyr†   r‡   r,   r,   r-   rD     s~   öüðÿýÿüóÿzAsyncHTTPTransport.__init__rC   r%   c                 Ã  s   �| j  ¡ I d H  | S r?   )r}   Ú
__aenter__rH   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 r?   )r8   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   rd   r~   r   rq   r€   r‚   rƒ   r•   r8   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 r?   )r}   r©   rH   r,   r,   r-   r©   �  s   €zAsyncHTTPTransport.acloserŸ   )rC   r%   r)   r%   r    r¡   r¢   rL   )	rM   rN   rO   r   rD   rª   r«   r¬   r©   r,   r,   r,   r-   r&     r£   )r)   r'   )r)   r/   )?Ú__doc__Ú
__future__r   Ú
contextlibr™   Úcollections.abcr   Útypesr   ÚTYPE_CHECKINGÚsslZhttpx2Ú_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%   Útupler`   ÚbytesÚ	bytearrayZSOCKET_OPTIONÚ__all__r(   Ú__annotations__r.   Úcontextmanagerr8   r:   r#   r¤   r&   r,   r,   r,   r-   Ú<module>   s8    @0
 