ok

Mini Shell

Direktori : /proc/thread-self/root/opt/alt/python37/lib64/python3.7/asyncio/__pycache__/
Upload File :
Current File : //proc/thread-self/root/opt/alt/python37/lib64/python3.7/asyncio/__pycache__/locks.cpython-37.pyc

B

� f)>�@s�dZdZddlZddlZddlmZddlmZddlmZGdd	�d	�Z	Gd
d�d�Z
Gdd
�d
e
�ZGdd�d�ZGdd�de
�Z
Gdd�de
�ZGdd�de�ZdS)zSynchronization primitives.)�Lock�Event�	Condition�	Semaphore�BoundedSemaphore�N�)�events)�futures)�	coroutinec@s(eZdZdZdd�Zdd�Zdd�ZdS)	�_ContextManagera\Context manager.

    This enables the following idiom for acquiring and releasing a
    lock around a block:

        with (yield from lock):
            <block>

    while failing loudly when accidentally using:

        with lock:
            <block>

    Deprecated, use 'async with' statement:
        async with lock:
            <block>
    cCs
||_dS)N)�_lock)�self�lock�r�2/opt/alt/python37/lib64/python3.7/asyncio/locks.py�__init__ sz_ContextManager.__init__cCsdS)Nr)r
rrr�	__enter__#sz_ContextManager.__enter__cGsz|j��Wdd|_XdS)N)r�release)r
�argsrrr�__exit__(sz_ContextManager.__exit__N)�__name__�
__module__�__qualname__�__doc__rrrrrrrr
src@sHeZdZdd�Zdd�Zedd��Zdd�Zd	d
�Zdd�Z	d
d�Z
dS)�_ContextManagerMixincCstd��dS)Nz9"yield from" should be used as context manager expression)�RuntimeError)r
rrrr0sz_ContextManagerMixin.__enter__cGsdS)Nr)r
rrrrr4sz_ContextManagerMixin.__exit__ccs&tjdtdd�|��EdHt|�S)NzD'with (yield from lock)' is deprecated use 'async with lock' instead�)�
stacklevel)�warnings�warn�DeprecationWarning�acquirer)r
rrr�__iter__9s
z_ContextManagerMixin.__iter__c�s|��IdHt|�S)N)r!r)r
rrrZ
__acquire_ctxPsz"_ContextManagerMixin.__acquire_ctxcCstjdtdd�|����S)Nz='with await lock' is deprecated use 'async with lock' insteadr)r)rrr �!_ContextManagerMixin__acquire_ctx�	__await__)r
rrrr$Ts
z_ContextManagerMixin.__await__c�s|��IdHdS)N)r!)r
rrr�
__aenter__[sz_ContextManagerMixin.__aenter__c�s|��dS)N)r)r
�exc_type�exc�tbrrr�	__aexit__asz_ContextManagerMixin.__aexit__N)rrrrrr
r"r#r$r%r)rrrrr/srcsNeZdZdZdd�dd�Z�fdd�Zdd	�Zd
d�Zdd
�Zdd�Z	�Z
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
           ...

    N)�loopcCs.t��|_d|_|dk	r ||_n
t��|_dS)NF)�collections�deque�_waiters�_locked�_loopr�get_event_loop)r
r*rrrr�s

z
Lock.__init__csLt���}|jrdnd}|jr2|�dt|j���}d|dd��d|�d�S)	N�locked�unlockedz
, waiters:�<r���z [z]>)�super�__repr__r.r-�len)r
�res�extra)�	__class__rrr6�s

z
Lock.__repr__cCs|jS)z Return True if lock is acquired.)r.)r
rrrr1�szLock.lockedc	�s�|js$tdd�|jD��r$d|_dS|j��}|j�|�y"z|IdHWd|j�|�XWn&tjk
r�|js||�	��YnXd|_dS)z�Acquire a lock.

        This method blocks until the lock is unlocked, then sets it to
        locked and returns True.
        css|]}|��VqdS)N)�	cancelled)�.0�wrrr�	<genexpr>�szLock.acquire.<locals>.<genexpr>TN)
r.�allr-r/�
create_future�append�remover	�CancelledError�_wake_up_first)r
�futrrrr!�s
zLock.acquirecCs"|jrd|_|��ntd��dS)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.rDr)r
rrrr�s
zLock.releasecCs>ytt|j��}Wntk
r&dSX|��s:|�d�dS)z*Wake up the first waiter if it isn't done.NT)�next�iterr-�
StopIteration�done�
set_result)r
rErrrrD�szLock._wake_up_first)rrrrrr6r1r!rrD�
__classcell__rr)r:rres4rcsNeZdZdZdd�dd�Z�fdd�Zdd	�Zd
d�Zdd
�Zdd�Z	�Z
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.
    N)r*cCs.t��|_d|_|dk	r ||_n
t��|_dS)NF)r+r,r-�_valuer/rr0)r
r*rrrr�s

zEvent.__init__csLt���}|jrdnd}|jr2|�dt|j���}d|dd��d|�d�S)	N�setZunsetz
, waiters:r3rr4z [z]>)r5r6rLr-r7)r
r8r9)r:rrr6�s

zEvent.__repr__cCs|jS)z5Return True if and only if the internal flag is true.)rL)r
rrr�is_setszEvent.is_setcCs2|js.d|_x |jD]}|��s|�d�qWdS)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)rLr-rIrJ)r
rErrrrMs
z	Event.setcCs
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.FN)rL)r
rrr�clearszEvent.clearc	�sB|jr
dS|j��}|j�|�z|IdHdS|j�|�XdS)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)rLr/r@r-rArB)r
rErrr�waits

z
Event.wait)rrrrrr6rNrMrOrPrKrr)r:rr�srcsReZdZdZddd�dd�Z�fdd�Zdd	�Zd
d�Zdd
d�Zdd�Z	�Z
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.
    N)r*cCsp|dk	r||_n
t��|_|dkr0t|jd�}n|j|jk	rDtd��||_|j|_|j|_|j|_t	�
�|_dS)N)r*z"loop argument must agree with lock)r/rr0r�
ValueErrorrr1r!rr+r,r-)r
rr*rrrr5s
zCondition.__init__csNt���}|��rdnd}|jr4|�dt|j���}d|dd��d|�d�S)	Nr1r2z
, waiters:r3rr4z [z]>)r5r6r1r-r7)r
r8r9)r:rrr6Hs

zCondition.__repr__c�s�|��std��|��z8|j��}|j�|�z|IdHdS|j�|�XWdd}x4y|��IdHPWqXt	j
k
r�d}YqXXqXW|r�t	j
�XdS)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 lockNTF)r1rrr/r@r-rArBr!r	rC)r
rEr;rrrrPOs&

zCondition.waitc�s(|�}x|s"|��IdH|�}qW|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)rP)r
Z	predicate�resultrrr�wait_forts

zCondition.wait_forrcCsL|��std��d}x2|jD](}||kr*P|��s|d7}|�d�qWdS)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 lockrrFN)r1rr-rIrJ)r
�n�idxrErrr�notify�szCondition.notifycCs|�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)rVr7r-)r
rrr�
notify_all�szCondition.notify_all)N)r)rrrrrr6rPrSrVrWrKrr)r:rr+s%
rcsPeZdZdZddd�dd�Z�fdd�Zd	d
�Zdd�Zd
d�Zdd�Z	�Z
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.
    rN)r*cCs>|dkrtd��||_t��|_|dk	r0||_n
t��|_dS)Nrz$Semaphore initial value must be >= 0)rQrLr+r,r-r/rr0)r
�valuer*rrrr�s
zSemaphore.__init__csVt���}|��rdn
d|j��}|jr<|�dt|j���}d|dd��d|�d�S)	Nr1zunlocked, value:z
, waiters:r3rr4z [z]>)r5r6r1rLr-r7)r
r8r9)r:rrr6�s

zSemaphore.__repr__cCs0x*|jr*|j��}|��s|�d�dSqWdS)N)r-�popleftrIrJ)r
Zwaiterrrr�
_wake_up_next�s


zSemaphore._wake_up_nextcCs
|jdkS)z:Returns True if semaphore can not be acquired immediately.r)rL)r
rrrr1�szSemaphore.lockedc�sxxd|jdkrd|j��}|j�|�y|IdHWq|��|jdkrZ|��sZ|���YqXqW|jd8_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.
        rNrT)rLr/r@r-rAZcancelr;rZ)r
rErrrr!�s	
zSemaphore.acquirecCs|jd7_|��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.
        rN)rLrZ)r
rrrr�szSemaphore.release)r)rrrrrr6rZr1r!rrKrr)r:rr�s

rcs4eZdZdZd	dd��fdd�Z�fdd�Z�ZS)
rz�A bounded semaphore implementation.

    This raises ValueError in release() if it would increase the value
    above the initial value.
    rN)r*cs||_t�j||d�dS)N)r*)�_bound_valuer5r)r
rXr*)r:rrr�szBoundedSemaphore.__init__cs"|j|jkrtd��t���dS)Nz(BoundedSemaphore released too many times)rLr[rQr5r)r
)r:rrr�szBoundedSemaphore.release)r)rrrrrrrKrr)r:rr�sr)r�__all__r+r�rr	Z
coroutinesr
rrrrrrrrrrr�<module>s"6AwK

Zerion Mini Shell 1.0