
    -hM$                         S r SSKJr  SSKJr  SSKJr  SSKJr  SSKJ	r	  SSKJ
r
  SS	KJr  SS
KJr  / SQr " S S\5      r " S S\5      r " S S5      r " S S5      r " S S\5      rg)a  An adaptation of Py2.3/2.4's Queue module which supports reentrant
behavior, using RLock instead of Lock for its mutex object.  The
Queue object is used exclusively by the sqlalchemy.pool.QueuePool
class.

This is to support the connection pool's usage of weakref callbacks to return
connections to the underlying Queue, which can in extremely
rare cases be invoked within the ``get()`` method of the Queue itself,
producing a ``put()`` inside the ``get()`` and therefore a reentrant
condition.

    )deque)time   )compat)	threading)asyncio)await_fallback)
await_only)memoized_property)EmptyFullQueuec                       \ rS rSrSrSrg)r   #   z4Exception raised by Queue.get(block=0)/get_nowait(). N__name__
__module____qualname____firstlineno____doc____static_attributes__r       jC:\Users\ROHAN GUPTA\OneDrive\Desktop\mathbuddy-assessment\venv\Lib\site-packages\sqlalchemy/util/queue.pyr   r   #       :r   r   c                       \ rS rSrSrSrg)r   )   z4Exception raised by Queue.put(block=0)/put_nowait().r   Nr   r   r   r   r   r   )   r   r   r   c                   t    \ rS rSrSS jrS rS rS rSS jrS r	SS	 jr
S
 rS rS rS rS rS rS rSrg)r   /   c                     U R                  U5        [        R                  " 5       U l        [        R                  " U R                  5      U l        [        R                  " U R                  5      U l        X l        g)zInitialize a queue object with a given maximum size.

If `maxsize` is <= 0, the queue size is infinite.

If `use_lifo` is True, this Queue acts like a Stack (LIFO).
N)_initr   RLockmutex	Condition	not_emptynot_fulluse_lifoselfmaxsizer'   s      r   __init__Queue.__init__0   sU     	

7
 __&
 #,,TZZ8 "++DJJ7 r   c                 p    U R                      U R                  5       sSSS5        $ ! , (       d  f       g= f)z9Return the approximate size of the queue (not reliable!).N)r#   _qsizer)   s    r   qsizeQueue.qsizeG   s     ZZ;;= ZZ   '
5c                 p    U R                      U R                  5       sSSS5        $ ! , (       d  f       g= f)zCReturn True if the queue is empty, False otherwise (not
reliable!).N)r#   _emptyr/   s    r   emptyQueue.emptyM   s     ZZ;;= ZZr2   c                 p    U R                      U R                  5       sSSS5        $ ! , (       d  f       g= f)zBReturn True if the queue is full, False otherwise (not
reliable!).N)r#   _fullr/   s    r   full
Queue.fullT   s     ZZ::< ZZr2   Nc                 |   U R                      U(       d  U R                  5       (       a  [        eOUcG  U R                  5       (       a1  U R                   R                  5         U R                  5       (       a  M1  O~US:  a  [	        S5      e[        5       U-   nU R                  5       (       aK  U[        5       -
  nUS::  a  [        eU R                   R                  U5        U R                  5       (       a  MK  U R                  U5        U R                  R                  5         SSS5        g! , (       d  f       g= f)a  Put an item into the queue.

If optional args `block` is True and `timeout` is None (the
default), block if necessary until a free slot is
available. If `timeout` is a positive number, it blocks at
most `timeout` seconds and raises the ``Full`` exception if no
free slot was available within that time.  Otherwise (`block`
is false), put an item on the queue if a free slot is
immediately available, else raise the ``Full`` exception
(`timeout` is ignored in that case).
Nr   #'timeout' must be a positive number        )	r&   r8   r   wait
ValueError_time_putr%   notify)r)   itemblocktimeoutendtime	remainings         r   put	Queue.put[   s     ]]::<<J  jjllMM&&( jjll Q;$%JKK'G+jjll '%' 1I C'"
MM&&y1	 jjll
 IIdONN!!## ]]s   A+D-:A=D-9+D--
D;c                 &    U R                  US5      $ )zPut an item into the queue without blocking.

Only enqueue the item if a free slot is immediately available.
Otherwise raise the ``Full`` exception.
F)rH   r)   rC   s     r   
put_nowaitQueue.put_nowait{   s     xxe$$r   c                 ~   U R                      U(       d  U R                  5       (       a  [        eOUcG  U R                  5       (       a1  U R                   R                  5         U R                  5       (       a  M1  O~US:  a  [	        S5      e[        5       U-   nU R                  5       (       aK  U[        5       -
  nUS::  a  [        eU R                   R                  U5        U R                  5       (       a  MK  U R                  5       nU R                  R                  5         UsSSS5        $ ! , (       d  f       g= f)a  Remove and return an item from the queue.

If optional args `block` is True and `timeout` is None (the
default), block if necessary until an item is available. If
`timeout` is a positive number, it blocks at most `timeout`
seconds and raises the ``Empty`` exception if no item was
available within that time.  Otherwise (`block` is false),
return an item if one is immediately available, else raise the
``Empty`` exception (`timeout` is ignored in that case).

Nr   r<   r=   )	r%   r4   r   r>   r?   r@   _getr&   rB   )r)   rD   rE   rF   rG   rC   s         r   get	Queue.get   s     ^^;;==K !kkmmNN'') kkmm Q;$%JKK'G+kkmm '%' 1I C'#NN''	2	 kkmm
 99;DMM  "% ^^s   A+D.:A=D.9+D..
D<c                 $    U R                  S5      $ )zRemove and return an item from the queue without blocking.

Only get an item if one is immediately available. Otherwise
raise the ``Empty`` exception.
F)rP   r/   s    r   
get_nowaitQueue.get_nowait   s     xxr   c                 .    Xl         [        5       U l        g N)r*   r   queue)r)   r*   s     r   r!   Queue._init   s    W
r   c                 ,    [        U R                  5      $ rV   )lenrW   r/   s    r   r.   Queue._qsize   s    4::r   c                 $    U R                   (       + $ rV   )rW   r/   s    r   r4   Queue._empty   s    ::~r   c                 r    U R                   S:  =(       a"    [        U R                  5      U R                   :H  $ )Nr   )r*   rZ   rW   r/   s    r   r8   Queue._full   s'    ||aCC

Ot||$CCr   c                 :    U R                   R                  U5        g rV   )rW   appendrK   s     r   rA   
Queue._put   s    

$r   c                     U R                   (       a  U R                  R                  5       $ U R                  R                  5       $ rV   )r'   rW   poppopleftr/   s    r   rO   
Queue._get   s/    ==::>>## ::%%''r   )r*   r#   r%   r&   rW   r'   r   FTN)r   r   r   r   r+   r0   r5   r9   rH   rL   rP   rS   r!   r.   r4   r8   rA   rO   r   r   r   r   r   r   /   sK    !.!! $@%@D (r   r   c                   p    \ rS rSr\" \5      rSS jrS rS r	S r
\S 5       rS rSS	 jrS
 rSS jrSrg)AsyncAdaptedQueue   c                     X l         Xl        g rV   )r'   r*   r(   s      r   r+   AsyncAdaptedQueue.__init__   s     r   c                 6    U R                   R                  5       $ rV   )_queuer5   r/   s    r   r5   AsyncAdaptedQueue.empty       {{  ""r   c                 6    U R                   R                  5       $ rV   )ro   r9   r/   s    r   r9   AsyncAdaptedQueue.full   s    {{!!r   c                 6    U R                   R                  5       $ rV   )ro   r0   r/   s    r   r0   AsyncAdaptedQueue.qsize   rq   r   c                     U R                   (       a   [        R                  " U R                  S9nU$ [        R                  " U R                  S9nU$ )N)r*   )r'   r   	LifoQueuer*   r   )r)   rW   s     r   ro   AsyncAdaptedQueue._queue   s?     ==%%dll;E  MM$,,7Er   c                      U R                   R                  U5      $ ! [        R                   a'  n[        R
                  " [        5       US9   S nAg S nAff = fN)replace_context)ro   rL   r   	QueueFullr   raise_r   )r)   rC   errs      r   rL   AsyncAdaptedQueue.put_nowait   sF    	;;))$//   	MM #	s    AAANc                    U(       d  U R                  U5      $  Ub?  U R                  [        R                  " U R                  R                  U5      U5      5      $ U R                  U R                  R                  U5      5      $ ! [        R                  [        R                  4 a'  n[        R                  " [        5       US9   S nAg S nAff = frz   )rL   await_r   wait_forro   rH   r|   TimeoutErrorr   r}   r   )r)   rC   rD   rE   r~   s        r   rH   AsyncAdaptedQueue.put   s    ??4((	"{{$$T[[__T%:GD  {{4;;??4#899!!7#7#78 	MM #	s   AB )B $C*CCc                      U R                   R                  5       $ ! [        R                   a'  n[        R
                  " [        5       US9   S nAg S nAff = frz   )ro   rS   r   
QueueEmptyr   r}   r   )r)   r~   s     r   rS   AsyncAdaptedQueue.get_nowait  sD    	;;))++!! 	MM #	s    AAAc                    U(       d  U R                  5       $  Ub>  U R                  [        R                  " U R                  R                  5       U5      5      $ U R                  U R                  R                  5       5      $ ! [        R                  [        R                  4 a'  n[        R                  " [        5       US9   S nAg S nAff = frz   )rS   r   r   r   ro   rP   r   r   r   r}   r   )r)   rD   rE   r~   s       r   rP   AsyncAdaptedQueue.get  s    ??$$	"{{$$T[[__%6@  {{4;;??#455""G$8$89 	MM #	s   A B (B $C'C		C)r*   r'   rg   rh   )r   r   r   r   staticmethodr
   r   r+   r5   r9   r0   r   ro   rL   rH   rS   rP   r   r   r   r   rj   rj      sH    *%F#"#  "r   rj   c                   $    \ rS rSr\" \5      rSrg)FallbackAsyncAdaptedQueuei"  r   N)r   r   r   r   r   r	   r   r   r   r   r   r   r   "  s    .)Fr   r   N)r   collectionsr   r   r@    r   r   concurrencyr   r	   r
   langhelpersr   __all__	Exceptionr   r   r   rj   r   r   r   r   <module>r      sj          ' # * %	I 		9 	\( \(~Q Qh* 1 *r   