403Webshell
Server IP : 54.37.205.81  /  Your IP : 216.73.216.76
Web Server : nginx/1.22.1
System : Linux vps-249481fa 6.1.0-50-cloud-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.176-1 (2026-07-02) x86_64
User : debian ( 1000)
PHP Version : 8.2.32
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /lib/python3/dist-packages/tornado/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /lib/python3/dist-packages/tornado/__pycache__/locks.cpython-311.pyc
�

��b�C��L�ddlZddlZddlZddlmZmZddlmZmZddl	m
Z
mZmZm
Z
mZddl	Z	e	jrddl	mZmZgd�ZGd�de��ZGd	�d
e��ZGd�de��ZGd
�de��ZGd�de��ZGd�de��ZGd�de��ZdS)�N)�gen�ioloop)�Future�"future_set_result_unless_cancelled)�Union�Optional�Type�Any�	Awaitable)�Deque�Set)�	Condition�Event�	Semaphore�BoundedSemaphore�Lockc�"�eZdZdZdd�Zdd�ZdS)�_TimeoutGarbageCollectorz�Base class for objects that periodically clean up timed-out waiters.

    Avoids memory leak in a common pattern like:

        while True:
            yield condition.wait(short_timeout)
            print('looping....')
    �returnNc�D�tj��|_d|_dS)Nr)�collections�deque�_waiters�	_timeouts��selfs �//usr/lib/python3/dist-packages/tornado/locks.py�__init__z!_TimeoutGarbageCollector.__init__)s��#�)�+�+��
������c��|xjdz
c_|jdkr1d|_tjd�|jD����|_dSdS)N��drc3�BK�|]}|����|V��dS�N)�done)�.0�ws  r�	<genexpr>z<_TimeoutGarbageCollector._garbage_collect.<locals>.<genexpr>2s/����-W�-W�A�a�f�f�h�h�-W�a�-W�-W�-W�-W�-W�-Wr)rrrrrs r�_garbage_collectz)_TimeoutGarbageCollector._garbage_collect-sU�����!�����>�C����D�N�'�-�-W�-W���-W�-W�-W�W�W�D�M�M�M� �r�rN)�__name__�
__module__�__qualname__�__doc__rr)�rrrrsL������������X�X�X�X�X�Xrrc�~�eZdZdZdefd�Z	ddeeee	j
fdeefd�Z
ddeddfd	�Zd
d
�ZdS)ra�A condition allows one or more coroutines to wait until notified.

    Like a standard `threading.Condition`, but does not need an underlying lock
    that is acquired and released.

    With a `Condition`, coroutines can wait to be notified by other coroutines:

    .. testcode::

        import asyncio
        from tornado import gen
        from tornado.locks import Condition

        condition = Condition()

        async def waiter():
            print("I'll wait right here")
            await condition.wait()
            print("I'm done waiting")

        async def notifier():
            print("About to notify")
            condition.notify()
            print("Done notifying")

        async def runner():
            # Wait for waiter() and notifier() in parallel
            await gen.multi([waiter(), notifier()])

        asyncio.run(runner())

    .. testoutput::

        I'll wait right here
        About to notify
        Done notifying
        I'm done waiting

    `wait` takes an optional ``timeout`` argument, which is either an absolute
    timestamp::

        io_loop = IOLoop.current()

        # Wait up to 1 second for a notification.
        await condition.wait(timeout=io_loop.time() + 1)

    ...or a `datetime.timedelta` for a timeout relative to the current time::

        # Wait up to 1 second.
        await condition.wait(timeout=datetime.timedelta(seconds=1))

    The method returns False if there's no notification before the deadline.

    .. versionchanged:: 5.0
       Previously, waiters could be notified synchronously from within
       `notify`. Now, the notification will always be received on the
       next iteration of the `.IOLoop`.
    rc�l�d|jj��}|jr|dt|j��zz
}|dzS)N�<z waiters[%s]�>)�	__class__r+r�len)r�results  r�__repr__zCondition.__repr__qsA����.�1�1�3���=�	:��n�s�4�=�'9�'9�9�9�F���|�rN�timeoutc�
�����t����j����|rTd��fd�}tj������||�������fd����S)z�Wait for `.notify`.

        Returns a `.Future` that resolves ``True`` if the condition is notified,
        or ``False`` after a timeout.
        rNc�x������st�d������dS�NF)r%rr)�r�waiters��r�
on_timeoutz"Condition.wait.<locals>.on_timeout�s<����{�{�}�}�F�6�v�u�E�E�E��%�%�'�'�'�'�'rc�.�������Sr$��remove_timeout��_�io_loop�timeout_handles ��r�<lambda>z Condition.wait.<locals>.<lambda>�s���w�/E�/E�n�/U�/U�rr*)rr�appendr�IOLoop�current�add_timeout�add_done_callback�rr8r>rDrEr=s`  @@@r�waitzCondition.waitws������������
���V�$�$�$��		W�
(�
(�
(�
(�
(�
(�
(�
�m�+�+�-�-�G�$�0�0��*�E�E�N��$�$�%U�%U�%U�%U�%U�V�V�V��
rr!�nc���g}|rW|jrP|j���}|���s|dz}|�|��|r|j�P|D]}t	|d���dS)zWake ``n`` waiters.r!TN)r�popleftr%rGr)rrN�waitersr=s    r�notifyzCondition.notify�s������	'�D�M�	'��]�*�*�,�,�F��;�;�=�=�
'��Q������v�&�&�&�	�	'�D�M�	'��	=�	=�F�.�v�t�<�<�<�<�	=�	=rc�T�|�t|j����dS)zWake all waiters.N)rRr5rrs r�
notify_allzCondition.notify_all�s$�����C��
�&�&�'�'�'�'�'rr$�r!r*)r+r,r-r.�strr7rr�float�datetime�	timedeltar�boolrM�intrRrTr/rrrr5s�������9�9�v�#�����EI�����e�X�-?�&?� @�A��	�4������,
=�
=��
=�D�
=�
=�
=�
=�(�(�(�(�(�(rrc��eZdZdZdd�Zdefd�Zdefd�Zdd�Z	dd�Z
	dd	eee
ejfdedfd
�ZdS)
ra�An event blocks coroutines until its internal flag is set to True.

    Similar to `threading.Event`.

    A coroutine can wait for an event to be set. Once it is set, calls to
    ``yield event.wait()`` will not block unless the event has been cleared:

    .. testcode::

        import asyncio
        from tornado import gen
        from tornado.locks import Event

        event = Event()

        async def waiter():
            print("Waiting for event")
            await event.wait()
            print("Not waiting this time")
            await event.wait()
            print("Done")

        async def setter():
            print("About to set the event")
            event.set()

        async def runner():
            await gen.multi([waiter(), setter()])

        asyncio.run(runner())

    .. testoutput::

        Waiting for event
        About to set the event
        Not waiting this time
        Done
    rNc�:�d|_t��|_dSr;)�_value�setrrs rrzEvent.__init__�s���������
�
�
rc�T�d|jj�d|���rdnd�d�S)Nr2� r_�clearr3)r4r+�is_setrs rr7zEvent.__repr__�s6����N�#�#�#��[�[�]�]�/�E�E��/�/�
�	
rc��|jS)z-Return ``True`` if the internal flag is true.�r^rs rrczEvent.is_set�s
���{�rc��|js:d|_|jD]-}|���s|�d���,dSdS)z�Set the internal flag to ``True``. All waiters are awakened.

        Calling `.wait` once the flag is set will not block.
        TN)r^rr%�
set_result)r�futs  rr_z	Event.set�s]��
�{�	)��D�K��}�
)�
)���x�x�z�z�)��N�N�4�(�(�(��	)�	)�
)�
)rc��d|_dS)zkReset the internal flag to ``False``.

        Calls to `.wait` will block until `.set` is called.
        FNrers rrbzEvent.clear�s��
����rr8c�(���t����jr��d���S�j�������fd���|��St
j|���}|��fd���|S)z�Block until the internal flag is true.

        Returns an awaitable, which raises `tornado.util.TimeoutError` after a
        timeout.
        Nc�8���j�|��Sr$)r�remove)rhrs �rrFzEvent.wait.<locals>.<lambda>�s���$�-�*>�*>�s�*C�*C�rc�X������s����ndSr$)r%�cancel)�tfrhs �rrFzEvent.wait.<locals>.<lambda>�s ���s�x�x�z�z�C�3�:�:�<�<�<�t�r)rr^rgr�addrKr�with_timeout)rr8�timeout_futrhs`  @rrMz
Event.wait�s������h�h���;�	��N�N�4� � � ��J��
���#�������C�C�C�C�D�D�D��?��J��*�7�C�8�8�K�
�)�)�C�C�C�C�
�
�
��rr*r$)r+r,r-r.rrVr7rZrcr_rbrrrWrXrYrrMr/rrrr�s�������%�%�N����
�#�
�
�
�
�������
)�
)�
)�
)�����EI�����e�X�-?�&?� @�A��	�4�������rrc�d�eZdZdZdeddfd�Zdd�Zddd	eed
ee	j
ddfd�ZdS)
�_ReleasingContextManagerz�Releases a Lock or Semaphore at the end of a "with" statement.

    with (yield semaphore.acquire()):
        pass

    # Now semaphore.release() has been called.
    �objrNc��||_dSr$)�_obj)rrus  rrz!_ReleasingContextManager.__init__s
����	�	�	rc��dSr$r/rs r�	__enter__z"_ReleasingContextManager.__enter__s���r�exc_type�Optional[Type[BaseException]]�exc_val�exc_tbc�8�|j���dSr$)rw�release)rrzr|r}s    r�__exit__z!_ReleasingContextManager.__exit__s��	
�	�������rr*)r+r,r-r.r
rryr�
BaseException�types�
TracebackTyper�r/rrrtrts����������C��D�����
�
�
�
��1���-�(����,�-�	�

������rrtc���eZdZdZddeddf�fd�
Zdef�fd�Zdd�Z	dd	e	e
eej
fdeefd
�Zdd�Zdd
de	ede	ejddfd�Zdd�Zdd
de	ede	ejddfd�Z�xZS)ra�A lock that can be acquired a fixed number of times before blocking.

    A Semaphore manages a counter representing the number of `.release` calls
    minus the number of `.acquire` calls, plus an initial value. The `.acquire`
    method blocks if necessary until it can return without making the counter
    negative.

    Semaphores limit access to a shared resource. To allow access for two
    workers at a time:

    .. testsetup:: semaphore

       from collections import deque

       from tornado import gen
       from tornado.ioloop import IOLoop
       from tornado.concurrent import Future

       inited = False

       async def simulator(futures):
           for f in futures:
               # simulate the asynchronous passage of time
               await gen.sleep(0)
               await gen.sleep(0)
               f.set_result(None)

       def use_some_resource():
           global inited
           global futures_q
           if not inited:
               inited = True
               # Ensure reliable doctest output: resolve Futures one at a time.
               futures_q = deque([Future() for _ in range(3)])
               IOLoop.current().add_callback(simulator, list(futures_q))

           return futures_q.popleft()

    .. testcode:: semaphore

        import asyncio
        from tornado import gen
        from tornado.locks import Semaphore

        sem = Semaphore(2)

        async def worker(worker_id):
            await sem.acquire()
            try:
                print("Worker %d is working" % worker_id)
                await use_some_resource()
            finally:
                print("Worker %d is done" % worker_id)
                sem.release()

        async def runner():
            # Join all workers.
            await gen.multi([worker(i) for i in range(3)])

        asyncio.run(runner())

    .. testoutput:: semaphore

        Worker 0 is working
        Worker 1 is working
        Worker 0 is done
        Worker 2 is working
        Worker 1 is done
        Worker 2 is done

    Workers 0 and 1 are allowed to run concurrently, but worker 2 waits until
    the semaphore has been released once, by worker 0.

    The semaphore can be used as an async context manager::

        async def worker(worker_id):
            async with sem:
                print("Worker %d is working" % worker_id)
                await use_some_resource()

            # Now the semaphore has been released.
            print("Worker %d is done" % worker_id)

    For compatibility with older versions of Python, `.acquire` is a
    context manager, so ``worker`` could also be written as::

        @gen.coroutine
        def worker(worker_id):
            with (yield sem.acquire()):
                print("Worker %d is working" % worker_id)
                yield use_some_resource()

            # Now the semaphore has been released.
            print("Worker %d is done" % worker_id)

    .. versionchanged:: 4.3
       Added ``async with`` support in Python 3.5.

    r!�valuerNc���t�����|dkrtd���||_dS)Nrz$semaphore initial value must be >= 0)�superr�
ValueErrorr^�rr�r4s  �rrzSemaphore.__init__s<���
���������1�9�9��C�D�D�D�����rc�,��t�����}|jdkrdnd�|j��}|jr(d�|t|j����}d�|dd�|��S)Nr�lockedzunlocked,value:{0}z{0},waiters:{1}z<{0} [{1}]>r!���)r�r7r^�formatrr5)r�res�extrar4s   �rr7zSemaphore.__repr__�s�����g�g��� � ����q�(�(�H�H�.B�.I�.I�$�+�.V�.V�	��=�	H�%�,�,�U�C��
�4F�4F�G�G�E��#�#�C��"��I�u�5�5�5rc��|xjdz
c_|jrj|j���}|���s4|xjdzc_|�t|����dS|j�hdSdS)�*Increment the counter and wake one waiter.r!N)r^rrPr%rgrtr<s  rrzSemaphore.release�s������q�����m�	��]�*�*�,�,�F��;�;�=�=�

����q� ����!�!�":�4�"@�"@�A�A�A����m�	�	�	�	�	rr8c������t����jdkr3�xjdzc_��t�����np�j����|rTd��fd�}tj������	||�����
��fd����S)z�Decrement the counter. Returns an awaitable.

        Block if the counter is zero and wait for a `.release`. The awaitable
        raises `.TimeoutError` after the deadline.
        rr!rNc�������s&��tj��������dSr$)r%�
set_exceptionr�TimeoutErrorr)r<s��rr>z%Semaphore.acquire.<locals>.on_timeout�sI���!�;�;�=�=�A��,�,�S�-=�-?�-?�@�@�@��)�)�+�+�+�+�+rc�.�������Sr$r@rBs ��rrFz#Semaphore.acquire.<locals>.<lambda>�s���g�4�4�^�D�D�rr*)rr^rgrtrrGrrHrIrJrKrLs`  @@@r�acquirezSemaphore.acquire�s������������;��?�?��K�K�1��K�K����6�t�<�<�=�=�=�=��M� � ��(�(�(��
�,�,�,�,�,�,�,�
!�-�/�/�1�1��!(�!4�!4�W�j�!I�!I���(�(�D�D�D�D�D�����
rc� �td���)Nz0Use 'async with' instead of 'with' for Semaphore��RuntimeErrorrs rryzSemaphore.__enter__�s���M�N�N�Nr�typr{�	tracebackc�.�|���dSr$�ry)rr�r�r�s    rr�zSemaphore.__exit__����	
�������rc��>K�|����d{V��dSr$�r�rs r�
__aenter__zSemaphore.__aenter__��,�����l�l�n�n���������r�tbc��2K�|���dSr$�r�rr�r�r�s    r�	__aexit__zSemaphore.__aexit__������	
�������rrUr*r$)r+r,r-r.r[rrVr7rrrrWrXrYrrtr�ryr�r�r�r�r�r��
__classcell__�r4s@rrrs��������b�b�H��c��$�������6�#�6�6�6�6�6�6�����$EI�����e�X�-?�&?� @�A��	�+�	,�����8O�O�O�O��
,���
�&���E�/�0�	�

����������
,���
�&��
�U�(�)�	�

��������rrc�:��eZdZdZddeddf�fd�
Zd	�fd�Z�xZS)
ra:A semaphore that prevents release() being called too many times.

    If `.release` would increment the semaphore's value past the initial
    value, it raises `ValueError`. Semaphores are mostly used to guard
    resources with limited capacity, so a semaphore released too many times
    is a sign of a bug.
    r!r�rNc�Z��t���|���||_dS)N�r�)r�r�_initial_valuer�s  �rrzBoundedSemaphore.__init__�s,���
�����u��%�%�%�#����rc���|j|jkrtd���t�����dS)r�z!Semaphore released too many timesN)r^r�r�r�r)rr4s �rrzBoundedSemaphore.release�s<����;�$�-�-�-��@�A�A�A�
���������rrUr*)r+r,r-r.r[rrr�r�s@rrr�sx���������$�$�c�$�$�$�$�$�$�$�$����������rrc��eZdZdZdd�Zdefd�Z	ddeee	e
jfdee
fd�Zdd�Zdd	�Zd
ddeed
eejddfd�Zdd�Zd
ddeed
eejddfd�ZdS)ra�A lock for coroutines.

    A Lock begins unlocked, and `acquire` locks it immediately. While it is
    locked, a coroutine that yields `acquire` waits until another coroutine
    calls `release`.

    Releasing an unlocked lock raises `RuntimeError`.

    A Lock can be used as an async context manager with the ``async
    with`` statement:

    >>> from tornado import locks
    >>> lock = locks.Lock()
    >>>
    >>> async def f():
    ...    async with lock:
    ...        # Do something holding the lock.
    ...        pass
    ...
    ...    # Now the lock is released.

    For compatibility with older versions of Python, the `.acquire`
    method asynchronously returns a regular context manager:

    >>> async def f2():
    ...    with (yield lock.acquire()):
    ...        # Do something holding the lock.
    ...        pass
    ...
    ...    # Now the lock is released.

    .. versionchanged:: 4.3
       Added ``async with`` support in Python 3.5.

    rNc�0�td���|_dS)Nr!r�)r�_blockrs rrz
Lock.__init__s��&�Q�/�/�/����rc�2�d|jj�d|j�d�S)Nr2z _block=r3)r4r+r�rs rr7z
Lock.__repr__s ���#'�>�#:�#:�#:�D�K�K�K�H�Hrr8c�6�|j�|��S)z�Attempt to lock. Returns an awaitable.

        Returns an awaitable, which raises `tornado.util.TimeoutError` after a
        timeout.
        )r�r�)rr8s  rr�zLock.acquires���{�"�"�7�+�+�+rc�t�	|j���dS#t$rtd���wxYw)z�Unlock.

        The first coroutine in line waiting for `acquire` gets the lock.

        If not locked, raise a `RuntimeError`.
        zrelease unlocked lockN)r�rr�r�rs rrzLock.releasesK��	8��K���!�!�!�!�!���	8�	8�	8��6�7�7�7�	8���s��7c� �td���)Nz+Use `async with` instead of `with` for Lockr�rs rryzLock.__enter__(s���H�I�I�Irr�r{r�r�c�.�|���dSr$r�r�s    rr�z
Lock.__exit__+r�rc��>K�|����d{V��dSr$r�rs rr�zLock.__aenter__3r�rc��2K�|���dSr$r�r�s    rr�zLock.__aexit__6r�rr*r$)r+r,r-r.rrVr7rrrWrXrYrrtr�rryr�r�r�r�r�r�r/rrrr�si������"�"�H0�0�0�0�I�#�I�I�I�I�EI�,�,���e�X�-?�&?� @�A�,�	�+�	,�,�,�,�,�
8�
8�
8�
8�J�J�J�J��
,���
�&��
�U�(�)�	�

����������
,���
�&��
�U�(�)�	�

������rr)rrXr��tornadorr�tornado.concurrentrr�typingrrr	r
r�
TYPE_CHECKINGrr
�__all__�objectrrrrtrrrr/rr�<module>r�s����������������������I�I�I�I�I�I�I�I�8�8�8�8�8�8�8�8�8�8�8�8�8�8�
�
�
�
�	��"�!�!�!�!�!�!�!�!�
I�
I�
I��X�X�X�X�X�v�X�X�X�,f(�f(�f(�f(�f(�(�f(�f(�f(�Ra�a�a�a�a�F�a�a�a�H�����v����0v�v�v�v�v�(�v�v�v�r�����y����(U�U�U�U�U�6�U�U�U�U�Ur

Youez - 2016 - github.com/yon3zu
LinuXploit