
    F\h'                         S r SSKrSSKrSSKJr  SSKJr  SSKJr   " S S\5      r	 " S	 S
\5      r
 " S S\5      r " S S\R                  5      r " S S\5      r " S S\5      rg))QueuePriorityQueue	LifoQueue	QueueFull
QueueEmptyQueueShutDown    N)GenericAlias   )locks)mixinsc                       \ rS rSrSrSrg)r      z;Raised when Queue.get_nowait() is called on an empty Queue. N__name__
__module____qualname____firstlineno____doc____static_attributes__r       %/usr/lib/python3.13/asyncio/queues.pyr   r      s    Er   r   c                       \ rS rSrSrSrg)r      zDRaised when the Queue.put_nowait() method is called on a full Queue.r   Nr   r   r   r   r   r      s    Nr   r   c                       \ rS rSrSrSrg)r      z<Raised when putting on to or getting from a shut-down Queue.r   Nr   r   r   r   r   r      s    Fr   r   c                       \ rS rSrSrSS jrS rS rS rS r	S r
S	 r\" \5      rS
 rS r\S 5       rS rS rS rS rS rS rS rS rSS jrSrg)r   !   a  A queue, useful for coordinating producer and consumer coroutines.

If maxsize is less than or equal to zero, the queue size is infinite. If it
is an integer greater than 0, then "await put()" will block when the
queue reaches maxsize, until an item is removed by get().

Unlike the standard library Queue, you can reliably know this Queue's size
with qsize(), since your single-threaded asyncio application won't be
interrupted between calling qsize() and doing an operation on the Queue.
c                    Xl         [        R                  " 5       U l        [        R                  " 5       U l        SU l        [        R                  " 5       U l        U R                  R                  5         U R                  U5        SU l        g )Nr   F)_maxsizecollectionsdeque_getters_putters_unfinished_tasksr   Event	_finishedset_init_is_shutdownselfmaxsizes     r   __init__Queue.__init__-   sb     $))+#))+!"

7!r   c                 8    [         R                  " 5       U l        g N)r!   r"   _queuer+   s     r   r)   Queue._init<   s    !'')r   c                 6    U R                   R                  5       $ r1   )r2   popleftr,   s    r   _get
Queue._get?   s    {{""$$r   c                 :    U R                   R                  U5        g r1   r2   appendr,   items     r   _put
Queue._putB       4 r   c                     U(       aA  UR                  5       nUR                  5       (       d  UR                  S 5        g U(       a  M@  g g r1   )r5   done
set_result)r,   waiterswaiters      r   _wakeup_nextQueue._wakeup_nextG   s4    __&F;;==!!$'	 gr   c                 p    S[        U 5      R                   S[        U 5      S SU R                  5        S3$ )N<z at z#x >)typer   id_formatr6   s    r   __repr__Queue.__repr__O   s5    4:&&'tBtHR=$,,.9IKKr   c                 V    S[        U 5      R                   SU R                  5        S3$ )NrI   rJ   rK   )rL   r   rN   r6   s    r   __str__Queue.__str__R   s)    4:&&'q(8::r   c                    SU R                   < 3n[        U SS 5      (       a  US[        U R                  5      < 3-  nU R                  (       a  US[        U R                  5       S3-  nU R                  (       a  US[        U R                  5       S3-  nU R                  (       a  USU R                   3-  nU R                  (       a  US-  nU$ )	Nzmaxsize=r2   z _queue=z
 _getters[]z
 _putters[z tasks=z	 shutdown)	r    getattrlistr2   r#   lenr$   r%   r*   )r,   results     r   rN   Queue._formatW   s    DMM,-44((dkk!2 566F==
3t}}#5"6a88F==
3t}}#5"6a88F!! 6 6788Fk!Fr   c                 ,    [        U R                  5      $ )zNumber of items in the queue.)rX   r2   r6   s    r   qsizeQueue.qsizee   s    4;;r   c                     U R                   $ )z%Number of items allowed in the queue.)r    r6   s    r   r-   Queue.maxsizei   s     }}r   c                 $    U R                   (       + $ )z3Return True if the queue is empty, False otherwise.r2   r6   s    r   emptyQueue.emptyn   s    ;;r   c                 ^    U R                   S::  a  gU R                  5       U R                   :  $ )zReturn True if there are maxsize items in the queue.

Note: if the Queue was initialized with maxsize=0 (the default),
then full() is never True.
r   F)r    r\   r6   s    r   full
Queue.fullr   s(     ==A::<4==00r   c                 N  #    U R                  5       (       ar  U R                  (       a  [        eU R                  5       R	                  5       nU R
                  R                  U5         UI Sh  vN   U R                  5       (       a  Mr  U R                  U5      $  N,!   UR                  5          U R
                  R                  U5        O! [         a     Of = fU R                  5       (       d0  UR                  5       (       d  U R                  U R
                  5        e = f7f)zPut an item into the queue.

Put an item into the queue. If the queue is full, wait until a free
slot is available before adding item.

Raises QueueShutDown if the queue has been shut down.
N)re   r*   r   	_get_loopcreate_futurer$   r;   cancelremove
ValueError	cancelledrF   
put_nowait)r,   r=   putters      r   put	Queue.put}   s      iikk  ##^^%335FMM  ( iikk* t$$ MM((0!   yy{{6+;+;+=+= %%dmm4s[   A&D%)B .B/B 3D%
D%B D"0CD"
CD"CA	D""D%c                    U R                   (       a  [        eU R                  5       (       a  [        eU R	                  U5        U =R
                  S-  sl        U R                  R                  5         U R                  U R                  5        g)zPut an item into the queue without blocking.

If no free slot is immediately available, raise QueueFull.

Raises QueueShutDown if the queue has been shut down.
r
   N)
r*   r   re   r   r>   r%   r'   clearrF   r#   r<   s     r   rn   Queue.put_nowait   sa     99;;O		$!#$--(r   c                 v  #    U R                  5       (       a  U R                  (       a  U R                  5       (       a  [        eU R                  5       R	                  5       nU R
                  R                  U5         UI Sh  vN   U R                  5       (       a  M  U R                  5       $  N+!   UR                  5          U R
                  R                  U5        O! [         a     Of = fU R                  5       (       d0  UR                  5       (       d  U R                  U R
                  5        e = f7f)zRemove and return an item from the queue.

If queue is empty, wait until an item is available.

Raises QueueShutDown if the queue has been shut down and is empty, or
if the queue has been shut down immediately.
N)rb   r*   r   rh   ri   r#   r;   rj   rk   rl   rm   rF   
get_nowait)r,   getters     r   get	Queue.get   s      jjll  TZZ\\##^^%335FMM  ( jjll*    MM((0!   zz||F,<,<,>,> %%dmm4s[   A;D9>B1 B/B1 D9D9/B1 1D6C D6 
C-*D6,C--A	D66D9c                     U R                  5       (       a  U R                  (       a  [        e[        eU R	                  5       nU R                  U R                  5        U$ )zRemove and return an item from the queue.

Return an item if one is immediately available, else raise QueueEmpty.

Raises QueueShutDown if the queue has been shut down and is empty, or
if the queue has been shut down immediately.
)rb   r*   r   r   r7   rF   r$   r<   s     r   rv   Queue.get_nowait   sF     ::<<  ##yy{$--(r   c                     U R                   S::  a  [        S5      eU =R                   S-  sl         U R                   S:X  a  U R                  R                  5         gg)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 currently blocking, it will resume when all items have
been processed (meaning that a task_done() call was received for every
item that had been put() into the queue).

shutdown(immediate=True) calls task_done() for each remaining item in
the queue.

Raises ValueError if called more times than there were items placed in
the queue.
r   z!task_done() called too many timesr
   N)r%   rl   r'   r(   r6   s    r   	task_doneQueue.task_done   sR    " !!Q&@AA!#!!Q&NN  'r   c                 v   #    U R                   S:  a#  U R                  R                  5       I Sh  vN   gg N7f)aW  Block until all items in the queue have been gotten and processed.

The count of unfinished tasks goes up whenever an item is added to the
queue. The count goes down whenever a consumer calls task_done() to
indicate that the item was retrieved and all work on it is complete.
When the count of unfinished tasks drops to zero, join() unblocks.
r   N)r%   r'   waitr6   s    r   join
Queue.join   s3      !!A%..%%''' &'s   .979c                    SU l         U(       a  U R                  5       (       dL  U R                  5         U R                  S:  a  U =R                  S-  sl        U R                  5       (       d  ML  U R                  S:X  a  U R                  R                  5         U R                  (       aS  U R                  R                  5       nUR                  5       (       d  UR                  S5        U R                  (       a  MS  U R                  (       aT  U R                  R                  5       nUR                  5       (       d  UR                  S5        U R                  (       a  MS  gg)ao  Shut-down the queue, making queue gets and puts raise QueueShutDown.

By default, gets will only raise once the queue is empty. Set
'immediate' to True to make gets raise immediately instead.

All blocked callers of put() and get() will be unblocked. If
'immediate', a task is marked as done for each item remaining in
the queue, which may unblock callers of join().
Tr   r
   N)r*   rb   r7   r%   r'   r(   r#   r5   rB   rC   r$   )r,   	immediaterw   ro   s       r   shutdownQueue.shutdown   s     !jjll		))A-**a/* jjll %%*""$mm]]**,F;;==!!$' mmm mm]]**,F;;==!!$' mmmr   )r'   r#   r*   r    r$   r2   r%   N)r   )F)r   r   r   r   r   r.   r)   r7   r>   rF   rO   rR   classmethodr	   __class_getitem__rN   r\   propertyr-   rb   re   rp   rn   rx   rv   r}   r   r   r   r   r   r   r   r   !   s    	"*%!
L; $L1   	1%>) !> !.	((r   r   c                   ^    \ rS rSrSrS r\R                  4S jr\R                  4S jr
Srg)r   i  zA subclass of Queue; retrieves entries in priority order (lowest first).

Entries are typically tuples of the form: (priority number, data).
c                     / U l         g r1   ra   r+   s     r   r)   PriorityQueue._init   	    r   c                 *    U" U R                   U5        g r1   ra   )r,   r=   heappushs      r   r>   PriorityQueue._put#  s    d#r   c                 &    U" U R                   5      $ r1   ra   )r,   heappops     r   r7   PriorityQueue._get&  s    t{{##r   ra   N)r   r   r   r   r   r)   heapqr   r>   r   r7   r   r   r   r   r   r     s(    
 #(.. $ !== $r   r   c                   *    \ rS rSrSrS rS rS rSrg)r   i*  zEA subclass of Queue that retrieves most recently added entries first.c                     / U l         g r1   ra   r+   s     r   r)   LifoQueue._init-  r   r   c                 :    U R                   R                  U5        g r1   r:   r<   s     r   r>   LifoQueue._put0  r@   r   c                 6    U R                   R                  5       $ r1   )r2   popr6   s    r   r7   LifoQueue._get3  s    {{  r   ra   N)	r   r   r   r   r   r)   r>   r7   r   r   r   r   r   r   *  s    O!!r   r   )__all__r!   r   typesr	    r   r   	Exceptionr   r   r   _LoopBoundMixinr   r   r   r   r   r   <module>r      sn        	 	
		 	
	I 	
v(F"" v(r$E $ 
! 
!r   