o
    ;'h`O  ã                   @  s”  d dl mZ d dlZd dlmZ d dlmZ d dlmZ d dl	m
Z
 ddlmZ d	d
lmZ d	dlmZ d	dlmZ d	dlmZmZ edd�G dd„ dƒƒZedd�G dd„ dƒƒZedd�G dd„ dƒƒZedd�G dd„ dƒƒZedd�G dd„ dƒƒZG dd„ dƒZG dd„ deƒZG dd„ dƒZG d d!„ d!eƒZG d"d#„ d#ƒZG d$d%„ d%ƒZ G d&d'„ d'e ƒZ!G d(d)„ d)ƒZ"G d*d+„ d+e"ƒZ#G d,d-„ d-ƒZ$dS ).é    )ÚannotationsN)Údeque)Ú	dataclass)ÚTracebackType)ÚAsyncLibraryNotFoundErroré   )Ú
checkpointé   )Úget_async_backend)ÚBusyResourceError)ÚCancelScope)ÚTaskInfoÚget_current_taskT)Úfrozenc                   @  ó   e Zd ZU dZded< dS )ÚEventStatisticszR
    :ivar int tasks_waiting: number of tasks waiting on :meth:`~.Event.wait`
    ÚintÚtasks_waitingN©Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú__annotations__© r   r   úRC:\Users\shubh\Videos\agent\nova\Lib\site-packages\anyio/_core/_synchronization.pyr      s   
 r   c                   @  s2   e Zd ZU dZded< ded< ded< ded< d	S )
ÚCapacityLimiterStatisticsaš  
    :ivar int borrowed_tokens: number of tokens currently borrowed by tasks
    :ivar float total_tokens: total number of available tokens
    :ivar tuple borrowers: tasks or other objects currently holding tokens borrowed from
        this limiter
    :ivar int tasks_waiting: number of tasks waiting on
        :meth:`~.CapacityLimiter.acquire` or
        :meth:`~.CapacityLimiter.acquire_on_behalf_of`
    r   Úborrowed_tokensÚfloatÚtotal_tokensztuple[object, ...]Ú	borrowersr   Nr   r   r   r   r   r      s   
 
r   c                   @  s*   e Zd ZU dZded< ded< ded< dS )	ÚLockStatisticsa  
    :ivar bool locked: flag indicating if this lock is locked or not
    :ivar ~anyio.TaskInfo owner: task currently holding the lock (or ``None`` if the
        lock is not held by any task)
    :ivar int tasks_waiting: number of tasks waiting on :meth:`~.Lock.acquire`
    ÚboolÚlockedúTaskInfo | NoneÚownerr   r   Nr   r   r   r   r   r!   ,   s
   
 r!   c                   @  s"   e Zd ZU dZded< ded< dS )ÚConditionStatisticsz¼
    :ivar int tasks_waiting: number of tasks blocked on :meth:`~.Condition.wait`
    :ivar ~anyio.LockStatistics lock_statistics: statistics of the underlying
        :class:`~.Lock`
    r   r   r!   Zlock_statisticsNr   r   r   r   r   r&   :   s   
 r&   c                   @  r   )ÚSemaphoreStatisticszZ
    :ivar int tasks_waiting: number of tasks waiting on :meth:`~.Semaphore.acquire`

    r   r   Nr   r   r   r   r   r'   F   s   
 r'   c                   @  s>   e Zd Zddd„Zddd„Zddd	„Zdd
d„Zddd„ZdS )ÚEventÚreturnc                 C  s&   zt ƒ  ¡ W S  ty   tƒ  Y S w ©N)r
   Úcreate_eventr   ÚEventAdapter©Úclsr   r   r   Ú__new__Q   s
   
ÿzEvent.__new__ÚNonec                 C  ó   t ‚)z&Set the flag, notifying all listeners.©ÚNotImplementedError©Úselfr   r   r   ÚsetW   ó   z	Event.setr"   c                 C  r1   )z5Return ``True`` if the flag is set, ``False`` if not.r2   r4   r   r   r   Úis_set[   r7   zEvent.is_setc                 Ã  ó   �t ‚)zš
        Wait until the flag has been set.

        If the flag has already been set when this method is called, it returns
        immediately.

        r2   r4   r   r   r   Úwait_   s   €z
Event.waitr   c                 C  r1   )z8Return statistics about the current state of this event.r2   r4   r   r   r   Ú
statisticsi   r7   zEvent.statisticsN©r)   r(   ©r)   r0   ©r)   r"   ©r)   r   )r   r   r   r/   r6   r8   r:   r;   r   r   r   r   r(   P   s    




r(   c                   @  sf   e Zd ZU dZded< dZded< ddd	„Zeddd„ƒZddd„Z	ddd„Z
ddd„Zddd„ZdS )r,   NzEvent | NoneÚ_internal_eventFr"   Ú_is_setr)   c                 C  ó
   t  | ¡S r*   ©Úobjectr/   r-   r   r   r   r/   r   ó   
zEventAdapter.__new__r(   c                 C  s,   | j d u rtƒ  ¡ | _ | jr| j  ¡  | j S r*   )r@   r
   r+   rA   r6   r4   r   r   r   Ú_eventu   s
   

zEventAdapter._eventr0   c                 C  s"   | j d u r
d| _d S | j ¡  d S ©NT)r@   rA   rF   r6   r4   r   r   r   r6   ~   s   

zEventAdapter.setc                 C  s   | j d u r| jS | j  ¡ S r*   )r@   rA   r8   r4   r   r   r   r8   „   s   

zEventAdapter.is_setc                 Ã  ó   �| j  ¡ I d H  d S r*   )rF   r:   r4   r   r   r   r:   Š   ó   €zEventAdapter.waitr   c                 C  s   | j d u r
tdd�S | j  ¡ S ©Nr   )r   )r@   r   r;   r4   r   r   r   r;   �   ó   


zEventAdapter.statistics)r)   r,   r<   r=   r>   r?   )r   r   r   r@   r   rA   r/   ÚpropertyrF   r6   r8   r:   r;   r   r   r   r   r,   n   s   
 



r,   c                   @  sb   e Zd Zddœddd„Zd d	d
„Zd!dd„Zd dd„Zd dd„Zd dd„Zd"dd„Z	d#dd„Z
dS )$ÚLockF©Úfast_acquirerO   r"   r)   c                C  s.   zt ƒ j|d�W S  ty   t|d� Y S w ©NrN   )r
   Úcreate_lockr   ÚLockAdapter©r.   rO   r   r   r   r/   •   s
   ÿzLock.__new__r0   c                 Ã  ó   �|   ¡ I d H  d S r*   ©Úacquirer4   r   r   r   Ú
__aenter__›   ó   €zLock.__aenter__Úexc_typeútype[BaseException] | NoneÚexc_valúBaseException | NoneÚexc_tbúTracebackType | Nonec                 Ã  ó   �|   ¡  d S r*   ©Úrelease©r5   rY   r[   r]   r   r   r   Ú	__aexit__ž   ó   €zLock.__aexit__c                 Ã  r9   )úAcquire the lock.r2   r4   r   r   r   rV   ¦   ó   €zLock.acquirec                 C  r1   )úw
        Acquire the lock, without blocking.

        :raises ~anyio.WouldBlock: if the operation would block

        r2   r4   r   r   r   Úacquire_nowaitª   ó   zLock.acquire_nowaitc                 C  r1   )úRelease the lock.r2   r4   r   r   r   ra   ³   r7   zLock.releasec                 C  r1   ©z*Return True if the lock is currently held.r2   r4   r   r   r   r#   ·   r7   zLock.lockedr!   c                 C  r1   )zh
        Return statistics about the current state of this lock.

        .. versionadded:: 3.0
        r2   r4   r   r   r   r;   »   ó   zLock.statisticsN)rO   r"   r)   rM   r=   ©rY   rZ   r[   r\   r]   r^   r)   r0   r>   ©r)   r!   )r   r   r   r/   rW   rc   rV   rh   ra   r#   r;   r   r   r   r   rM   ”   s    




	
rM   c                   @  sŽ   e Zd ZU dZded< ddœd&d	d
„Zddœd'dd„Zed(dd„ƒZd)dd„Z	d*dd„Z
d)dd„Zd)dd„Zd)dd „Zd+d!d"„Zd,d$d%„ZdS )-rR   NúLock | NoneÚ_internal_lockFrN   rO   r"   r)   c                C  rB   r*   rC   rS   r   r   r   r/   Ç   rE   zLockAdapter.__new__c                C  ó
   || _ d S r*   )Ú_fast_acquire)r5   rO   r   r   r   Ú__init__Ê   rE   zLockAdapter.__init__rM   c                 C  s"   | j d u rtƒ j| jd�| _ | j S rP   )rp   r
   rQ   rr   r4   r   r   r   Ú_lockÍ   s
   
ÿzLockAdapter._lockr0   c                 Ã  rH   r*   ©rt   rV   r4   r   r   r   rW   Ö   rI   zLockAdapter.__aenter__rY   rZ   r[   r\   r]   r^   c                 Ã  s   �| j d ur| j  ¡  d S d S r*   )rp   ra   rb   r   r   r   rc   Ù   s   €
ÿzLockAdapter.__aexit__c                 Ã  s   �| j  ¡ I dH  dS )re   Nru   r4   r   r   r   rV   â   s   €zLockAdapter.acquirec                 C  ó   | j  ¡  dS )rg   N)rt   rh   r4   r   r   r   rh   æ   s   zLockAdapter.acquire_nowaitc                 C  rv   )rj   N©rt   ra   r4   r   r   r   ra   ï   ó   zLockAdapter.releasec                 C  ó
   | j  ¡ S rk   ©rt   r#   r4   r   r   r   r#   ó   ó   
zLockAdapter.lockedr!   c                 C  s    | j du rtdddƒS | j  ¡ S )zi
        Return statistics about the current state of this lock.

        .. versionadded:: 3.0

        NFr   )rp   r!   r;   r4   r   r   r   r;   ÷   s   

zLockAdapter.statistics)rO   r"   r)   rR   )rO   r"   )r)   rM   r=   rm   r>   rn   )r   r   r   rp   r   r/   rs   rL   rt   rW   rc   rV   rh   ra   r#   r;   r   r   r   r   rR   Ä   s   
 


	

	
rR   c                   @  s–   e Zd ZU dZded< d+d,dd„Zd-d
d„Zd.dd„Zd-dd„Zd-dd„Z	d-dd„Z
d-dd„Zd/dd„Zd0d1d"d#„Zd-d$d%„Zd-d&d'„Zd2d)d*„ZdS )3Ú	ConditionNr$   Ú_owner_taskÚlockro   c                 C  s   |pt ƒ | _tƒ | _d S r*   )rM   rt   r   Ú_waiters)r5   r~   r   r   r   rs     s   zCondition.__init__r)   r0   c                 Ã  rT   r*   rU   r4   r   r   r   rW     rX   zCondition.__aenter__rY   rZ   r[   r\   r]   r^   c                 Ã  r_   r*   r`   rb   r   r   r   rc     rd   zCondition.__aexit__c                 C  s   | j tƒ kr
tdƒ‚d S )Nz3The current task is not holding the underlying lock)r}   r   ÚRuntimeErrorr4   r   r   r   Ú_check_acquired  s   ÿzCondition._check_acquiredc                 Ã  s   �| j  ¡ I dH  tƒ | _dS )zAcquire the underlying lock.N)rt   rV   r   r}   r4   r   r   r   rV     s   €zCondition.acquirec                 C  s   | j  ¡  tƒ | _dS )ú‚
        Acquire the underlying lock, without blocking.

        :raises ~anyio.WouldBlock: if the operation would block

        N)rt   rh   r   r}   r4   r   r   r   rh     s   
zCondition.acquire_nowaitc                 C  rv   )zRelease the underlying lock.Nrw   r4   r   r   r   ra   )  rx   zCondition.releaser"   c                 C  ry   )zReturn True if the lock is set.rz   r4   r   r   r   r#   -  r{   zCondition.lockedr	   Únr   c              	   C  sH   |   ¡  t|ƒD ]}z| j ¡ }W n ty   Y  dS w | ¡  qdS )zNotify exactly n listeners.N)r�   Úranger   ÚpopleftÚ
IndexErrorr6   )r5   rƒ   Ú_Úeventr   r   r   Únotify1  s   ÿ
úzCondition.notifyc                 C  s*   |   ¡  | jD ]}| ¡  q| j ¡  dS )zNotify all the listeners.N)r�   r   r6   Úclear©r5   rˆ   r   r   r   Ú
notify_all<  s   

zCondition.notify_allc                 Ã  sÜ   �t ƒ I dH  tƒ }| j |¡ |  ¡  z<z	| ¡ I dH  W n ty0   | ¡ s/| j |¡ ‚ w W t	dd�� |  
¡ I dH  W d  ƒ dS 1 sJw   Y  dS t	dd�� |  
¡ I dH  W d  ƒ w 1 shw   Y  w )zWait for a notification.NT)Úshield)r   r(   r   Úappendra   r:   ÚBaseExceptionr8   Úremover   rV   r‹   r   r   r   r:   D  s$   €üÿ.ÿÿzCondition.waitr&   c                 C  s   t t| jƒ| j ¡ ƒS )zm
        Return statistics about the current state of this condition.

        .. versionadded:: 3.0
        )r&   Úlenr   rt   r;   r4   r   r   r   r;   U  s   zCondition.statisticsr*   )r~   ro   r=   rm   r>   )r	   )rƒ   r   r)   r0   )r)   r&   )r   r   r   r}   r   rs   rW   rc   r�   rV   rh   ra   r#   r‰   rŒ   r:   r;   r   r   r   r   r|     s   
 









r|   c                   @  sˆ   e Zd Zdddœd'dd„Zdddœd(dd„Zd)dd„Zd*dd„Zd+dd„Zd+dd„Zd+dd„Z	e
d,d d!„ƒZe
d-d"d#„ƒZd.d%d&„ZdS )/Ú	SemaphoreNF©Ú	max_valuerO   Úinitial_valuer   r”   ú
int | NonerO   r"   r)   c                C  s4   z
t ƒ j|||d�W S  ty   t||d� Y S w )Nr“   ©r”   )r
   Úcreate_semaphorer   ÚSemaphoreAdapter©r.   r•   r”   rO   r   r   r   r/   _  s   ÿÿzSemaphore.__new__c                C  sV   t |tƒs	tdƒ‚|dk rtdƒ‚|d ur&t |tƒstdƒ‚||k r&tdƒ‚|| _d S )Nz initial_value must be an integerr   zinitial_value must be >= 0z$max_value must be an integer or Nonez7max_value must be equal to or higher than initial_value)Ú
isinstancer   Ú	TypeErrorÚ
ValueErrorrr   ©r5   r•   r”   rO   r   r   r   rs   m  s   

ÿ
zSemaphore.__init__c                 Ã  s   �|   ¡ I d H  | S r*   rU   r4   r   r   r   rW   ‚  s   €zSemaphore.__aenter__rY   rZ   r[   r\   r]   r^   r0   c                 Ã  r_   r*   r`   rb   r   r   r   rc   †  rd   zSemaphore.__aexit__c                 Ã  r9   )z5Decrement the semaphore value, blocking if necessary.r2   r4   r   r   r   rV   Ž  rf   zSemaphore.acquirec                 C  r1   )r‚   r2   r4   r   r   r   rh   ’  ri   zSemaphore.acquire_nowaitc                 C  r1   )zIncrement the semaphore value.r2   r4   r   r   r   ra   ›  r7   zSemaphore.releasec                 C  r1   )z#The current value of the semaphore.r2   r4   r   r   r   ÚvalueŸ  ó   zSemaphore.valuec                 C  r1   )z#The maximum value of the semaphore.r2   r4   r   r   r   r”   ¤  r    zSemaphore.max_valuer'   c                 C  r1   )zm
        Return statistics about the current state of this semaphore.

        .. versionadded:: 3.0
        r2   r4   r   r   r   r;   ©  rl   zSemaphore.statistics)r•   r   r”   r–   rO   r"   r)   r’   )r•   r   r”   r–   rO   r"   ©r)   r’   rm   r=   ©r)   r   ©r)   r–   ©r)   r'   )r   r   r   r/   rs   rW   rc   rV   rh   ra   rL   rŸ   r”   r;   r   r   r   r   r’   ^  s"    ûû




	r’   c                      s˜   e Zd ZU dZded< dddœd"dd„Zdddœd#‡ fdd„Zed$dd„ƒZd%dd„Z	d%dd„Z
d%dd„Zed&dd„ƒZed'dd„ƒZd(d d!„Z‡  ZS ))r™   NzSemaphore | NoneÚ_internal_semaphoreFr“   r•   r   r”   r–   rO   r"   r)   c                C  rB   r*   rC   rš   r   r   r   r/   µ  s   
zSemaphoreAdapter.__new__r0   c                  s"   t ƒ j|||d� || _|| _d S )Nr“   )Úsuperrs   Ú_initial_valueÚ
_max_valuerž   ©Ú	__class__r   r   rs   ¾  s   
zSemaphoreAdapter.__init__r’   c                 C  s&   | j d u rtƒ j| j| jd�| _ | j S )Nr—   )r¥   r
   r˜   r§   r¨   r4   r   r   r   Ú
_semaphoreÉ  s
   
ÿzSemaphoreAdapter._semaphorec                 Ã  rH   r*   )r«   rV   r4   r   r   r   rV   Ò  rI   zSemaphoreAdapter.acquirec                 C  ó   | j  ¡  d S r*   )r«   rh   r4   r   r   r   rh   Õ  ó   zSemaphoreAdapter.acquire_nowaitc                 C  r¬   r*   )r«   ra   r4   r   r   r   ra   Ø  r­   zSemaphoreAdapter.releasec                 C  s   | j d u r| jS | jjS r*   )r¥   r§   r«   rŸ   r4   r   r   r   rŸ   Û  ó   
zSemaphoreAdapter.valuec                 C  s   | j S r*   )r¨   r4   r   r   r   r”   â  s   zSemaphoreAdapter.max_valuer'   c                 C  s   | j d u r
tdd�S | j ¡ S rJ   )r¥   r'   r«   r;   r4   r   r   r   r;   æ  rK   zSemaphoreAdapter.statistics)r•   r   r”   r–   rO   r"   r)   r™   )r•   r   r”   r–   rO   r"   r)   r0   r¡   r=   r¢   r£   r¤   )r   r   r   r¥   r   r/   rs   rL   r«   rV   rh   ra   rŸ   r”   r;   Ú__classcell__r   r   r©   r   r™   ²  s$   
 ûû


r™   c                   @  sª   e Zd Zd-dd„Zd.dd„Zd/dd„Zed0dd„ƒZejd1dd„ƒZed2dd„ƒZ	ed0dd„ƒZ
d.dd„Zd3dd „Zd.d!d"„Zd3d#d$„Zd.d%d&„Zd3d'd(„Zd4d*d+„Zd,S )5ÚCapacityLimiterr   r   r)   c                 C  s*   zt ƒ  |¡W S  ty   t|ƒ Y S w r*   )r
   Úcreate_capacity_limiterr   ÚCapacityLimiterAdapter©r.   r   r   r   r   r/   î  s
   ÿzCapacityLimiter.__new__r0   c                 Ã  r9   r*   r2   r4   r   r   r   rW   ô  s   €zCapacityLimiter.__aenter__rY   rZ   r[   r\   r]   r^   úbool | Nonec                 Ã  r9   r*   r2   rb   r   r   r   rc   ÷  ó   €zCapacityLimiter.__aexit__c                 C  r1   )aM  
        The total number of tokens available for borrowing.

        This is a read-write property. If the total number of tokens is increased, the
        proportionate number of tasks waiting on this limiter will be granted their
        tokens.

        .. versionchanged:: 3.0
            The property is now writable.

        r2   r4   r   r   r   r   ÿ  s   zCapacityLimiter.total_tokensrŸ   c                 C  r1   r*   r2   ©r5   rŸ   r   r   r   r     r7   r   c                 C  r1   )z7The number of tokens that have currently been borrowed.r2   r4   r   r   r   r     r    zCapacityLimiter.borrowed_tokensc                 C  r1   )z7The number of tokens currently available to be borrowedr2   r4   r   r   r   Úavailable_tokens  r    z CapacityLimiter.available_tokensc                 C  r1   )z¿
        Acquire a token for the current task without waiting for one to become
        available.

        :raises ~anyio.WouldBlock: if there are no tokens available for borrowing

        r2   r4   r   r   r   rh     ó   zCapacityLimiter.acquire_nowaitÚborrowerrD   c                 C  r1   )zØ
        Acquire a token without waiting for one to become available.

        :param borrower: the entity borrowing a token
        :raises ~anyio.WouldBlock: if there are no tokens available for borrowing

        r2   ©r5   r¹   r   r   r   Úacquire_on_behalf_of_nowait&  r¸   z+CapacityLimiter.acquire_on_behalf_of_nowaitc                 Ã  r9   )zr
        Acquire a token for the current task, waiting if necessary for one to become
        available.

        r2   r4   r   r   r   rV   0  rµ   zCapacityLimiter.acquirec                 Ã  r9   )zŒ
        Acquire a token, waiting if necessary for one to become available.

        :param borrower: the entity borrowing a token

        r2   rº   r   r   r   Úacquire_on_behalf_of8  s   €z$CapacityLimiter.acquire_on_behalf_ofc                 C  r1   )z©
        Release the token held by the current task.

        :raises RuntimeError: if the current task has not borrowed a token from this
            limiter.

        r2   r4   r   r   r   ra   A  r¸   zCapacityLimiter.releasec                 C  r1   )z§
        Release the token held by the given borrower.

        :raises RuntimeError: if the borrower has not borrowed a token from this
            limiter.

        r2   rº   r   r   r   Úrelease_on_behalf_ofK  r¸   z$CapacityLimiter.release_on_behalf_ofr   c                 C  r1   )zl
        Return statistics about the current state of this limiter.

        .. versionadded:: 3.0

        r2   r4   r   r   r   r;   U  ri   zCapacityLimiter.statisticsN)r   r   r)   r°   r=   ©rY   rZ   r[   r\   r]   r^   r)   r´   ©r)   r   ©rŸ   r   r)   r0   r¢   ©r¹   rD   r)   r0   ©r)   r   )r   r   r   r/   rW   rc   rL   r   Úsetterr   r·   rh   r»   rV   r¼   ra   r½   r;   r   r   r   r   r°   í  s&    









	


r°   c                   @  sÐ   e Zd ZU dZded< d4dd„Zd5d
d„Zed6dd„ƒZd7dd„Z	d8dd„Z
ed9dd„ƒZejd:dd„ƒZed;dd „ƒZed9d!d"„ƒZd7d#d$„Zd<d'd(„Zd7d)d*„Zd<d+d,„Zd7d-d.„Zd<d/d0„Zd=d2d3„ZdS )>r²   NzCapacityLimiter | NoneÚ_internal_limiterr   r   r)   c                 C  rB   r*   rC   r³   r   r   r   r/   b  rE   zCapacityLimiterAdapter.__new__r0   c                 C  rq   r*   )r   )r5   r   r   r   r   rs   e  rE   zCapacityLimiterAdapter.__init__r°   c                 C  s    | j d u rtƒ  | j¡| _ | j S r*   )rÄ   r
   r±   Ú_total_tokensr4   r   r   r   Ú_limiterh  s
   
ÿzCapacityLimiterAdapter._limiterc                 Ã  rH   r*   )rÆ   rW   r4   r   r   r   rW   q  rI   z!CapacityLimiterAdapter.__aenter__rY   rZ   r[   r\   r]   r^   r´   c                 Ã  s   �| j  |||¡I d H S r*   )rÆ   rc   rb   r   r   r   rc   t  s   €z CapacityLimiterAdapter.__aexit__c                 C  ó   | j d u r| jS | j jS r*   )rÄ   rÅ   r   r4   r   r   r   r   |  r®   z#CapacityLimiterAdapter.total_tokensrŸ   c                 C  sL   t |tƒs|tjurtdƒ‚|dk rtdƒ‚| jd u r || _d S || j_	d S )Nz'total_tokens must be an int or math.infr	   ztotal_tokens must be >= 1)
r›   r   ÚmathÚinfrœ   r�   rÄ   rÅ   rÆ   r   r¶   r   r   r   r   ƒ  s   
r   c                 C  s   | j d u rdS | j jS )Nr   )rÄ   r   r4   r   r   r   r   �  s   
z&CapacityLimiterAdapter.borrowed_tokensc                 C  rÇ   r*   )rÄ   rÅ   r·   r4   r   r   r   r·   —  r®   z'CapacityLimiterAdapter.available_tokensc                 C  r¬   r*   )rÆ   rh   r4   r   r   r   rh   ž  r­   z%CapacityLimiterAdapter.acquire_nowaitr¹   rD   c                 C  ó   | j  |¡ d S r*   )rÆ   r»   rº   r   r   r   r»   ¡  ó   z2CapacityLimiterAdapter.acquire_on_behalf_of_nowaitc                 Ã  rH   r*   )rÆ   rV   r4   r   r   r   rV   ¤  rI   zCapacityLimiterAdapter.acquirec                 Ã  s   �| j  |¡I d H  d S r*   )rÆ   r¼   rº   r   r   r   r¼   §  s   €z+CapacityLimiterAdapter.acquire_on_behalf_ofc                 C  r¬   r*   )rÆ   ra   r4   r   r   r   ra   ª  r­   zCapacityLimiterAdapter.releasec                 C  rÊ   r*   )rÆ   r½   rº   r   r   r   r½   ­  rË   z+CapacityLimiterAdapter.release_on_behalf_ofr   c                 C  s&   | j d u rtd| jddd�S | j  ¡ S )Nr   r   )r   r   r    r   )rÄ   r   r   r;   r4   r   r   r   r;   °  s   
ü
z!CapacityLimiterAdapter.statistics)r   r   r)   r²   )r   r   r)   r0   )r)   r°   r=   r¾   r¿   rÀ   r¢   rÁ   rÂ   )r   r   r   rÄ   r   r/   rs   rL   rÆ   rW   rc   r   rÃ   r   r·   rh   r»   rV   r¼   ra   r½   r;   r   r   r   r   r²   _  s.   
 









r²   c                   @  s4   e Zd ZdZdZdddd„Zdd
d„Zddd„ZdS )ÚResourceGuardaŸ  
    A context manager for ensuring that a resource is only used by a single task at a
    time.

    Entering this context manager while the previous has not exited it yet will trigger
    :exc:`BusyResourceError`.

    :param action: the action to guard against (visible in the :exc:`BusyResourceError`
        when triggered, e.g. "Another task is already {action} this resource")

    .. versionadded:: 4.1
    ©ÚactionÚ_guardedÚusingrÎ   Ústrc                 C  s   || _ d| _d S ©NFrÍ   )r5   rÎ   r   r   r   rs   Ì  s   
zResourceGuard.__init__r)   r0   c                 C  s   | j rt| jƒ‚d| _ d S rG   )rÏ   r   rÎ   r4   r   r   r   Ú	__enter__Ð  s   

zResourceGuard.__enter__rY   rZ   r[   r\   r]   r^   c                 C  s
   d| _ d S rÒ   )rÏ   rb   r   r   r   Ú__exit__Ö  s   
zResourceGuard.__exit__N)rÐ   )rÎ   rÑ   r=   rm   )r   r   r   r   Ú	__slots__rs   rÓ   rÔ   r   r   r   r   rÌ   ¼  s    
rÌ   )%Ú
__future__r   rÈ   Úcollectionsr   Údataclassesr   Útypesr   Zsniffior   Zlowlevelr   Z
_eventloopr
   Ú_exceptionsr   Ú_tasksr   Z_testingr   r   r   r   r!   r&   r'   r(   r,   rM   rR   r|   r’   r™   r°   r²   rÌ   r   r   r   r   Ú<module>   s>    	&0@ZT;r]