� l\�g�'���dZddlmZddlZddlmZddlZddlmZddl Z ddl m Z ddl m Z ddl m Z dd l m Z dd l mZdd l mZd d lmZd dlmZd dlmZede ���Zgd�ZGd�de��ZGd�de��ZGd�de e��ZGd�dee��ZGd�dee��ZGd�dee��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. �)� annotationsN)�deque)�time)�Any)� Awaitable)�Deque)�Generic)�Optional)�TypeVar�)�await_fallback)� await_only)�memoized_property�_T)�bound)�Empty�Full�Queuec��eZdZdZdS)rz4Exception raised by Queue.get(block=0)/get_nowait().N��__name__� __module__� __qualname__�__doc__���e/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/sqlalchemy/util/queue.pyrr,�������:�:��Drrc��eZdZdZdS)rz4Exception raised by Queue.put(block=0)/put_nowait().Nrrrrrr2rrrc�l�eZdZUded<ded<ddd�Zdd �Zdd �Zdd �Zdd�Z ddd�Z dd�Z dd d�Z dS)!� QueueCommon�int�maxsize�bool�use_liforFc��dS�Nr��selfr#r%s r�__init__zQueueCommon.__init__<s���r�returnc��t���r'��NotImplementedError�r)s r�emptyzQueueCommon.empty>���!�#�#�#rc��t���r'r-r/s r�fullzQueueCommon.fullAr1rc��t���r'r-r/s r�qsizezQueueCommon.qsizeDr1r�itemr�Nonec��t���r'r-�r)r6s r� put_nowaitzQueueCommon.put_nowaitGr1rTN�block�timeout�Optional[float]c��t���r'r-)r)r6r;r<s r�putzQueueCommon.putJs��"�#�#�#rc��t���r'r-r/s r� get_nowaitzQueueCommon.get_nowaitOr1rc��t���r'r-)r)r;r<s r�getzQueueCommon.getRr1r�rF�r#r"r%r$�r+r$�r+r"�r6rr+r7�TN�r6rr;r$r<r=r+r7�r+r�r;r$r<r=r+r) rrr�__annotations__r*r0r3r5r:r?rArCrrrr!r!8s���������L�L�L��N�N�N�E�E�E�E�E�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�HL�$�$�$�$�$� $�$�$�$�$�$�$�$�$�$�$rr!c��eZdZUded<d d!d �Zd"d �Zd#d �Zd#d �Z d$d%d�Zd&d�Z d$d'd�Z d(d�Z d)d�Z d"d�Z d#d�Zd#d�Zd&d�Zd(d�ZdS)*rz Deque[_T]�queuerFr#r"r%r$c���|�|��tj��|_tj|j��|_tj|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)�_init� threading�RLock�mutex� Condition� not_empty�not_fullr%r(s rr*zQueue.__init__Ys^�� � � �7���� �_�&�&�� �#�,�T�Z�8�8���"�+�D�J�7�7�� � �� � � rr+c�l�|j5|���cddd��S#1swxYwYdS)z9Return the approximate size of the queue (not reliable!).N)rT�_qsizer/s rr5z Queue.qsizeps{���Z� !� !��;�;�=�=� !� !� !� !� !� !� !� !� !� !� !� !���� !� !� !� !� !� !� �)�-�-c�l�|j5|���cddd��S#1swxYwYdS)zKReturn True if the queue is empty, False otherwise (not reliable!).N)rT�_emptyr/s rr0z Queue.emptyvs{���Z� !� !��;�;�=�=� !� !� !� !� !� !� !� !� !� !� !� !���� !� !� !� !� !� !rZc�l�|j5|���cddd��S#1swxYwYdS)zJReturn True if the queue is full, False otherwise (not reliable!).N)rT�_fullr/s rr3z Queue.full}s{���Z� � ��:�:�<�<� � � � � � � � � � � � ���� � � � � � rZTNr6rr;r<r=r7c�r�|j5|s|���rt�n�|�B|���r-|j���|����-n�|dkrt d���t ��|z}|���rL|t ��z }|dkrt�|j�|��|����L|�|��|j���ddd��dS#1swxYwYdS)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�) rWr^r�wait� ValueError�_time�_putrV�notify)r)r6r;r<�endtime� remainings rr?z Queue.put�sq���]� $� $�� 2��:�:�<�<���J�����j�j�l�l�)��M�&�&�(�(�(��j�j�l�l�)���Q�;�;�$�%J�K�K�K��'�'�G�+���j�j�l�l�2� '�%�'�'� 1�I� �C�'�'�"� ��M�&�&�y�1�1�1� �j�j�l�l�2� �I�I�d�O�O�O� �N� !� !� #� #� #�# $� $� $� $� $� $� $� $� $� $� $� $���� $� $� $� $� $� $��DD,�,D0�3D0c�.�|�|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)r?r9s rr:zQueue.put_nowait�s�� �x�x��e�$�$�$rc�r�|j5|s|���rt�n�|�B|���r-|j���|����-n�|dkrt d���t ��|z}|���rL|t ��z }|dkrt�|j�|��|����L|���}|j���|cddd��S#1swxYwYdS)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`ra) rVr\rrbrcrd�_getrWrf)r)r;r<rgrhr6s rrCz Queue.get�sr���^� � �� 3��;�;�=�=� ��K� ����k�k�m�m�*��N�'�'�)�)�)��k�k�m�m�*���Q�;�;�$�%J�K�K�K��'�'�G�+���k�k�m�m�3� '�%�'�'� 1�I� �C�'�'�#� ��N�'�'� �2�2�2� �k�k�m�m�3� �9�9�;�;�D� �M� � � "� "� "��% � � � � � � � � � � � ���� � � � � � ric�,�|�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)rCr/s rrAzQueue.get_nowait�s���x�x����rc�:�||_t��|_dSr')r#rrO)r)r#s rrQz Queue._init�s���� ��W�W�� � � rc�*�t|j��Sr')�lenrOr/s rrYz Queue._qsize�s���4�:���rc��|j Sr')rOr/s rr\z Queue._empty�s ���:�~�rc�R�|jdkot|j��|jkS)Nr)r#rprOr/s rr^z Queue._full�s#���|�a��C�C�� �O�O�t�|�$C�Crc�:�|j�|��dSr')rO�appendr9s rrez Queue._put�s�� � ���$�����rc�t�|jr|j���S|j���Sr')r%rO�pop�popleftr/s rrlz Queue._get�s4�� �=� (��:�>�>�#�#� #��:�%�%�'�'� 'rrDrErGrFrIrJrHrLrK)r#r"r+r7)rrrrMr*r5r0r3r?r:rCrArQrYr\r^rerlrrrrrVsV�����������!�!�!�!�!�.!�!�!�!� !�!�!�!� � � � �HL� $� $� $� $� $�D%�%�%�%������@����������������D�D�D�D� � � � �(�(�(�(�(�(rrc��eZdZejr edd���Zn ee��Zddd �Zd d �Z d�Z d�Z e d!d���Z d"d�Z d#d$d�Zd%d�Zd#d&d�ZdS)'�AsyncAdaptedQueue� coroutine�Awaitable[Any]r+rc��dSr'r)rzs r�await_zAsyncAdaptedQueue.await_�s��58�SrrFr#r"r%r$c�"�||_||_dSr')r%r#r(s rr*zAsyncAdaptedQueue.__init__�s�� �� ��� � � rc�4�|j���Sr')�_queuer0r/s rr0zAsyncAdaptedQueue.empty�����{� � �"�"�"rc�4�|j���Sr')r�r3r/s rr3zAsyncAdaptedQueue.fulls���{���!�!�!rc�4�|j���Sr')r�r5r/s rr5zAsyncAdaptedQueue.qsizer�r�asyncio.Queue[_T]c�~�|jrtj|j���}ntj|j���}|S)N)r#)r%�asyncio� LifoQueuer#r)r)rOs rr�zAsyncAdaptedQueue._queues>�� �=� 8��%�d�l�;�;�;�E�E��M�$�,�7�7�7�E�� rr6r7c�� |j�|��dS#tj$r}t ��|�d}~wwxYwr')r�r:r�� QueueFullr)r)r6�errs rr:zAsyncAdaptedQueue.put_nowaitsQ�� "� �K� "� "�4� (� (� (� (� (��� � "� "� "��&�&�c� !����� "���s��A�<�ATNr;r<r=c�|�|s|�|��S |�B|�tj|j�|��|����dS|�|j�|����dS#tjtjf$r}t��|�d}~wwxYwr') r:r}r��wait_forr�r?r�� TimeoutErrorr)r)r6r;r<r�s rr?zAsyncAdaptedQueue.puts���� )��?�?�4�(�(� (� "��"�� � �G�,�T�[�_�_�T�-B�-B�G�L�L�M�M�M�M�M�� � �D�K�O�O�D�1�1�2�2�2�2�2���!�7�#7�8� "� "� "��&�&�c� !����� "���s�AB �-B � B;�'B6�6B;c�� |j���S#tj$r}t ��|�d}~wwxYwr')r�rAr�� QueueEmptyr)r)r�s rrAzAsyncAdaptedQueue.get_nowait+sI�� #��;�)�)�+�+� +���!� #� #� #��'�'�s� "����� #���s��>�9�>c�n�|s|���S |�?|�tj|j���|����S|�|j�����S#tjtjf$r}t��|�d}~wwxYwr') rAr}r�r�r�rCr�r�r)r)r;r<r�s rrCzAsyncAdaptedQueue.get1s���� %��?�?�$�$� $� #��"��{�{��$�T�[�_�_�%6�%6��@�@�����{�{�4�;�?�?�#4�#4�5�5�5���"�G�$8�9� #� #� #��'�'�s� "����� #���s�AB�+B�B4� B/�/B4)rzr{r+rrDrErF)r+r�rHrIrJrKrL)rrr�typing� TYPE_CHECKING� staticmethodr}rr*r0r3r5rr�r:r?rArCrrrryry�s������ ��*� �8�8�8� ��8�8���j�)�)�������#�#�#�#�"�"�"�#�#�#�������� "�"�"�"�HL� "� "� "� "� "�#�#�#�#� #� #� #� #� #� #� #rryc�6�eZdZejs ee��ZdSdS)�FallbackAsyncAdaptedQueueN)rrrr�r�r�r r}rrrr�r�@s2������ � �.���n�-�-����.�.rr�)r� __future__rr�� collectionsrrRrrdr�rrrr r r � concurrencyr r� langhelpersrr�__all__� Exceptionrrr!rryr�rrr�<module>r�sR�� � �#�"�"�"�"�"��������������������� � � � �������������������������������������'�'�'�'�'�'�#�#�#�#�#�#�*�*�*�*�*�*� �W�T������ $� $� $�� � � � � �I� � � �  � � � � �9� � � � $�$�$�$�$�'�"�+�$�$�$�<W(�W(�W(�W(�W(�K��O�W(�W(�W(�tM#�M#�M#�M#�M#� �B��M#�M#�M#�`.�.�.�.�.� 1�"� 5�.�.�.�.�.r
Memory