U ÃÏ ap%ã@s¾dZddlmZddlmZddlmZddlmZddlm Z ddlm Z dd lm Z dd l m Z d d d gZGdd „d eƒZGdd „d eƒZGdd „d ƒZGdd„dƒZGdd„deƒZdS)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@seZdZdZdS)r z4Exception raised by Queue.get(block=0)/get_nowait().N©Ú__name__Ú __module__Ú __qualname__Ú__doc__©rrúVC:\Users\vtejo\AppData\Local\Temp\pip-unpacked-wheel-nyjtotrf\sqlalchemy\util\queue.pyr #sc@seZdZdZdS)r z4Exception raised by Queue.put(block=0)/put_nowait().Nrrrrrr )sc@s‚eZdZd!dd„Zdd„Zdd„Zd d „Zd"d d„Zdd„Zd#dd„Z dd„Z dd„Z dd„Z dd„Z dd„Zdd„Zdd „Zd S)$r rFcCs:| |¡t ¡|_t |j¡|_t |j¡|_||_dS)z½Initialize 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ÚmaxsizerrrrÚ__init__0s   zQueue.__init__c Cs&|j| ¡W5QR£SQRXdS)z9Return the approximate size of the queue (not reliable!).N)rÚ_qsize©rrrrÚqsizeGsz Queue.qsizec Cs&|j| ¡W5QR£SQRXdS)zKReturn True if the queue is empty, False otherwise (not reliable!).N)rÚ_emptyr!rrrÚemptyMsz Queue.emptyc Cs&|j| ¡W5QR£SQRXdS)zJReturn True if the queue is full, False otherwise (not reliable!).N)rÚ_fullr!rrrÚfullTsz Queue.fullTNc Cs |j|s| ¡r~t‚nd|dkr8| ¡r~|j ¡q"nF|dkrHtdƒ‚tƒ|}| ¡r~|tƒ}|dkrpt‚|j |¡qR| |¡|j ¡W5QRXdS)aPut 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ç) rr%r ÚwaitÚ ValueErrorÚ_timeÚ_putrÚnotify)rÚitemÚblockÚtimeoutÚendtimeÚ remainingrrrÚput[s"    z Queue.putcCs | |d¡S)z­Put an item into the queue without blocking. Only enqueue the item if a free slot is immediately available. Otherwise raise the ``Full`` exception. F)r3©rr.rrrÚ put_nowait{szQueue.put_nowaitc Csª|jš|s| ¡r~t‚nd|dkr8| ¡r~|j ¡q"nF|dkrHtdƒ‚tƒ|}| ¡r~|tƒ}|dkrpt‚|j |¡qR| ¡}|j ¡|W5QR£SQRXdS)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). Nrr'r() rr#r r)r*r+Ú_getrr-)rr/r0r1r2r.rrrÚgetƒs$    z Queue.getcCs | d¡S)z¯Remove and return an item from the queue without blocking. Only get an item if one is immediately available. Otherwise raise the ``Empty`` exception. F)r7r!rrrÚ get_nowait£szQueue.get_nowaitcCs||_tƒ|_dS©N)rrÚqueue)rrrrrr±sz Queue._initcCs t|jƒSr9)Úlenr:r!rrrr µsz Queue._qsizecCs|j Sr9)r:r!rrrr#¹sz Queue._emptycCs|jdkot|jƒ|jkS)Nr)rr;r:r!rrrr%½sz Queue._fullcCs|j |¡dSr9)r:Úappendr4rrrr,Ász Queue._putcCs|jr|j ¡S|j ¡SdSr9)rr:ÚpopÚpopleftr!rrrr6Ås z Queue._get)rF)TN)TN)rrrrr"r$r&r3r5r7r8rr r#r%r,r6rrrrr /s   c@sfeZdZeeƒZddd„Zdd„Zdd„Zd d „Z e d d „ƒZ d d„Z ddd„Z dd„Zddd„ZdS)ÚAsyncAdaptedQueuerFcCs||_||_dSr9)rrrrrrrÑszAsyncAdaptedQueue.__init__cCs |j ¡Sr9)Ú_queuer$r!rrrr$ÕszAsyncAdaptedQueue.emptycCs |j ¡Sr9)r@r&r!rrrr&ØszAsyncAdaptedQueue.fullcCs |j ¡Sr9)r@r"r!rrrr"ÛszAsyncAdaptedQueue.qsizecCs(|jrtj|jd}ntj|jd}|S)N)r)rrÚ LifoQueuerr )rr:rrrr@Þs zAsyncAdaptedQueue._queuec CsHz|j |¡WStjk rB}ztjtƒ|dW5d}~XYnXdS©N)Zreplace_context)r@r5rÚ QueueFullrÚraise_r )rr.Úerrrrrr5ísþzAsyncAdaptedQueue.put_nowaitTNc CsŠ|s| |¡Sz<|dk r4| t |j |¡|¡¡WS| |j |¡¡WSWn:tjtjfk r„}ztj t ƒ|dW5d}~XYnXdSrB) r5Úawait_rÚwait_forr@r3rCÚ TimeoutErrorrrDr )rr.r/r0rErrrr3ös ÿþzAsyncAdaptedQueue.putc CsFz |j ¡WStjk r@}ztjtƒ|dW5d}~XYnXdSrB)r@r8rÚ QueueEmptyrrDr )rrErrrr8s þzAsyncAdaptedQueue.get_nowaitc Cs„|s | ¡Sz8|dk r0| t |j ¡|¡¡WS| |j ¡¡WSWn:tjtjfk r~}ztj t ƒ|dW5d}~XYnXdSrB) r8rFrrGr@r7rIrHrrDr )rr/r0rErrrr7sÿþzAsyncAdaptedQueue.get)rF)TN)TN)rrrÚ staticmethodr rFrr$r&r"r r@r5r3r8r7rrrrr?Îs    r?c@seZdZeeƒZdS)ÚFallbackAsyncAdaptedQueueN)rrrrJrrFrrrrrK"srKN)rÚ collectionsrrr+ÚrrZ concurrencyrrr Z langhelpersr Ú__all__Ú Exceptionr r r r?rKrrrrÚs          T