o
    h$                     @   s  d dl Z d dlmZ d dlmZmZ ddlmZmZm	Z	 zd dl
Z
W n ey-   dZ
Y nw zd dlZW n ey?   dZY nw def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 )    N)TracebackType)OptionalType   )ExceptionMappingPoolTimeoutmap_exceptionsreturnc                  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   Q/var/www/html/zoom/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
eee	  dee	 dee
 ddf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	   Nc                 C   
   d| _ d S N _backendselfr   r   r   __init__7      
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__E   s   

zAsyncLock.__aenter__exc_type	exc_value	tracebackc                    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__P   s   

zAsyncLock.__aexit__r	   N)r	   r   NNN)__name__
__module____qualname____doc__r   r$   r(   r   r   BaseExceptionr   r/   r   r   r   r   r   /   s"    



r   c                	   @   sL   e Zd ZdZdddZ			ddeee  dee dee ddf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__d      zAsyncThreadLock.__enter__Nr)   r*   r+   c                 C      d S r:   r   r.   r   r   r   __exit__g      zAsyncThreadLock.__exit__)r	   r7   r1   )
r2   r3   r4   r5   r;   r   r   r6   r   r>   r   r   r   r   r7   \   s    

r7   c                   @   sB   e Zd ZdddZdddZdddZdd	ee ddfd
dZdS )
AsyncEventr	   Nc                 C   r   r   r   r   r   r   r   r   q   r   zAsyncEvent.__init__c                 C   r   r    )r   r   r   Event_trio_eventr   _anyio_eventr   r   r   r   r$   t   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$   rB   setrC   r   r   r   r   rD      s   

zAsyncEvent.settimeoutc              	      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rt
ti}t|. t| | j	 I d H  W d    n1 s~w   Y  W d    d S W d    d S 1 sw   Y  d S d S )Nr   infr
   )r   r$   r   TooSlowErrorr   floatr   
fail_afterrB   waitTimeoutErrorr   rC   )r   rE   trio_exc_maptimeout_or_infanyio_exc_mapr   r   r   rJ      s.   


"

"zAsyncEvent.waitr0   r:   )	r2   r3   r4   r   r$   rD   r   rH   rJ   r   r   r   r   r@   p   s
    


	r@   c                   @   s<   e Zd ZdeddfddZdddZddd	Zdd
dZdS )AsyncSemaphoreboundr	   Nc                 C   s   || _ d| _d S r   )_boundr   r   rP   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   	SemaphorerQ   _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$   rV   r'   rW   r   r   r   r   r'      s   

zAsyncSemaphore.acquirec                    r,   r&   )r   rV   r-   rW   r   r   r   r   r-      s   

zAsyncSemaphore.releaser0   )r2   r3   r4   intr   r$   r'   r-   r   r   r   r   rO      s
    

	rO   c                	   @   sR   e Zd ZdddZdddZ			ddeee  dee d	ee ddfd
dZ	dS )AsyncShieldCancellationr	   Nc                 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   r\   r;   r]   r   r   r   r   r;      s   



z!AsyncShieldCancellation.__enter__r)   r*   r+   c                 C   s@   | j dkr| j||| d S | j dkr| j||| d S d S r&   )r   r\   r>   r]   r.   r   r   r   r>      s
   

z AsyncShieldCancellation.__exit__r0   )r	   rY   r1   )
r2   r3   r4   r   r;   r   r   r6   r   r>   r   r   r   r   rY      s    

	
rY   c                	   @   V   e Zd ZdZdddZdddZ			ddeee  d	ee d
ee	 ddfddZ
dS )r!   r   r	   Nc                 C      t  | _d S r:   	threadingr!   _lockr   r   r   r   r         zLock.__init__c                 C      | j   | S r:   rb   r'   r   r   r   r   r;         
zLock.__enter__r)   r*   r+   c                 C      | j   d S r:   rb   r-   r.   r   r   r   r>         zLock.__exit__r0   )r	   r!   r1   r2   r3   r4   r5   r   r;   r   r   r6   r   r>   r   r   r   r   r!           


r!   c                	   @   r^   )
ThreadLockr8   r	   Nc                 C   r_   r:   r`   r   r   r   r   r     rc   zThreadLock.__init__c                 C   rd   r:   re   r   r   r   r   r;   
  rf   zThreadLock.__enter__r)   r*   r+   c                 C   rg   r:   rh   r.   r   r   r   r>     ri   zThreadLock.__exit__r0   )r	   rl   r1   rj   r   r   r   r   rl      rk   rl   c                   @   s8   e Zd Zd
ddZd
ddZddee ddfdd	ZdS )rA   r	   Nc                 C   r_   r:   )ra   rA   _eventr   r   r   r   r     rc   zEvent.__init__c                 C   rg   r:   )rm   rD   r   r   r   r   rD     rc   z	Event.setrE   c                 C   s(   |t dkrd }| jj|dst d S )NrF   )rE   )rH   rm   rJ   r   )r   rE   r   r   r   rJ     s
   z
Event.waitr0   r:   )r2   r3   r4   r   rD   r   rH   rJ   r   r   r   r   rA     s    

rA   c                   @   s2   e Zd ZdeddfddZd
ddZd
dd	ZdS )rU   rP   r	   Nc                 C   s   t j|d| _d S )N)value)ra   rU   
_semaphorerR   r   r   r   r   &  s   zSemaphore.__init__c                 C   rg   r:   )ro   r'   r   r   r   r   r'   )  rc   zSemaphore.acquirec                 C   rg   r:   )ro   r-   r   r   r   r   r-   ,  rc   zSemaphore.releaser0   )r2   r3   r4   rX   r   r'   r-   r   r   r   r   rU   %  s    
rU   c                	   @   sH   e Zd Zd
ddZ			ddeee  dee dee ddfdd	ZdS )ShieldCancellationr	   c                 C   r9   r:   r   r   r   r   r   r;   4  r<   zShieldCancellation.__enter__Nr)   r*   r+   c                 C   r=   r:   r   r.   r   r   r   r>   7  r?   zShieldCancellation.__exit__)r	   rp   r1   )	r2   r3   r4   r;   r   r   r6   r   r>   r   r   r   r   rp   0  s    

rp   )ra   typesr   typingr   r   _exceptionsr   r   r   r   r   r   strr   r   r7   r@   rO   rY   r!   rl   rA   rU   rp   r   r   r   r   <module>   s2    -)$*