HEX
Server: LiteSpeed
System: Linux s787.bom1.mysecurecloudhost.com 4.18.0-477.13.1.lve.el8.x86_64 #1 SMP Thu Jun 1 16:40:47 EDT 2023 x86_64
User: mobilech (5348)
PHP: 8.1.34
Disabled: NONE
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/tornado/__pycache__/queues.cpython-310.pyc
o

;j�0�@s$dZddlZddlZddlZddlmZmZddlmZm	Z	ddl
mZddlm
Z
mZmZmZmZddlZejrCddlmZmZmZed�Zgd	�ZGd
d�de�ZGdd
�d
e�Zdede
deejfddfdd�ZGdd�dee�ZGdd�dee�ZGdd�de�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�Optional)�Deque�Tuple�Any�_T)�Queue�
PriorityQueue�	LifoQueue�	QueueFull�
QueueEmptyc@�eZdZdZdS)rz:Raised by `.Queue.get_nowait` when the queue has no items.N��__name__�
__module__�__qualname__�__doc__�rr�B/opt/saltstack/salt/lib/python3.10/site-packages/tornado/queues.pyr/�rc@r)rzBRaised by `.Queue.put_nowait` when a queue is at its maximum size.Nrrrrrr5rr�future�timeout�returncsD|r d�fdd�}tj�����||������fdd��dSdS)Nr cs���s
��t���dSdS�N)�doneZ
set_exceptionr�TimeoutErrorr)rrr�
on_timeout@s�z _set_timeout.<locals>.on_timeoutcs
����Sr!)Zremove_timeout)�_)�io_loop�timeout_handlerr�<lambda>Fs
z_set_timeout.<locals>.<lambda>�r N)rZIOLoop�currentZadd_timeoutZadd_done_callback)rrr$r)rr&r'r�_set_timeout;s
�r+c@s(eZdZd	dd�Zdeefdd�ZdS)
�_QueueIterator�q�	Queue[_T]r NcCs
||_dSr!)r-)�selfr-rrr�__init__J�
z_QueueIterator.__init__cC�
|j��Sr!)r-�get�r/rrr�	__anext__Mr1z_QueueIterator.__anext__)r-r.r N)rrrr0r
rr5rrrrr,Is
r,c@s�eZdZdZdZd1deddfdd�Zedefdd	��Zdefd
d�Z	de
fdd
�Zde
fdd�Z	d2de
deeeejfddfdd�Zde
ddfdd�Z	d2deeeejfdee
fdd�Zde
fdd�Zd3dd�Z	d2deeeejfdedfdd�Zdee
fdd �Zd3d!d"�Zde
fd#d$�Zde
ddfd%d&�Zde
ddfd'd(�Zd3d)d*�Z de!fd+d,�Z"de!fd-d.�Z#de!fd/d0�Z$dS)4ra�Coordinate producer and consumer coroutines.

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

    .. testcode::

        import asyncio
        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 asyncio.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')

        asyncio.run(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�maxsizer cCsb|durtd��|dkrtd��||_|��t�g�|_t�g�|_d|_t	�|_
|j
��dS)Nzmaxsize can't be Nonerzmaxsize can't be negative)�	TypeError�
ValueError�_maxsize�_init�collections�deque�_getters�_putters�_unfinished_tasksr�	_finished�set)r/r6rrrr0�szQueue.__init__cCs|jS)z%Number of items allowed in the queue.)r9r4rrrr6�sz
Queue.maxsizecCs
t|j�S)zNumber of items in the queue.)�len�_queuer4rrr�qsize�s
zQueue.qsizecCs|jSr!�rCr4rrr�empty��zQueue.emptycCs|jdkrdS|��|jkS)NrF)r6rDr4rrr�full�s
z
Queue.full�itemrzFuture[None]cCsRt�}z|�|�Wnty!|j�||f�t||�Y|Sw|�d�|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_nowaitrr>�appendr+�
set_result)r/rIrrrrr�put�s
�
z	Queue.putcCs^|��|jr"|��sJd��|j��}|�|�t||���dS|��r(t�|�|�dS)z{Put an item into the queue without blocking.

        If no free slot is immediately available, raise `QueueFull`.
        z)queue non-empty, why are getters waiting?N)	�_consume_expiredr=rF�popleft�_Queue__put_internalr�_getrHr)r/rI�getterrrrrJ�s

zQueue.put_nowaitcCsFt�}z
|�|���W|Sty"|j�|�t||�Y|Sw)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).

        )rrL�
get_nowaitrr=rKr+)r/rrrrrr3�s��z	Queue.getcCs\|��|jr$|��sJd��|j��\}}|�|�t|d�|��S|��r,|��St�)z�Remove and return an item from the queue without blocking.

        Return an item if one is immediately available, else raise
        `QueueEmpty`.
        z(queue not full, why are putters waiting?N)	rNr>rHrOrPrrQrDr)r/rIZputterrrrrSs

zQueue.get_nowaitcCs<|jdkr	td��|jd8_|jdkr|j��dSdS)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)r?r8r@rAr4rrr�	task_dones

�zQueue.task_donecCs|j�|�S)z�Block until all items in the queue are processed.

        Returns an awaitable, which raises `tornado.util.TimeoutError` after a
        timeout.
        )r@�wait)r/rrrr�join$sz
Queue.joincCst|�Sr!)r,r4rrr�	__aiter__.rGzQueue.__aiter__cCst��|_dSr!)r;r<rCr4rrrr:2szQueue._initcCr2r!)rCrOr4rrrrQ5r1z
Queue._getcC�|j�|�dSr!�rCrK�r/rIrrr�_put8�z
Queue._putcCs&|jd7_|j��|�|�dS)NrT)r?r@�clearr\r[rrrZ__put_internal=s
zQueue.__put_internalcCs||jr|jdd��r|j��|jr|jdd��s|jr8|jd��r<|j��|jr:|jd��s'dSdSdSdS)NrrT)r>r"rOr=r4rrrrNBs
�
$�zQueue._consume_expiredcCs*dt|�j�dtt|���d|���d�S)N�<z at � �>)�typer�hex�id�_formatr4rrr�__repr__Js*zQueue.__repr__cCsdt|�j�d|���d�S)Nr_r`ra)rbrrer4rrr�__str__Msz
Queue.__str__cCsnd|j��}t|dd�r|d|j7}|jr|dt|j�7}|jr+|dt|j�7}|jr5|d|j7}|S)Nzmaxsize=rCz	 queue=%rz getters[%s]z putters[%s]z	 tasks=%s)r6�getattrrCr=rBr>r?)r/�resultrrrrePsz
Queue._format)rr!r))%rrrrrC�intr0�propertyr6rD�boolrFrHrrr�float�datetime�	timedeltarMrJr
r3rSrUrWr,rXr:rQr\rPrN�strrfrgrerrrrrQsRE���
���
�
��
�


rc@�:eZdZdZddd�Zdeddfdd�Zdefd	d
�ZdS)ra�A `.Queue` that retrieves entries in priority order, lowest first.

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

    .. testcode::

        import asyncio
        from tornado.queues import PriorityQueue

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

            print(await q.get())
            print(await q.get())
            print(await q.get())

        asyncio.run(main())

    .. testoutput::

        (0, 'high-priority item')
        (1, 'medium-priority item')
        (10, 'low-priority item')
    r NcC�
g|_dSr!rEr4rrrr:zr1zPriorityQueue._initrIcCst�|j|�dSr!)�heapq�heappushrCr[rrrr\}szPriorityQueue._putcCst�|j�Sr!)rs�heappoprCr4rrrrQ�szPriorityQueue._getr)�rrrrr:rr\rQrrrrr]s

rc@rq)ra�A `.Queue` that retrieves the most recently put items first.

    .. testcode::

        import asyncio
        from tornado.queues import LifoQueue

        async def main():
            q = LifoQueue()
            q.put(3)
            q.put(2)
            q.put(1)

            print(await q.get())
            print(await q.get())
            print(await q.get())

        asyncio.run(main())

    .. testoutput::

        1
        2
        3
    r NcCrrr!rEr4rrrr:�r1zLifoQueue._initrIcCrYr!rZr[rrrr\�r]zLifoQueue._putcCr2r!)rC�popr4rrrrQ�r1zLifoQueue._getr)rvrrrrr�s

r)"rr;rnrsZtornadorrZtornado.concurrentrrZ
tornado.locksr�typingrrr	r
r�
TYPE_CHECKINGrr
rr�__all__�	Exceptionrrrmror+r,rrrrrrr�<module>s8
��
�'