Hacked By AnonymousFox

Current Path : /opt/alt/python311/lib64/python3.11/asyncio/__pycache__/
Upload File :
Current File : //opt/alt/python311/lib64/python3.11/asyncio/__pycache__/locks.cpython-311.pyc

�

c��fFJ��b�dZdZddlZddlZddlmZddlmZddlmZGd�d	��ZGd
�deej	��Z
Gd�d
ej	��ZGd�deej	��ZGd�deej	��Z
Gd�de
��ZGd�dej��ZGd�dej	��ZdS)zSynchronization primitives.)�Lock�Event�	Condition�	Semaphore�BoundedSemaphore�Barrier�N�)�
exceptions)�mixins)�tasksc��eZdZd�Zd�ZdS)�_ContextManagerMixinc��>K�|����d{V��dS�N)�acquire��selfs �4/opt/alt/python311/lib64/python3.11/asyncio/locks.py�
__aenter__z_ContextManagerMixin.__aenter__s-�����l�l�n�n���������t�c��2K�|���dSr)�release)r�exc_type�exc�tbs    r�	__aexit__z_ContextManagerMixin.__aexit__s�����������rN)�__name__�
__module__�__qualname__rr�rrrr
s2�������������rrc�@��eZdZdZd�Z�fd�Zd�Zd�Zd�Zd�Z	�xZ
S)ra�Primitive lock objects.

    A primitive lock is a synchronization primitive that is not owned
    by a particular coroutine when locked.  A primitive lock is in one
    of two states, 'locked' or 'unlocked'.

    It is created in the unlocked state.  It has two basic methods,
    acquire() and release().  When the state is unlocked, acquire()
    changes the state to locked and returns immediately.  When the
    state is locked, acquire() blocks until a call to release() in
    another coroutine changes it to unlocked, then the acquire() call
    resets it to locked and returns.  The release() method should only
    be called in the locked state; it changes the state to unlocked
    and returns immediately.  If an attempt is made to release an
    unlocked lock, a RuntimeError will be raised.

    When more than one coroutine is blocked in acquire() waiting for
    the state to turn to unlocked, only one coroutine proceeds when a
    release() call resets the state to unlocked; first coroutine which
    is blocked in acquire() is being processed.

    acquire() is a coroutine and should be called with 'await'.

    Locks also support the asynchronous context management protocol.
    'async with lock' statement should be used.

    Usage:

        lock = Lock()
        ...
        await lock.acquire()
        try:
            ...
        finally:
            lock.release()

    Context manager usage:

        lock = Lock()
        ...
        async with lock:
             ...

    Lock objects can be tested for locking state:

        if not lock.locked():
           await lock.acquire()
        else:
           # lock is acquired
           ...

    c�"�d|_d|_dS�NF)�_waiters�_lockedrs r�__init__z
Lock.__init__Ns����
�����rc���t�����}|jrdnd}|jr|�dt	|j����}d|dd��d|�d�S�	N�locked�unlocked�
, waiters:�<r	���� [�]>)�super�__repr__r%r$�len�r�res�extra�	__class__s   �rr1z
Lock.__repr__Rsp����g�g��� � �� �L�8���j���=�	=��<�<��D�M�(:�(:�<�<�E�)�3�q��t�9�)�)��)�)�)�)rc��|jS)z Return True if lock is acquired.)r%rs rr)zLock.lockedYs
���|�rc��(K�|js.|j�td�|jD����r	d|_dS|j�tj��|_|������}|j�|��		|�d{V��|j�|��n#|j�|��wxYwn/#tj
$r|js|����wxYwd|_dS)z�Acquire a lock.

        This method blocks until the lock is unlocked, then sets it to
        locked and returns True.
        Nc3�>K�|]}|���V��dSr��	cancelled��.0�ws  r�	<genexpr>zLock.acquire.<locals>.<genexpr>ds*����9�9�a�A�K�K�M�M�9�9�9�9�9�9rT)r%r$�all�collections�deque�	_get_loop�
create_future�append�remover
�CancelledError�_wake_up_first�r�futs  rrzLock.acquire]s-������	�$�-�"7��9�9�4�=�9�9�9�9�9�#8��D�L��4��=� �'�-�/�/�D�M��n�n���,�,�.�.���
���S�!�!�!�
	�
*��	�	�	�	�	�	�	��
�$�$�S�)�)�)�)���
�$�$�S�)�)�)�)����)���(�	�	�	��<�
&��#�#�%�%�%��	����
����ts�B<�!C�<C�C�,Dc�h�|jrd|_|���dStd���)aGRelease a lock.

        When the lock is locked, reset it to unlocked, and return.
        If any other coroutines are blocked waiting for the lock to become
        unlocked, allow exactly one of them to proceed.

        When invoked on an unlocked lock, a RuntimeError is raised.

        There is no return value.
        FzLock is not acquired.N)r%rH�RuntimeErrorrs rrzLock.release}s<���<�	8� �D�L����!�!�!�!�!��6�7�7�7rc���|jsdS	tt|j����}n#t$rYdSwxYw|���s|�d��dSdS)z*Wake up the first waiter if it isn't done.NT)r$�next�iter�
StopIteration�done�
set_resultrIs  rrHzLock._wake_up_first�s����}�	��F�	��t�D�M�*�*�+�+�C�C���	�	�	��F�F�	�����x�x�z�z�	!��N�N�4� � � � � �	!�	!s�!-�
;�;)rrr�__doc__r&r1r)rrrH�
__classcell__�r6s@rrrs��������3�3�j���*�*�*�*�*�������@8�8�8�"
!�
!�
!�
!�
!�
!�
!rrc�@��eZdZdZd�Z�fd�Zd�Zd�Zd�Zd�Z	�xZ
S)ra#Asynchronous equivalent to threading.Event.

    Class implementing event objects. An event manages a flag that can be set
    to true with the set() method and reset to false with the clear() method.
    The wait() method blocks until the flag is true. The flag is initially
    false.
    c�D�tj��|_d|_dSr#)rArBr$�_valuers rr&zEvent.__init__�s��#�)�+�+��
�����rc���t�����}|jrdnd}|jr|�dt	|j����}d|dd��d|�d�S)	N�set�unsetr+r,r	r-r.r/)r0r1rXr$r2r3s   �rr1zEvent.__repr__�sp����g�g��� � ����1���'���=�	=��<�<��D�M�(:�(:�<�<�E�)�3�q��t�9�)�)��)�)�)�)rc��|jS)z5Return True if and only if the internal flag is true.�rXrs r�is_setzEvent.is_set�s
���{�rc��|js:d|_|jD]-}|���s|�d���,dSdS)z�Set the internal flag to true. All coroutines waiting for it to
        become true are awakened. Coroutine that call wait() once the flag is
        true will not block at all.
        TN)rXr$rQrRrIs  rrZz	Event.set�s]��
�{�	)��D�K��}�
)�
)���x�x�z�z�)��N�N�4�(�(�(��	)�	)�
)�
)rc��d|_dS)z�Reset the internal flag to false. Subsequently, coroutines calling
        wait() will block until set() is called to set the internal flag
        to true again.FNr]rs r�clearzEvent.clear�s������rc��"K�|jrdS|������}|j�|��	|�d{V��	|j�|��dS#|j�|��wxYw)z�Block until the internal flag is true.

        If the internal flag is true on entry, return True
        immediately.  Otherwise, block until another coroutine calls
        set() to set the flag to true, then return True.
        TN)rXrCrDr$rErFrIs  r�waitz
Event.wait�s������;�	��4��n�n���,�,�.�.���
���S�!�!�!�	&��I�I�I�I�I�I�I���M� � ��%�%�%�%�%��D�M� � ��%�%�%�%���s�
A2�2B)rrrrSr&r1r^rZrarcrTrUs@rrr�s�������������*�*�*�*�*����
)�
)�
)����&�&�&�&�&�&�&rrc�D��eZdZdZd
d�Z�fd�Zd�Zd�Zdd�Zd	�Z	�xZ
S)raAsynchronous equivalent to threading.Condition.

    This class implements condition variable objects. A condition variable
    allows one or more coroutines to wait until they are notified by another
    coroutine.

    A new Lock object is created and used as the underlying lock.
    Nc��|�t��}||_|j|_|j|_|j|_tj��|_dSr)r�_lockr)rrrArBr$)r�locks  rr&zCondition.__init__�sF���<��6�6�D���
��k����|����|���#�)�+�+��
�
�
rc����t�����}|���rdnd}|jr|�dt	|j����}d|dd��d|�d�Sr()r0r1r)r$r2r3s   �rr1zCondition.__repr__�sv����g�g��� � �� �K�K�M�M�9���z���=�	=��<�<��D�M�(:�(:�<�<�E�)�3�q��t�9�)�)��)�)�)�)rc��K�|���std���|���	|������}|j�|��	|�d{V��	|j�|��d}		|����d{V��n#tj
$rd}YnwxYw�4|rtj
�dS#|j�|��wxYw#d}		|����d{V��n#tj
$rd}YnwxYw�4|rtj
�wxYw)a�Wait until notified.

        If the calling coroutine has not acquired the lock when this
        method is called, a RuntimeError is raised.

        This method releases the underlying lock, and then blocks
        until it is awakened by a notify() or notify_all() call for
        the same condition variable in another coroutine.  Once
        awakened, it re-acquires the lock and returns True.
        zcannot wait on un-acquired lockNFT)r)rLrrCrDr$rErFrr
rG)rrJr;s   rrczCondition.wait�s������{�{�}�}�	B��@�A�A�A�������	0��.�.�"�"�0�0�2�2�C��M� � ��%�%�%�
*��	�	�	�	�	�	�	���
�$�$�S�)�)�)��I�
%�%��,�,�.�.�(�(�(�(�(�(�(���!�0�%�%�%� $�I�I�I�%����	
%��
0� �/�/�
0�
0���
�$�$�S�)�)�)�)������I�
%�%��,�,�.�.�(�(�(�(�(�(�(���!�0�%�%�%� $�I�I�I�%����	
%��
0� �/�/�/�/�/�/sZ�AD�<C&�D�#B>�>C�C�&D�D�E�
D%�$E�%D9�6E�8D9�9Ec��nK�|��}|s&|����d{V��|��}|�&|S)z�Wait until a predicate becomes true.

        The predicate should be a callable which result will be
        interpreted as a boolean value.  The final predicate value is
        the return value.
        N�rc)r�	predicate�results   r�wait_forzCondition.wait_forsW����������	!��)�)�+�+���������Y�[�[�F��	!��
rr	c���|���std���d}|jD]9}||krdS|���s|dz
}|�d���:dS)aBy default, wake up one coroutine waiting on this condition, if any.
        If the calling coroutine has not acquired the lock when this method
        is called, a RuntimeError is raised.

        This method wakes up at most n of the coroutines waiting for the
        condition variable; it is a no-op if no coroutines are waiting.

        Note: an awakened coroutine does not actually return from its
        wait() call until it can reacquire the lock. Since notify() does
        not release the lock, its caller should.
        z!cannot notify on un-acquired lockrr	FN)r)rLr$rQrR)r�n�idxrJs    r�notifyzCondition.notify*s����{�{�}�}�	D��B�C�C�C����=�	&�	&�C��a�x�x�����8�8�:�:�
&��q������u�%�%�%��
	&�	&rc�T�|�t|j����dS)aWake up all threads waiting on this condition. This method acts
        like notify(), but wakes up all waiting threads instead of one. If the
        calling thread has not acquired the lock when this method is called,
        a RuntimeError is raised.
        N)rrr2r$rs r�
notify_allzCondition.notify_allBs&��	
���C��
�&�&�'�'�'�'�'rr�r	)rrrrSr&r1rcrnrrrtrTrUs@rrr�s����������
,�
,�
,�
,�*�*�*�*�*�#0�#0�#0�J���&�&�&�&�0(�(�(�(�(�(�(rrc�B��eZdZdZd	d�Z�fd�Zd�Zd�Zd�Zd�Z	�xZ
S)
raA Semaphore implementation.

    A semaphore manages an internal counter which is decremented by each
    acquire() call and incremented by each release() call. The counter
    can never go below zero; when acquire() finds that it is zero, it blocks,
    waiting until some other thread calls release().

    Semaphores also support the context management protocol.

    The optional argument gives the initial value for the internal
    counter; it defaults to 1. If the value given is less than 0,
    ValueError is raised.
    r	c�L�|dkrtd���d|_||_dS)Nrz$Semaphore initial value must be >= 0)�
ValueErrorr$rX)r�values  rr&zSemaphore.__init__Zs,���1�9�9��C�D�D�D���
�����rc����t�����}|���rdn	d|j��}|jr|�dt|j����}d|dd��d|�d�S)	Nr)zunlocked, value:r+r,r	r-r.r/)r0r1r)rXr$r2r3s   �rr1zSemaphore.__repr__`s�����g�g��� � �� �K�K�M�M�O���/O�$�+�/O�/O���=�	=��<�<��D�M�(:�(:�<�<�E�)�3�q��t�9�)�)��)�)�)�)rc�X�|jdkptd�|jpdD����S)z9Returns True if semaphore cannot be acquired immediately.rc3�@K�|]}|���V��dSrr:r<s  rr?z#Semaphore.locked.<locals>.<genexpr>js-����A�A�a�A�K�K�M�M�!�A�A�A�A�A�Arr )rX�anyr$rs rr)zSemaphore.lockedgs9���{�a��C��A�A�D�M�,?�R�A�A�A�A�A�	Crc��tK�|���s|xjdzc_dS|j�tj��|_|������}|j�|��		|�d{V��|j�|��n#|j�|��wxYwnL#tj
$r:|���s$|xjdz
c_|����wxYw|jdkr|���dS)a5Acquire a semaphore.

        If the internal counter is larger than zero on entry,
        decrement it by one and return True immediately.  If it is
        zero on entry, block, waiting until some other coroutine has
        called release() to make it larger than 0, and then return
        True.
        r	TNr)
r)rXr$rArBrCrDrErFr
rGr;�
_wake_up_nextrIs  rrzSemaphore.acquirels@�����{�{�}�}�	��K�K�1��K�K��4��=� �'�-�/�/�D�M��n�n���,�,�.�.���
���S�!�!�!�
		�
*��	�	�	�	�	�	�	��
�$�$�S�)�)�)�)���
�$�$�S�)�)�)�)����)���(�	�	�	��=�=�?�?�
%����q� ����"�"�$�$�$��		�����;��?�?���� � � ��ts�
B-�C
�-C	�	C
�
A	Dc�N�|xjdz
c_|���dS)z�Release a semaphore, incrementing the internal counter by one.

        When it was zero on entry and another coroutine is waiting for it to
        become larger than zero again, wake up that coroutine.
        r	N)rXrrs rrzSemaphore.release�s,��	
���q�����������rc��|jsdS|jD]>}|���s(|xjdzc_|�d��dS�?dS)z)Wake up the first waiter that isn't done.Nr	T)r$rQrXrRrIs  rrzSemaphore._wake_up_next�sj���}�	��F��=�	�	�C��8�8�:�:�
����q� ������t�$�$�$����
�	�	rru)rrrrSr&r1r)rrrrTrUs@rrrKs��������������*�*�*�*�*�C�C�C�
"�"�"�H���	�	�	�	�	�	�	rrc�.��eZdZdZd�fd�	Z�fd�Z�xZS)rz�A bounded semaphore implementation.

    This raises ValueError in release() if it would increase the value
    above the initial value.
    r	c�X��||_t���|��dSr)�_bound_valuer0r&)rryr6s  �rr&zBoundedSemaphore.__init__�s)���!���
����������rc���|j|jkrtd���t�����dS)Nz(BoundedSemaphore released too many times)rXr�rxr0r)rr6s �rrzBoundedSemaphore.release�s<����;�$�+�+�+��G�H�H�H�
���������rru)rrrrSr&rrTrUs@rrr�s`��������� � � � � � ���������rrc��eZdZdZdZdZdZdS)�
_BarrierState�filling�draining�	resetting�brokenN)rrr�FILLING�DRAINING�	RESETTING�BROKENr rrr�r��s"�������G��H��I�
�F�F�Frr�c���eZdZdZd�Z�fd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zed
���Zed���Zed���Z�xZS)ra	Asyncio equivalent to threading.Barrier

    Implements a Barrier primitive.
    Useful for synchronizing a fixed number of tasks at known synchronization
    points. Tasks block on 'wait()' and are simultaneously awoken once they
    have all made their call.
    c��|dkrtd���t��|_||_tj|_d|_dS)z1Create a barrier, initialised to 'parties' tasks.r	zparties must be > 0rN)rxr�_cond�_partiesr�r��_state�_count)r�partiess  rr&zBarrier.__init__�sA���Q�;�;��2�3�3�3��[�[��
���
�#�+�������rc���t�����}|jj�}|js|d|j�d|j��z
}d|dd��d|�d�S)Nr+�/r,r	r-r.r/)r0r1r�ryr��	n_waitingr�r3s   �rr1zBarrier.__repr__�sp����g�g��� � ���;�$�&���{�	B��A�$�.�A�A�4�<�A�A�A�E�)�3�q��t�9�)�)��)�)�)�)rc��:K�|����d{V��Srrkrs rrzBarrier.__aenter__�s(�����Y�Y�[�[� � � � � � � rc��
K�dSrr )r�argss  rrzBarrier.__aexit__�s�����rc���K�|j4�d{V��|����d{V��	|j}|xjdz
c_|dz|jkr|����d{V��n|����d{V��||xjdzc_|���cddd���d{V��S#|xjdzc_|���wxYw#1�d{V��swxYwYdS)z�Wait for the barrier.

        When the specified number of tasks have started waiting, they are all
        simultaneously awoken.
        Returns an unique and individual index number from 0 to 'parties-1'.
        Nr	)r��_blockr�r��_release�_wait�_exit)r�indexs  rrczBarrier.wait�s������:�	�	�	�	�	�	�	�	��+�+�-�-��������
�������q� ����1�9��
�-�-��-�-�/�/�)�)�)�)�)�)�)�)��*�*�,�,�&�&�&�&�&�&�&�����q� ����
�
����	�	�	�	�	�	�	�	�	�	�	�	�	�	�����q� ����
�
��������	�	�	�	�	�	�	�	�	�	����	�	�	�	�	�	s)�C'�AB>�$C'�>&C$�$C'�'
C1�4C1c���K��j��fd����d{V���jtjurtjd���dS)Nc�B���jtjtjfvSr)r�r�r�r�rs�r�<lambda>z Barrier._block.<locals>.<lambda>�s���D�K��&�
�(?�(��rzBarrier aborted)r�rnr�r�r�r
�BrokenBarrierErrorrs`rr�zBarrier._block�s�������j�!�!�
�
�
�
�
�
�	
�	
�	
�	
�	
�	
�	
��;�-�.�.�.��/�0A�B�B�B�/�.rc��^K�tj|_|j���dSr)r�r�r�r�rtrs rr�zBarrier._releases,����
$�,����
�������rc���K��j��fd����d{V���jtjtjfvrt
jd���dS)Nc�*���jtjuSr)r�r�r�rs�rr�zBarrier._wait.<locals>.<lambda>s���$�+�]�=R�*R�rzAbort or reset of barrier)r�rnr�r�r�r�r
r�rs`rr�z
Barrier._waitsn������j�!�!�"R�"R�"R�"R�S�S�S�S�S�S�S�S�S��;�=�/��1H�I�I�I��/�0K�L�L�L�J�Irc��|jdkrK|jtjtjfvrtj|_|j���dSdS)Nr)r�r�r�r�r�r�r�rtrs rr�z
Barrier._exitsU���;�!����{�}�6�
�8N�O�O�O�+�3����J�!�!�#�#�#�#�#��rc��"K�|j4�d{V��|jdkr%|jtjurtj|_ntj|_|j���ddd���d{V��dS#1�d{V��swxYwYdS)z�Reset the barrier to the initial state.

        Any tasks currently waiting will get the BrokenBarrier exception
        raised.
        Nr)r�r�r�r�r�r�rtrs r�resetz
Barrier.reset#s�����:�	$�	$�	$�	$�	$�	$�	$�	$��{�Q����;�m�&=�=�=�"/�"9�D�K��+�3����J�!�!�#�#�#�	$�	$�	$�	$�	$�	$�	$�	$�	$�	$�	$�	$�	$�	$�	$�	$�	$�	$�	$�	$�	$�	$�	$�	$����	$�	$�	$�	$�	$�	$s�AA>�>
B�Bc���K�|j4�d{V��tj|_|j���ddd���d{V��dS#1�d{V��swxYwYdS)z�Place the barrier into a 'broken' state.

        Useful in case of error.  Any currently waiting tasks and tasks
        attempting to 'wait()' will have BrokenBarrierError raised.
        N)r�r�r�r�rtrs r�abortz
Barrier.abort2s������:�	$�	$�	$�	$�	$�	$�	$�	$�'�.�D�K��J�!�!�#�#�#�	$�	$�	$�	$�	$�	$�	$�	$�	$�	$�	$�	$�	$�	$�	$�	$�	$�	$�	$�	$�	$�	$�	$�	$����	$�	$�	$�	$�	$�	$s�+A�
A�Ac��|jS)z8Return the number of tasks required to trip the barrier.)r�rs rr�zBarrier.parties<s���}�rc�:�|jtjur|jSdS)z<Return the number of tasks currently waiting at the barrier.r)r�r�r�r�rs rr�zBarrier.n_waitingAs!���;�-�/�/�/��;���qrc�(�|jtjuS)z0Return True if the barrier is in a broken state.)r�r�r�rs rr�zBarrier.brokenHs���{�m�2�2�2r)rrrrSr&r1rrrcr�r�r�r�r�r��propertyr�r�r�rTrUs@rrr�s/���������	�	�	�*�*�*�*�*�!�!�!�

�
�
����.C�C�C�  � � �	M�	M�	M�$�$�$�
$�
$�
$�$�$�$�����X������X���3�3��X�3�3�3�3�3rr)rS�__all__rA�enum�r
rrr�_LoopBoundMixinrrrrr�Enumr�rr rr�<module>r�s���!�!�*������������������������������������C!�C!�C!�C!�C!���!7�C!�C!�C!�L:&�:&�:&�:&�:&�F�"�:&�:&�:&�zm(�m(�m(�m(�m(�$�f�&<�m(�m(�m(�`W�W�W�W�W�$�f�&<�W�W�W�t�����y����$�����D�I����M3�M3�M3�M3�M3�f�$�M3�M3�M3�M3�M3r

Hacked By AnonymousFox1.0, Coded By AnonymousFox