o
    Ù­jÚ$  ã                	   @  s  d dl mZ d dlZd dlZddlmZmZmZ zd dlZW n e	e
fy+   dZY nw zd dlZW n e	y=   dZY nw ddd„ZG d	d
„ d
ƒZG dd„ dƒZG dd„ dƒZG dd„ dƒZG dd„ dƒZG dd„ dƒZG dd„ dƒZG dd„ dƒZG dd„ dƒZG dd„ dƒZdS )é    )ÚannotationsNé   )ÚExceptionMappingÚPoolTimeoutÚmap_exceptionsÚreturnÚstrc                  C  sp   zdd l } W n ty   d}Y nw |  ¡ }|dvrtdƒ‚|dkr*td u r*tdƒ‚|dkr6td u r6tdƒ‚|S )Nr   Úasyncio)r	   Útrioz/Running under an unsupported async environment.zBRunning with asyncio requires installation of 'httpcore[asyncio]'.r
   z<Running with trio requires installation of 'httpcore[trio]'.)ÚsniffioÚImportErrorÚcurrent_async_libraryÚRuntimeErrorÚanyior
   )r   Úenvironment© r   úV/var/www/html/CropPilot/venv/lib/python3.10/site-packages/httpcore/_synchronization.pyr      s"   ÿÿÿr   c                   @  s@   e Zd ZdZddd„Zddd„Zddd	„Z	
	
	
dddd„Zd
S )Ú	AsyncLockú’
    This is a standard lock.

    In the sync case `Lock` provides thread locking.
    In the async case `AsyncLock` provides async locking.
    r   ÚNonec                 C  ó
   d| _ d S ©NÚ ©Ú_backend©Úselfr   r   r   Ú__init__8   ó   
zAsyncLock.__init__c                 C  ó<   t ƒ | _| jdkrt ¡ | _dS | jdkrt ¡ | _dS dS ©z~
        Detect if we're running under 'asyncio' or 'trio' and create
        a lock with the correct implementation.
        r
   r	   N)r   r   r
   ÚLockÚ
_trio_lockr   Ú_anyio_lockr   r   r   r   Úsetup;   ó   

ÿzAsyncLock.setupc                 Ã  sL   �| j s|  ¡  | j dkr| j ¡ I d H  | S | j dkr$| j ¡ I d H  | S ©Nr
   r	   )r   r$   r"   Úacquirer#   r   r   r   r   Ú
__aenter__F   s   €

ýzAsyncLock.__aenter__NÚexc_typeútype[BaseException] | NoneÚ	exc_valueúBaseException | NoneÚ	tracebackútypes.TracebackType | Nonec                 Ã  ó6   �| j dkr| j ¡  d S | j dkr| j ¡  d S d S r&   )r   r"   Úreleaser#   ©r   r)   r+   r-   r   r   r   Ú	__aexit__Q   s   €

ÿzAsyncLock.__aexit__©r   r   )r   r   ©NNN©r)   r*   r+   r,   r-   r.   r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r$   r(   r2   r   r   r   r   r   0   s    


ür   c                   @  s,   e Zd ZdZddd„Z			dddd„ZdS )ÚAsyncThreadLockú¬
    This is a threading-only lock for no-I/O contexts.

    In the sync case `ThreadLock` provides thread locking.
    In the async case `AsyncThreadLock` is a no-op.
    r   c                 C  ó   | S ©Nr   r   r   r   r   Ú	__enter__e   ó   zAsyncThreadLock.__enter__Nr)   r*   r+   r,   r-   r.   r   c                 C  ó   d S r=   r   r1   r   r   r   Ú__exit__h   ó   zAsyncThreadLock.__exit__)r   r:   r4   r5   )r6   r7   r8   r9   r>   rA   r   r   r   r   r:   ]   s    
ür:   c                   @  s6   e Zd Zddd„Zddd„Zddd„Zdddd„Zd	S )Ú
AsyncEventr   r   c                 C  r   r   r   r   r   r   r   r   r   r   zAsyncEvent.__init__c                 C  r   r    )r   r   r
   ÚEventÚ_trio_eventr   Ú_anyio_eventr   r   r   r   r$   u   r%   zAsyncEvent.setupc                 C  sB   | j s|  ¡  | j dkr| j ¡  d S | j dkr| j ¡  d S d S r&   )r   r$   rE   ÚsetrF   r   r   r   r   rG   €   s   

ÿzAsyncEvent.setNÚtimeoutúfloat | Nonec              	   Ã  s>  �| j s|  ¡  | j dkrXtjti}|d u rtdƒn|}t|ƒ�. t |¡� | j 	¡ I d H  W d   ƒ n1 s9w   Y  W d   ƒ d S W d   ƒ d S 1 sQw   Y  d S | j dkr�t
ti}t|ƒ�. t |¡� | j 	¡ I d H  W d   ƒ n1 s~w   Y  W d   ƒ d S W d   ƒ d S 1 s–w   Y  d S d S )Nr
   Úinfr	   )r   r$   r
   ÚTooSlowErrorr   Úfloatr   Ú
fail_afterrE   ÚwaitÚTimeoutErrorr   rF   )r   rH   Útrio_exc_mapÚtimeout_or_infÚanyio_exc_mapr   r   r   rN   ‰   s.   €


ÿÿ"ÿ

ÿÿ"ÿþzAsyncEvent.waitr3   r=   ©rH   rI   r   r   )r6   r7   r8   r   r$   rG   rN   r   r   r   r   rC   q   s
    


	rC   c                   @  s4   e Zd Zddd„Zddd„Zdd	d
„Zddd„ZdS )ÚAsyncSemaphoreÚboundÚintr   r   c                 C  s   || _ d| _d S r   )Ú_boundr   ©r   rU   r   r   r   r   ›   s   
zAsyncSemaphore.__init__c                 C  sP   t ƒ | _| jdkrtj| j| jd�| _dS | jdkr&tj| j| jd�| _dS dS )zƒ
        Detect if we're running under 'asyncio' or 'trio' and create
        a semaphore with the correct implementation.
        r
   )Úinitial_valueÚ	max_valuer	   N)r   r   r
   Ú	SemaphorerW   Ú_trio_semaphorer   Ú_anyio_semaphorer   r   r   r   r$   Ÿ   s   
ÿ
ÿÿzAsyncSemaphore.setupc                 Ã  sP   �| j s|  ¡  | j dkr| j ¡ I d H  d S | j dkr&| j ¡ I d H  d S d S r&   )r   r$   r\   r'   r]   r   r   r   r   r'   ®   s   €

ÿzAsyncSemaphore.acquirec                 Ã  r/   r&   )r   r\   r0   r]   r   r   r   r   r0   ·   s   €

ÿzAsyncSemaphore.releaseN©rU   rV   r   r   r3   )r6   r7   r8   r   r$   r'   r0   r   r   r   r   rT   š   s
    


	rT   c                   @  s2   e Zd Zddd„Zddd„Z			dddd„ZdS )ÚAsyncShieldCancellationr   r   c                 C  sD   t ƒ | _| jdkrtjdd�| _dS | jdkr tjdd�| _dS dS )zˆ
        Detect if we're running under 'asyncio' or 'trio' and create
        a shielded scope with the correct implementation.
        r
   T)Úshieldr	   N)r   r   r
   ÚCancelScopeÚ_trio_shieldr   Ú_anyio_shieldr   r   r   r   r   Æ   s   

ÿz AsyncShieldCancellation.__init__c                 C  s0   | j dkr| j ¡  | S | j dkr| j ¡  | S r&   )r   rb   r>   rc   r   r   r   r   r>   Ò   s   


þ
z!AsyncShieldCancellation.__enter__Nr)   r*   r+   r,   r-   r.   c                 C  s@   | j dkr| j |||¡ d S | j dkr| j |||¡ d S d S r&   )r   rb   rA   rc   r1   r   r   r   rA   Ù   s
   

ÿz AsyncShieldCancellation.__exit__r3   )r   r_   r4   r5   )r6   r7   r8   r   r>   rA   r   r   r   r   r_   ¾   s    

	ür_   c                   @  ó6   e Zd ZdZddd„Zddd„Z			dddd„ZdS )r!   r   r   r   c                 C  ó   t  ¡ | _d S r=   ©Ú	threadingr!   Ú_lockr   r   r   r   r   ð   ó   zLock.__init__c                 C  ó   | j  ¡  | S r=   ©rh   r'   r   r   r   r   r>   ó   ó   
zLock.__enter__Nr)   r*   r+   r,   r-   r.   c                 C  ó   | j  ¡  d S r=   ©rh   r0   r1   r   r   r   rA   ÷   ó   zLock.__exit__r3   )r   r!   r4   r5   ©r6   r7   r8   r9   r   r>   rA   r   r   r   r   r!   è   ó    

ür!   c                   @  rd   )Ú
ThreadLockr;   r   r   c                 C  re   r=   rf   r   r   r   r   r     ri   zThreadLock.__init__c                 C  rj   r=   rk   r   r   r   r   r>     rl   zThreadLock.__enter__Nr)   r*   r+   r,   r-   r.   c                 C  rm   r=   rn   r1   r   r   r   rA     ro   zThreadLock.__exit__r3   )r   rr   r4   r5   rp   r   r   r   r   rr      rq   rr   c                   @  s,   e Zd Zddd„Zddd„Zddd
d„ZdS )rD   r   r   c                 C  re   r=   )rg   rD   Ú_eventr   r   r   r   r     ri   zEvent.__init__c                 C  rm   r=   )rs   rG   r   r   r   r   rG     ri   z	Event.setNrH   rI   c                 C  s(   |t dƒkrd }| jj|d�stƒ ‚d S )NrJ   )rH   )rL   rs   rN   r   )r   rH   r   r   r   rN     s
   ÿz
Event.waitr3   r=   rS   )r6   r7   r8   r   rG   rN   r   r   r   r   rD     s    

rD   c                   @  s*   e Zd Zddd„Zddd„Zdd	d
„ZdS )r[   rU   rV   r   r   c                 C  s   t j|d�| _d S )N)Úvalue)rg   r[   Ú
_semaphorerX   r   r   r   r   '  s   zSemaphore.__init__c                 C  rm   r=   )ru   r'   r   r   r   r   r'   *  ri   zSemaphore.acquirec                 C  rm   r=   )ru   r0   r   r   r   r   r0   -  ri   zSemaphore.releaseNr^   r3   )r6   r7   r8   r   r'   r0   r   r   r   r   r[   &  s    

r[   c                   @  s(   e Zd Zddd„Z			dddd„ZdS )ÚShieldCancellationr   c                 C  r<   r=   r   r   r   r   r   r>   5  r?   zShieldCancellation.__enter__Nr)   r*   r+   r,   r-   r.   r   c                 C  r@   r=   r   r1   r   r   r   rA   8  rB   zShieldCancellation.__exit__)r   rv   r4   r5   )r6   r7   r8   r>   rA   r   r   r   r   rv   1  s    
ürv   )r   r   )Ú
__future__r   rg   ÚtypesÚ_exceptionsr   r   r   r
   r   ÚNotImplementedErrorr   r   r   r:   rC   rT   r_   r!   rr   rD   r[   rv   r   r   r   r   Ú<module>   s2    ÿÿ
-)$*