o
    i$                  	   @  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   S/home/kim/smarthome/.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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
   ZTooSlowErrorr   floatr   Z
fail_afterrE   waitTimeoutErrorr   rF   )r   rH   Ztrio_exc_mapZtimeout_or_infZanyio_exc_mapr   r   r   rL      s.   


"

"zAsyncEvent.waitr3   r=   rH   rI   r   r   )r6   r7   r8   r   r$   rG   rL   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   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_valueZ	max_valuer	   N)r   r   r
   	SemaphorerR   _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   r0   rW   r   r   r   r   r0      s   

zAsyncSemaphore.releaseNrP   rQ   r   r   r3   )r6   r7   r8   r   r$   r'   r0   r   r   r   r   rO      s
    


	rO   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
   Z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__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   r[   rA   r\   r1   r   r   r   rA      s
   

z AsyncShieldCancellation.__exit__r3   )r   rY   r4   r5   )r6   r7   r8   r   r>   rA   r   r   r   r   rY      s    

	rY   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=   ra   r'   r   r   r   r   r>         
zLock.__enter__Nr)   r*   r+   r,   r-   r.   c                 C     | j   d S r=   ra   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                   @  r]   )
ThreadLockr;   r   r   c                 C  r^   r=   r_   r   r   r   r   r     rb   zThreadLock.__init__c                 C  rc   r=   rd   r   r   r   r   r>     re   zThreadLock.__enter__Nr)   r*   r+   r,   r-   r.   c                 C  rf   r=   rg   r1   r   r   r   rA     rh   zThreadLock.__exit__r3   )r   rk   r4   r5   ri   r   r   r   r   rk      rj   rk   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  r^   r=   )r`   rD   _eventr   r   r   r   r     rb   zEvent.__init__c                 C  rf   r=   )rl   rG   r   r   r   r   rG     rb   z	Event.setNrH   rI   c                 C  s(   |t dkrd }| jj|dst d S )NrJ   )rH   )rK   rl   rL   r   )r   rH   r   r   r   rL     s
   z
Event.waitr3   r=   rN   )r6   r7   r8   r   rG   rL   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 )rU   rP   rQ   r   r   c                 C  s   t j|d| _d S )N)value)r`   rU   
_semaphorerS   r   r   r   r   '  s   zSemaphore.__init__c                 C  rf   r=   )rn   r'   r   r   r   r   r'   *  rb   zSemaphore.acquirec                 C  rf   r=   )rn   r0   r   r   r   r   r0   -  rb   zSemaphore.releaseNrX   r3   )r6   r7   r8   r   r'   r0   r   r   r   r   rU   &  s    

rU   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   ro   r4   r5   )r6   r7   r8   r>   rA   r   r   r   r   ro   1  s    
ro   )r   r   )
__future__r   r`   types_exceptionsr   r   r   r
   r   NotImplementedErrorr   r   r   r:   rC   rO   rY   r!   rk   rD   rU   ro   r   r   r   r   <module>   s2    
-)$*