BYPASS SHELL BY ./RAZORGANZ
Server: nginx/1.20.1
System: Linux iZdzfnv9mwfppeZ 5.10.134-19.2.al8.x86_64 #1 SMP Wed Oct 29 22:47:09 CST 2025 x86_64
User: apache (48)
PHP: 8.2.30
Disabled: NONE
Upload Files
File: //lib64/python3.6/site-packages/tornado/__pycache__/queues.cpython-36.opt-1.pyc
3

	��f�/�@s&dZddlZddlZddlZddlmZmZddlmZm	Z	ddl
mZddlm
Z
mZmZmZddlZejr�ddlmZmZmZmZed�Zd	d
ddd
gZGdd
�d
e�ZGdd�de�Zee
deejfdd�dd�ZGdd�dee�ZGdd	�d	ee�ZGdd
�d
e�Z Gdd�de�Z!dS)a�Asynchronous queues for coroutines. These classes are very similar
to those provided in the standard library's `asyncio package
<https://docs.python.org/3/library/asyncio-queue.html>`_.

.. warning::

   Unlike the standard library's `queue` module, the classes defined here
   are *not* thread-safe. To use these queues from another thread,
   use `.IOLoop.add_callback` to transfer control to the `.IOLoop` thread
   before calling any queue methods.

�N)�gen�ioloop)�Future�"future_set_result_unless_cancelled)�Event)�Union�TypeVar�Generic�	Awaitable)�Deque�Tuple�List�Any�_T�Queue�
PriorityQueue�	LifoQueue�	QueueFull�
QueueEmptyc@seZdZdZdS)rz:Raised by `.Queue.get_nowait` when the queue has no items.N)�__name__�
__module__�__qualname__�__doc__�rr�/usr/lib64/python3.6/queues.pyr/sc@seZdZdZdS)rzBRaised by `.Queue.put_nowait` when a queue is at its maximum size.N)rrrrrrrrr5s)�future�timeout�returncsD|r@dd��fdd�}tjj���j||���j��fdd��dS)N)rcs�j�s�jtj��dS)N)�doneZ
set_exceptionr�TimeoutErrorr)rrr�
on_timeout@sz _set_timeout.<locals>.on_timeoutcs
�j��S)N)Zremove_timeout)�_)�io_loop�timeout_handlerr�<lambda>Fsz_set_timeout.<locals>.<lambda>)rZIOLoopZcurrentZadd_timeoutZadd_done_callback)rrr r)rr"r#r�_set_timeout;s

r%c@s.eZdZddd�dd�Zeed�dd�ZdS)	�_QueueIteratorz	Queue[_T]N)�qrcCs
||_dS)N)r')�selfr'rrr�__init__Jsz_QueueIterator.__init__)rcCs
|jj�S)N)r'�get)r(rrr�	__anext__Msz_QueueIterator.__anext__)rrrr)r
rr+rrrrr&Isr&c@sreZdZdZdZd2edd�dd�Zeed�dd	��Zed�d
d�Z	e
d�dd
�Ze
d�dd�Zd3e
eeejfdd�dd�Ze
dd�dd�Zd4eeejfee
d�dd�Ze
d�dd�Zdd�dd�Zd5eeejfedd�dd�Zee
d�d d!�Zdd�d"d#�Ze
d�d$d%�Ze
dd�d&d'�Ze
dd�d(d)�Zdd�d*d+�Ze d�d,d-�Z!e d�d.d/�Z"e d�d0d1�Z#dS)6ra�Coordinate producer and consumer coroutines.

    If maxsize is 0 (the default) the queue size is unbounded.

    .. testcode::

        from tornado import gen
        from tornado.ioloop import IOLoop
        from tornado.queues import Queue

        q = Queue(maxsize=2)

        async def consumer():
            async for item in q:
                try:
                    print('Doing work on %s' % item)
                    await gen.sleep(0.01)
                finally:
                    q.task_done()

        async def producer():
            for item in range(5):
                await q.put(item)
                print('Put %s' % item)

        async def main():
            # Start consumer without waiting (since it never finishes).
            IOLoop.current().spawn_callback(consumer)
            await producer()     # Wait for producer to put all tasks.
            await q.join()       # Wait for consumer to finish all tasks.
            print('Done')

        IOLoop.current().run_sync(main)

    .. testoutput::

        Put 0
        Put 1
        Doing work on 0
        Put 2
        Doing work on 1
        Put 3
        Doing work on 2
        Put 4
        Doing work on 3
        Doing work on 4
        Done


    In versions of Python without native coroutines (before 3.5),
    ``consumer()`` could be written as::

        @gen.coroutine
        def consumer():
            while True:
                item = yield q.get()
                try:
                    print('Doing work on %s' % item)
                    yield gen.sleep(0.01)
                finally:
                    q.task_done()

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

    Nr)�maxsizercCsb|dkrtd��|dkr td��||_|j�tjg�|_tjg�|_d|_t	�|_
|j
j�dS)Nzmaxsize can't be Nonerzmaxsize can't be negative)�	TypeError�
ValueError�_maxsize�_init�collections�deque�_getters�_putters�_unfinished_tasksr�	_finished�set)r(r,rrrr)�szQueue.__init__)rcCs|jS)z%Number of items allowed in the queue.)r/)r(rrrr,�sz
Queue.maxsizecCs
t|j�S)zNumber of items in the queue.)�len�_queue)r(rrr�qsize�szQueue.qsizecCs|jS)N)r9)r(rrr�empty�szQueue.emptycCs |jdkrdS|j�|jkSdS)NrF)r,r:)r(rrr�full�s
z
Queue.fullzFuture[None])�itemrrcCsRt�}y|j|�Wn.tk
rB|jj||f�t||�YnX|jd�|S)a�Put an item into the queue, perhaps waiting until there is room.

        Returns a Future, which raises `tornado.util.TimeoutError` after a
        timeout.

        ``timeout`` may be a number denoting a time (on the same
        scale as `tornado.ioloop.IOLoop.time`, normally `time.time`), or a
        `datetime.timedelta` object for a deadline relative to the
        current time.
        N)r�
put_nowaitrr4�appendr%�
set_result)r(r=rrrrr�put�s

z	Queue.put)r=rcCsN|j�|jr2|jj�}|j|�t||j��n|j�r@t�n
|j|�dS)z{Put an item into the queue without blocking.

        If no free slot is immediately available, raise `QueueFull`.
        N)�_consume_expiredr3�popleft�_Queue__put_internalr�_getr<r)r(r=�getterrrrr>�s

zQueue.put_nowait)rrcCsHt�}y|j|j��Wn*tk
rB|jj|�t||�YnX|S)a.Remove and return an item from the queue.

        Returns an awaitable which resolves once an item is available, or raises
        `tornado.util.TimeoutError` after a timeout.

        ``timeout`` may be a number denoting a time (on the same
        scale as `tornado.ioloop.IOLoop.time`, normally `time.time`), or a
        `datetime.timedelta` object for a deadline relative to the
        current time.

        .. note::

           The ``timeout`` argument of this method differs from that
           of the standard library's `queue.Queue.get`. That method
           interprets numeric values as relative timeouts; this one
           interprets them as absolute deadlines and requires
           ``timedelta`` objects for relative timeouts (consistent
           with other timeouts in Tornado).

        )rr@�
get_nowaitrr3r?r%)r(rrrrrr*�sz	Queue.getcCsP|j�|jr8|jj�\}}|j|�t|d�|j�S|j�rH|j�St�dS)z�Remove and return an item from the queue without blocking.

        Return an item if one is immediately available, else raise
        `QueueEmpty`.
        N)rBr4rCrDrrEr:r)r(r=ZputterrrrrG�s

zQueue.get_nowaitcCs8|jdkrtd��|jd8_|jdkr4|jj�dS)a�Indicate that a formerly enqueued task is complete.

        Used by queue consumers. For each `.get` used to fetch a task, a
        subsequent call to `.task_done` tells the queue that the processing
        on the task is complete.

        If a `.join` is blocking, it resumes when all items have been
        processed; that is, when every `.put` is matched by a `.task_done`.

        Raises `ValueError` if called more times than `.put`.
        rz!task_done() called too many times�N)r5r.r6r7)r(rrr�	task_dones


zQueue.task_donecCs|jj|�S)z�Block until all items in the queue are processed.

        Returns an awaitable, which raises `tornado.util.TimeoutError` after a
        timeout.
        )r6�wait)r(rrrr�join"sz
Queue.joincCst|�S)N)r&)r(rrr�	__aiter__*szQueue.__aiter__cCstj�|_dS)N)r1r2r9)r(rrrr0.szQueue._initcCs
|jj�S)N)r9rC)r(rrrrE1sz
Queue._getcCs|jj|�dS)N)r9r?)r(r=rrr�_put4sz
Queue._putcCs&|jd7_|jj�|j|�dS)NrH)r5r6�clearrM)r(r=rrrZ__put_internal9s
zQueue.__put_internalcCsPx&|jr&|jddj�r&|jj�qWx"|jrJ|jdj�rJ|jj�q*WdS)NrrH)r4rrCr3)r(rrrrB>szQueue._consume_expiredcCs dt|�jtt|��|j�fS)Nz
<%s at %s %s>)�typer�hex�id�_format)r(rrr�__repr__FszQueue.__repr__cCsdt|�j|j�fS)Nz<%s %s>)rOrrR)r(rrr�__str__Isz
Queue.__str__cCsnd|jf}t|dd�r&|d|j7}|jr>|dt|j�7}|jrV|dt|j�7}|jrj|d|j7}|S)Nz
maxsize=%rr9z	 queue=%rz getters[%s]z putters[%s]z	 tasks=%s)r,�getattrr9r3r8r4r5)r(�resultrrrrRLsz
Queue._format)r)N)N)N)$rrrrr9�intr)�propertyr,r:�boolr;r<rr�float�datetime�	timedeltarAr>r
r*rGrIrKr&rLr0rErMrDrB�strrSrTrRrrrrrQs0B  c@s<eZdZdZdd�dd�Zedd�dd�Zed�d	d
�ZdS)raCA `.Queue` that retrieves entries in priority order, lowest first.

    Entries are typically tuples like ``(priority number, data)``.

    .. testcode::

        from tornado.queues import PriorityQueue

        q = PriorityQueue()
        q.put((1, 'medium-priority item'))
        q.put((0, 'high-priority item'))
        q.put((10, 'low-priority item'))

        print(q.get_nowait())
        print(q.get_nowait())
        print(q.get_nowait())

    .. testoutput::

        (0, 'high-priority item')
        (1, 'medium-priority item')
        (10, 'low-priority item')
    N)rcCs
g|_dS)N)r9)r(rrrr0rszPriorityQueue._init)r=rcCstj|j|�dS)N)�heapq�heappushr9)r(r=rrrrMuszPriorityQueue._putcCstj|j�S)N)r^�heappopr9)r(rrrrExszPriorityQueue._get)rrrrr0rrMrErrrrrYsc@s<eZdZdZdd�dd�Zedd�dd�Zed�d	d
�ZdS)ra]A `.Queue` that retrieves the most recently put items first.

    .. testcode::

        from tornado.queues import LifoQueue

        q = LifoQueue()
        q.put(3)
        q.put(2)
        q.put(1)

        print(q.get_nowait())
        print(q.get_nowait())
        print(q.get_nowait())

    .. testoutput::

        1
        2
        3
    N)rcCs
g|_dS)N)r9)r(rrrr0�szLifoQueue._init)r=rcCs|jj|�dS)N)r9r?)r(r=rrrrM�szLifoQueue._putcCs
|jj�S)N)r9�pop)r(rrrrE�szLifoQueue._get)rrrrr0rrMrErrrrr|s)"rr1r[r^ZtornadorrZtornado.concurrentrrZ
tornado.locksrZtypingrrr	r
Z
TYPE_CHECKINGrrr
rr�__all__�	ExceptionrrrZr\r%r&rrrrrrr�<module>s,
#