o
    Þ­jS4  ã                   @  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 Z2ddgZ3ej4ddd„ƒZ5e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Z6G dd„ de#ƒZ7G dd„ de)ƒZ8G dd„ de ƒZ9G 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Ú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)ÚexcÚ
mapped_excÚfrom_excÚto_excÚmessage© r5   úV/var/www/html/CropPilot/venv/lib/python3.10/site-packages/httpx/_transports/default.pyÚmap_httpcore_exceptionsE   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 r)   ©Ú_httpcore_stream©Úselfr:   r5   r5   r6   Ú__init__o   ó   
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?   ©rA   Úpartr5   r5   r6   Ú__iter__r   s   €
ÿ"ÿzResponseStream.__iter__c                 C  s   t | jdƒr| j ¡  d S d S )NÚclose)Úhasattrr?   rI   ©rA   r5   r5   r6   rI   w   s   ÿzResponseStream.closeN)r:   r;   r'   r<   )r'   rD   ©r'   r<   )Ú__name__Ú
__module__Ú__qualname__rB   rH   rI   r5   r5   r5   r6   r9   n   ó    

r9   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'   r<   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r™z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©rR   rS   rY   ©Úurl©
Ússl_contextÚmax_connectionsÚmax_keepalive_connectionsÚkeepalive_expiryrU   rW   r\   r^   r_   ra   ©ÚhttpÚhttps©ÚschemeÚhostÚportÚtarget)Ú	proxy_urlÚ
proxy_authÚproxy_headersrg   Úproxy_ssl_contextrh   ri   rj   rU   rW   ra   Úsocks5r   ú{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   rU   rW   zDProxy protocol must be either 'http', 'https', or 'socks5', but got Ú.)r   r-   r/   r   r   ÚhttpcoreÚConnectionPoolrh   ri   rj   Ú_poolre   ro   Ú	HTTPProxyÚ
raw_schemeÚraw_hostrq   Úraw_pathÚraw_authÚheadersÚrawrg   ÚsocksioÚImportErrorÚ
SOCKSProxyÚ
ValueError©rA   rR   rS   rU   rW   rX   rY   rZ   r\   r^   r_   ra   rg   r…   r5   r5   r6   rB   }   s€   öüðÿýÿüóÿÿzHTTPTransport.__init__rA   r"   c                 C  s   | j  ¡  | S r)   )r}   Ú	__enter__rK   r5   r5   r6   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__©rA   r‹   r�   r�   r5   r5   r6   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 ©Nrn   )Úmethodre   rƒ   ÚcontentÚ
extensions)Ústatus_coderƒ   Ústreamr—   )r-   r™   r   r{   r   r•   r   re   r   r€   rq   r�   rƒ   r„   r—   r7   r}   Úhandle_requestÚtypingÚIterabler   Ústatusr9   ©rA   r“   ÚreqÚrespr5   r5   r6   rš   Ù   s.   üöÿüzHTTPTransport.handle_requestc                 C  s   | j  ¡  d S r)   )r}   rI   rK   r5   r5   r6   rI   ÷   s   zHTTPTransport.close©rR   r   rS   rT   rU   rV   rW   rV   rX   r   rY   rV   rZ   r[   r\   r]   r^   r]   r_   r`   ra   rb   r'   r<   )rA   r"   r'   r"   ©NNN©r‹   rŒ   r�   rŽ   r�   r�   r'   r<   ©r“   r   r'   r   rL   )	rM   rN   rO   r   rB   rŠ   r‘   rš   rI   r5   r5   r5   r6   r#   |   ó(    ô
Oü
	c                   @  r8   )ÚAsyncResponseStreamr:   útyping.AsyncIterable[bytes]r'   r<   c                 C  r=   r)   r>   r@   r5   r5   r6   rB   ü   rC   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)   rE   rF   r5   r5   r6   Ú	__aiter__ÿ   s   €ÿ"ÿzAsyncResponseStream.__aiter__c                 Ã  s&   �t | jdƒr| j ¡ I d H  d S d S )NÚaclose)rJ   r?   rª   rK   r5   r5   r6   rª     s   €ÿzAsyncResponseStream.acloseN)r:   r§   r'   r<   )r'   r¨   rL   )rM   rN   rO   rB   r©   rª   r5   r5   r5   r6   r¦   û   rP   r¦   c                   @  rQ   )5r&   TNFr   rR   r   rS   rT   rU   rV   rW   rX   r   rY   rZ   r[   r\   r]   r^   r_   r`   ra   rb   r'   r<   c                 C  s:  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r™z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ƒ‚)Nrc   rd   rf   rk   rn   )rs   rt   ru   rv   rg   rh   ri   rj   rU   rW   ra   rw   r   rx   ry   zYProxy protocol must be either 'http', 'https', or 'socks5', but got {proxy.url.scheme!r}.)r   r-   r/   r   r   r{   ÚAsyncConnectionPoolrh   ri   rj   r}   re   ro   ÚAsyncHTTPProxyr   r€   rq   r�   r‚   rƒ   r„   rg   r…   r†   ÚAsyncSOCKSProxyrˆ   r‰   r5   r5   r6   rB   
  s|   öüðÿýÿüóÿzAsyncHTTPTransport.__init__rA   r%   c                 Ã  s   �| j  ¡ I d H  | S r)   )r}   Ú
__aenter__rK   r5   r5   r6   r®   Y  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’   r5   r5   r6   r¯   ]  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   r{   r   r•   r   re   r   r€   rq   r�   rƒ   r„   r—   r7   r}   Úhandle_async_requestr›   ÚAsyncIterabler   r�   r¦   rž   r5   r5   r6   r°   f  s0   €üöÿüz'AsyncHTTPTransport.handle_async_requestc                 Ã  s   �| j  ¡ I d H  d S r)   )r}   rª   rK   r5   r5   r6   rª   „  s   €zAsyncHTTPTransport.acloser¡   )rA   r%   r'   r%   r¢   r£   r¤   rL   )	rM   rN   rO   r   rB   r®   r¯   r°   rª   r5   r5   r5   r6   r&   	  r¥   )r'   r(   );Ú__doc__Ú
__future__r   Ú
contextlibr›   Útypesr   r{   Ú_configr   r   r   r   Ú_exceptionsr	   r
   r   r   r   r   r   r   r   r   r   r   r   r   Ú_modelsr   r   Ú_typesr   r   r   r   r   Ú_urlsr   Úbaser    r!   ÚTypeVarr"   r%   ÚUnionÚTupler`   ÚbytesÚ	bytearrayÚSOCKET_OPTIONÚ__all__Úcontextmanagerr7   r+   r9   r#   r¦   r&   r5   r5   r5   r6   Ú<module>   sT    @þÿò