� L�gO��Z�ddlZddlZddlZddlZddlZddlmZddlmZddl m Z m Z m Z m Z ddlmZeje��Ze��ZGd�d��ZGd�d ��ZGd �d ��Zd �ZejD],Zeeeje�ej�����-dS) �N)�Enum)� TracebackType)�Callable�Optional�Set�Type)� serializersc��eZdZUe��Zeedefed<e d���Z e d���Z e d���Z e d d���Z e d���ZdS) �API.�CMDSc�D�tj�|��|S�N)r r �add��cls�funcs �]/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/aiocache/base.py�registerz API.registers�� �� � �T����� �c�D�tj�|��dSr)r r �discardrs r� unregisterzAPI.unregisters�� ���������rc�T���d�tj����d���fd� ��}|S)a� This decorator sets a maximum timeout for a coroutine to execute. The timeout can be both set in the ``self.timeout`` attribute or in the ``timeout`` kwarg of the function call. I.e if you have a function ``get(self, key)``, if its decorated with this decorator, you will be able to call it with ``await get(self, "my_key", timeout=4)``. Use 0 or None to disable the timeout. �NOT_SET)�timeoutc���K�|�kr|jn|}|dks|��|g|�Ri|���d{V��Stj�|g|�Ri|��|���d{V��S)Nr)r�asyncio�wait_for)�selfr�args�kwargsrrs ��r�_timeoutzAPI.timeout.<locals>._timeout+s������&-��&8�&8�d�l�l�g�G��!�|�|�w��!�T�$�8��8�8�8��8�8�8�8�8�8�8�8�8� �)�$�$�t�*E�d�*E�*E�*E�f�*E�*E�w�O�O�O�O�O�O�O�O� Or�� functools�wraps)rrr"rs ` @rrz API.timeoutsZ������ ��� � �07� P� P� P� P� P� P� P� � � P� �rNc����fd�}|S)z� Use this decorator to be able to fake the return of the function by setting the ``AIOCACHE_DISABLE`` environment variable c�J���tj�����fd���}|S)Nc��X�K�tjd��dkr�S�|i|���d{V��S)N�AIOCACHE_DISABLE�1)�os�getenv)r r!� fake_returnrs ��r�_enabledz7API.aiocache_enabled.<locals>.enabled.<locals>._enabled<sJ������9�/�0�0�C�7�7�&�&�!�T�4�2�6�2�2�2�2�2�2�2�2�2rr#)rr.r-s` �r�enabledz%API.aiocache_enabled.<locals>.enabled;s>���� �_�T� "� "� 3� 3� 3� 3� 3�#� "� 3� �Or�)rr-r/s ` r�aiocache_enabledzAPI.aiocache_enabled4s#��� � � � � ��rc�F��tj����fd���}|S)Nc���K�tj��}|jD]:}t|d��j����|g|�Ri|���d{V���;�|g|�Ri|���d{V��}tj��}|jD]@}t|d��j����|g|�R||z |d�|���d{V���A|S)Nzpre_{}zpost_{})�took�ret)�time� monotonic�plugins�getattr�format�__name__)rr r!�start�pluginr5�endrs �r�_pluginszAPI.plugins.<locals>._pluginsHsG������N�$�$�E��,� ]� ]��E�g�f�h�o�o�d�m�&D�&D�E�E�d�\�T�\�\�\�U[�\�\�\�\�\�\�\�\�\�\���T�3�D�3�3�3�F�3�3�3�3�3�3�3�3�C��.�"�"�C��,� � ��F�g�f�i�&6�&6�t�}�&E�&E�F�F������&)�E�k�s���>D������������Jrr#)rrr?s ` rr8z API.pluginsFs8��� ��� � � � � � � � � ��rr)r;� __module__� __qualname__�setr rr�object�__annotations__� classmethodrrrr1r8r0rrr r s��������'*�s�u�u�D�#�h�s�F�{�#� $�,�,�,�����[������[������[��(�����[��"����[���rr c ���eZdZUdZeed< d6d�Zed���Zej d���Zed���Z e j d ���Z e j e � d � ��e je j edddfd ���������Zd7d �Ze j e � ��e je j d8d���������Zd7d�Zd9d�Ze j e � g� ��e je j d:d���������Zd7d�Ze j e � d � ��e je j eddddfd���������Zd;d�Ze j e � d � ��e je j edddfd���������Zd7d�Ze j e � d� ��e je j d;d���������Zd7d�Ze j e � d� ��e je j d;d���������Zd7d�Ze j e � d� ��e je j d<d���������Zd7d �Z e j e � d� ��e je j d;d!���������Z!d7d"�Z"e j e � d � ��e je j d;d#���������Z#d7d$�Z$e j e � ��e je j dd%�d&���������Z%d'�Z&d(�Z'e jdd%�d)���Z(d*�Z)d7d+�Z*d,�Z+d-�Z,d.�Z-d/�Z.d0�Z/d1e0e1e2d2e0e2d3e0e3d4dfd5�Z4dS)=� BaseCachea Base class that agregates the common logic for the different caches that may exist. Cache related available options are: :param serializer: obj derived from :class:`aiocache.serializers.BaseSerializer`. Default is :class:`aiocache.serializers.StringSerializer`. :param plugins: list of :class:`aiocache.plugins.BasePlugin` derived classes. Default is empty list. :param namespace: string to use as default prefix for the key used in all operations of the backend. Default is None :param key_builder: alternative callable to build the key. Receives the key and the namespace as params and should return something that can be used as key by the underlying backend. :param timeout: int or float in seconds specifying maximum timeout for the operations to last. By default its 5. Use 0 or None if you want to disable it. :param ttl: int the expiration time in seconds to use as a default in all operations of the backend. It can be overriden in the specific calls. �NAMEN�c���|�t|��n||_||_|�t|��n||_|p|j|_d|_|ptj��|_ d|_ |pg|_ dSr) �floatr� namespace�ttl� _build_key� build_key� _serializerr �StringSerializer� serializerr?r8)rrRr8rL� key_builderrrMs r�__init__zBaseCache.__init__osw��*1�)<�u�W�~�~�~�'�� �"���!$��5��:�:�:�c���$�7��������$�F� �(D�(F�(F����� ��}�"�� � � rc��|jSr�rP�rs rrRzBaseCache.serializer}s ����rc��||_dSrrV�r�values rrRzBaseCache.serializer�s�� ����rc��|jSr�r?rWs rr8zBaseCache.plugins�s ���}�rc��||_dSrr\rYs rr8zBaseCache.plugins�s ���� � � rT)r-c��hK�tj��}|p |jj}|�|n|j} |�|| ���} |�| ||��|�|��|����d{V��t� d| dtj��|z ��dS)a0 Stores the value in the given key with ttl if specified. Raises an error if the key already exists. :param key: str :param value: obj :param ttl: int the expiration time in seconds. Due to memcached restrictions if you want compatibility use int. In case you need miliseconds, redis and memory support float ttls :param dumps_fn: callable alternative to use as dumps function :param namespace: str alternative namespace to use :param timeout: int or float in seconds specifying maximum timeout for the operations to last :returns: True if key is inserted :raises: - ValueError if key already exists - :class:`asyncio.TimeoutError` if it lasts more than self.timeout N�rL�rM�_connzADD %s %s (%.4f)sT) r6r7rP�dumpsrLrO�_add�_get_ttl�logger�debug) r�keyrZrM�dumps_fnrLrar<rb�ns�ns_keys rrz BaseCache.add�s�����.�� � ���2�D�,�2��#�/�Y�Y�T�^������r��2�2���i�i����e� � �$�-�-��2D�2D�E�i�R�R�R�R�R�R�R�R�R�� � �(�&�$���8H�8H�5�8P�Q�Q�Q��trc��"K�t���r��NotImplementedError)rrgrZrMras rrczBaseCache._add������!�#�#�#rc��`K�tj��}|p |jj}|�|n|j}|�||���} ||�| |jj|����d{V����} t� d| | dutj��|z ��| �| n|S)a Get a value from the cache. Returns default if not found. :param key: str :param default: obj to return when key is not found :param loads_fn: callable alternative to use as loads function :param namespace: str alternative namespace to use :param timeout: int or float in seconds specifying maximum timeout for the operations to last :returns: obj loaded :raises: :class:`asyncio.TimeoutError` if it lasts more than self.timeout Nr_��encodingrazGET %s %s (%.4f)s) r6r7rP�loadsrLrO�_getrRrqrerf) rrg�default�loads_fnrLrar<rrrirjrZs r�getz BaseCache.get�s�����"�� � ���2�D�,�2��#�/�Y�Y�T�^������r��2�2����D�I�I�f�t��7O�W\�I�]�]�]�]�]�]�]�]�^�^��� � �(�&�%�t�2C�T�^�EU�EU�X]�E]�^�^�^��)�u�u�w�6rc��"K�t���rrl�rrgrqras rrszBaseCache._get�rnr�utf-8c��"K�t���rrlrxs r�_getszBaseCache._gets�rnrc��~��� K�tj��}|p �jj�|�|n�j� � �fd�|D��}�fd���|�jj|����d{V��D��}t� d|td�|D����tj��|z ��|S)a� Get multiple values from the cache, values not found are Nones. :param keys: list of str :param loads_fn: callable alternative to use as loads function :param namespace: str alternative namespace to use :param timeout: int or float in seconds specifying maximum timeout for the operations to last :returns: list of objs :raises: :class:`asyncio.TimeoutError` if it lasts more than self.timeout Nc�>��g|]}��|������S)r_)rO)�.0rgrirs ��r� <listcomp>z'BaseCache.multi_get.<locals>.<listcomp>�s)���E�E�E��4�>�>�#��>�4�4�E�E�Erc�&��g|] }�|����Sr0r0)r~rZrrs �rrz'BaseCache.multi_get.<locals>.<listcomp>�s1��� � � �� �E�%�L�L� � � rrpzMULTI_GET %s %d (%.4f)sc��g|]}|�|��Srr0)r~rZs rrz'BaseCache.multi_get.<locals>.<listcomp>�s��@�@�@�5�e�.?��.?�.?�.?r) r6r7rPrrrL� _multi_getrRrqrerf�len) r�keysrurLrar<�ns_keys�valuesrrris ` @@r� multi_getzBaseCache.multi_get�s������� �� � ���2�D�,�2��#�/�Y�Y�T�^��E�E�E�E�E��E�E�E�� � � � �#����$�/�":�%� /� � ������� � � �� � � � %� � �@�@�F�@�@�@� A� A� �N� � �u� $�  � � � � rc��"K�t���rrl)rr�rqras rr�zBaseCache._multi_get�rnrc��jK�tj��}|p |jj} |�|n|j} |�|| ���} |�| | |��|�|��||����d{V��} t� d| dtj��|z ��| S)a� Stores the value in the given key with ttl if specified :param key: str :param value: obj :param ttl: int the expiration time in seconds. Due to memcached restrictions if you want compatibility use int. In case you need miliseconds, redis and memory support float ttls :param dumps_fn: callable alternative to use as dumps function :param namespace: str alternative namespace to use :param timeout: int or float in seconds specifying maximum timeout for the operations to last :returns: True if the value was set :raises: :class:`asyncio.TimeoutError` if it lasts more than self.timeout Nr_)rM� _cas_tokenrazSET %s %d (%.4f)sT) r6r7rPrbrLrO�_setrdrerf) rrgrZrMrhrLr�rar<rbrirj�ress rrBz BaseCache.set�s�����,�� � ���2�D�,�2��#�/�Y�Y�T�^������r��2�2���I�I� �E�E�%�L�L�d�m�m�C�&8�&8�Z�W\�� � � � � � � � �� � � �(�&�$���8H�8H�5�8P�Q�Q�Q�� rc��"K�t���rrl)rrgrZrMr�ras rr�zBaseCache._setrnrc���K�tj��}|p |jj}|�|n|j}g} |D]:\} } | �|�| |���|| ��f���;|�| |�|��|����d{V��t� dd�| D��t| ��tj��|z ��dS)a� Stores multiple values in the given keys. :param pairs: list of two element iterables. First is key and second is value :param ttl: int the expiration time in seconds. Due to memcached restrictions if you want compatibility use int. In case you need miliseconds, redis and memory support float ttls :param dumps_fn: callable alternative to use as dumps function :param namespace: str alternative namespace to use :param timeout: int or float in seconds specifying maximum timeout for the operations to last :returns: True :raises: :class:`asyncio.TimeoutError` if it lasts more than self.timeout Nr_r`zMULTI_SET %s %d (%.4f)sc��g|]\}}|��Sr0r0)r~rgrZs rrz'BaseCache.multi_set.<locals>.<listcomp>=s�� -� -� -�Z�S�%�S� -� -� -rT) r6r7rPrbrL�appendrO� _multi_setrdrerfr�) r�pairsrMrhrLrar<rbri� tmp_pairsrgrZs r� multi_setzBaseCache.multi_sets����&�� � ���2�D�,�2��#�/�Y�Y�T�^��� �� P� P�J�C�� � � �d�n�n�S�B�n�?�?���u���N� O� O� O� O��o�o�i�T�]�]�3�-?�-?�u�o�M�M�M�M�M�M�M�M�M�� � � %� -� -�9� -� -� -� � �N�N� �N� � �u� $�  � � � �trc��"K�t���rrl)rr�rMras rr�zBaseCache._multi_setCrnrrc��K�tj��}|�|n|j}|�||���}|�||����d{V��}t �d||tj��|z ��|S)a{ Deletes the given key. :param key: Key to be deleted :param namespace: str alternative namespace to use :param timeout: int or float in seconds specifying maximum timeout for the operations to last :returns: int number of deleted keys :raises: :class:`asyncio.TimeoutError` if it lasts more than self.timeout Nr_�razDELETE %s %d (%.4f)s)r6r7rLrO�_deletererf�rrgrLrar<rirjr5s r�deletezBaseCache.deleteF������� � ��#�/�Y�Y�T�^������r��2�2���L�L��u�L�5�5�5�5�5�5�5�5��� � �+�V�S�$�.�:J�:J�U�:R�S�S�S�� rc��"K�t���rrl�rrgras rr�zBaseCache._delete\rnrFc��K�tj��}|�|n|j}|�||���}|�||����d{V��}t �d||tj��|z ��|S)a� Check key exists in the cache. :param key: str key to check :param namespace: str alternative namespace to use :param timeout: int or float in seconds specifying maximum timeout for the operations to last :returns: True if key exists otherwise False :raises: :class:`asyncio.TimeoutError` if it lasts more than self.timeout Nr_r�zEXISTS %s %d (%.4f)s)r6r7rLrO�_existsrerfr�s r�existszBaseCache.exists_r�rc��"K�t���rrlr�s rr�zBaseCache._existsurnr�c��K�tj��}|�|n|j}|�||���}|�|||����d{V��}t �d||tj��|z ��|S)a~ Increments value stored in key by delta (can be negative). If key doesn't exist, it creates the key with delta as value. :param key: str key to check :param delta: int amount to increment/decrement :param namespace: str alternative namespace to use :param timeout: int or float in seconds specifying maximum timeout for the operations to last :returns: Value of the key once incremented. -1 if key is not found. :raises: :class:`asyncio.TimeoutError` if it lasts more than self.timeout :raises: :class:`TypeError` if value is not incrementable Nr_r�zINCREMENT %s %d (%.4f)s)r6r7rLrO� _incrementrerf) rrg�deltarLrar<rirjr5s r� incrementzBaseCache.incrementxs�����$�� � ��#�/�Y�Y�T�^������r��2�2���O�O�F�E��O�?�?�?�?�?�?�?�?��� � �.���T�^�=M�=M�PU�=U�V�V�V�� rc��"K�t���rrl)rrgr�ras rr�zBaseCache._increment�rnrc��K�tj��}|�|n|j}|�||���}|�|||����d{V��}t �d||tj��|z ��|S)a Set the ttl to the given key. By setting it to 0, it will disable it :param key: str key to expire :param ttl: int number of seconds for expiration. If 0, ttl is disabled :param namespace: str alternative namespace to use :param timeout: int or float in seconds specifying maximum timeout for the operations to last :returns: True if set, False if key is not found :raises: :class:`asyncio.TimeoutError` if it lasts more than self.timeout Nr_r�zEXPIRE %s %d (%.4f)s)r6r7rLrO�_expirererf) rrgrMrLrar<rirjr5s r�expirezBaseCache.expire�s����� �� � ��#�/�Y�Y�T�^������r��2�2���L�L���E�L�:�:�:�:�:�:�:�:��� � �+�V�S�$�.�:J�:J�U�:R�S�S�S�� rc��"K�t���rrl)rrgrMras rr�zBaseCache._expire�rnrc���K�tj��}|�||����d{V��}t�d||tj��|z ��|S)a� Clears the cache in the cache namespace. If an alternative namespace is given, it will clear those ones instead. :param namespace: str alternative namespace to use :param timeout: int or float in seconds specifying maximum timeout for the operations to last :returns: True :raises: :class:`asyncio.TimeoutError` if it lasts more than self.timeout r�NzCLEAR %s %d (%.4f)s)r6r7�_clearrerf)rrLrar<r5s r�clearzBaseCache.clear�sg������ � ���K�K� ��K�7�7�7�7�7�7�7�7��� � �*�I�s�D�N�<L�<L�u�<T�U�U�U�� rc��"K�t���rrl)rrLras rr�zBaseCache._clear�rnrr�c���K�tj��}|j|g|�R|jj|d�|���d{V��}t �d|tj��|z ��|S)a: Send the raw command to the underlying client. Note that by using this CMD you will lose compatibility with other backends. Due to limitations with aiomcache client, args have to be provided as bytes. For rest of backends, str. :param command: str with the command. :param timeout: int or float in seconds specifying maximum timeout for the operations to last :returns: whatever the underlying client returns :raises: :class:`asyncio.TimeoutError` if it lasts more than self.timeout rpNz %s (%.4f)s)r6r7�_rawrRrqrerf)r�commandrar r!r<r5s r�rawz BaseCache.raw�s�����$�� � ���D�I� � �� � �%)�_�%=�U� � �NT� � � � � � � � �� � � �\�7�D�N�,<�,<�u�,D�E�E�E�� rc��"K�t���rrl)rr�r r!s rr�zBaseCache._raw�rnrc��"K�t���rrl)rrgrZs r�_redlock_releasezBaseCache._redlock_release�rnrc��K�tj��}|j|d|i|���d{V��}t�dtj��|z ��|S)a Perform any resource clean up necessary to exit the program safely. After closing, cmd execution is still possible but you will have to close again before exiting. :raises: :class:`asyncio.TimeoutError` if it lasts more than self.timeout raNz CLOSE (%.4f)s)r6r7�_closererf)rrar r!r<r5s r�closezBaseCache.close�sh������ � ���D�K��=�U�=�f�=�=�=�=�=�=�=�=��� � �_�d�n�&6�&6��&>�?�?�?�� rc�� K�dSrr0)rr r!s rr�zBaseCache._close�� ���� �rc��|�#d�|t|����S|j�(d�|jt|����S|S)Nz{}{})r:� _ensure_keyrL)rrgrLs rrNzBaseCache._build_key�sO�� � ��=�=��K��,<�,<�=�=� =� �>� %��=�=����S�1A�1A�B�B� B�� rc�&�|tur|n|jSr)�SENTINELrM)rrMs rrdzBaseCache._get_ttl�s����)�)�s�s�t�x�7rc� �t|��Sr)�_ConnrWs r�get_connectionzBaseCache.get_connection�s���T�{�{�rc�� K�|Srr0rWs r� acquire_connzBaseCache.acquire_conn� ����� rc�� K�dSrr0)r�conns r� release_connzBaseCache.release_connr�rc�� K�|Srr0rWs r� __aenter__zBaseCache.__aenter__r�r�exc_type�exc�tb�returnc��>K�|����d{V��dSr)r�)rr�r�r�s r� __aexit__zBaseCache.__aexit__ s.�����j�j�l�l���������r)NNNNrINr)NNNN)ryN)NNN)NN)r�NN)5r;r@rA�__doc__�strrDrT�propertyrR�setterr8r rr1rr�rrcrvrsr{r�r�rBr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rNrdr�r�r�r�rr� BaseExceptionrr�r0rrrGrGZsg���������$ �I�I�I�_c� %� %� %� %�� � ��X� ���!�!���!�����X�� �^����^�� �\����d��+�+��[��[�(0�4�4�W[�����[��[�,�+��\��:$�$�$�$� �\�������[��[�7�7�7��[��[����\�7�.$�$�$�$�$�$�$�$� �\����b��)�)��[��[�����[��[�*�)��\��@$�$�$�$� �\����d��+�+��[��[�&���RV�^b�����[��[�,�+��\��<$�$�$�$� �\����d��+�+��[��[�)1�D�D�X\�����[��[�,�+��\��B$�$�$�$� �\����a��(�(��[��[�����[��[�)�(��\��$$�$�$�$� �\����e��,�,��[��[�����[��[�-�,��\��$$�$�$�$� �\����a��(�(��[��[�����[��[�)�(��\��*$�$�$�$� �\����e��,�,��[��[�����[��[�-�,��\��&$�$�$�$� �\����d��+�+��[��[�����[��[�,�+��\�� $�$�$�$� �\�������[��[�.2������[��[����\��*$�$�$�$�$�$� �[�'+� � � � ��[� � � � �����8�8�8������� � � ����� ��m�!4�5�� �m� $��*2�=�*A�� ������rrGc�<�eZdZd�Zd�Zd�Zd�Zed���ZdS)r�c�"�||_d|_dSr)�_cachera)r�caches rrTz_Conn.__init__s���� ��� � � rc��RK�|j����d{V��|_|Sr)r�r�rarWs rr�z_Conn.__aenter__s2�����;�3�3�5�5�5�5�5�5�5�5�� �� rc��TK�|j�|j���d{V��dSr)r�r�ra)rr�� exc_value� tracebacks rr�z_Conn.__aexit__s6�����k�&�&�t�z�2�2�2�2�2�2�2�2�2�2�2rc�6�|j�|��Sr)r��__getattribute__)r�names r� __getattr__z_Conn.__getattr__s���{�+�+�D�1�1�1rc����fd�}|S)Nc��X�K�t|j���|d|ji|���d{V��S)Nra)r9r�ra)rr r!�cmd_names �r�_do_inject_connz+_Conn._inject_conn.<locals>._do_inject_conn#sB�����7����h�7�7��Z�T�Z�Z�SY�Z�Z�Z�Z�Z�Z�Z�Z� Zrr0)rr�r�s ` r� _inject_connz_Conn._inject_conn!s)��� [� [� [� [� [��rN) r;r@rArTr�r�r�rEr�r0rrr�r�sk������������3�3�3�2�2�2�����[���rr�c�>�t|t��r|jS|Sr)� isinstancerrZ)rgs rr�r�)s!���#�t�����y��� r)rr$�loggingr+r6�enumr�typesr�typingrrrr�aiocacher � getLoggerr;rerCr�r rGr�r�r �cmd�setattrr�r0rr�<module>r�s��������������� � � � � � � � �������������0�0�0�0�0�0�0�0�0�0�0�0� � � � � � � �� �8� $� $�� �6�8�8��E�E�E�E�E�E�E�E�Pu�u�u�u�u�u�u�u�p ��������.��� �8�C�C�C� �G�E�3�<��!3�!3�C�L�!A�!A�B�B�B�B�C�Cr
Memory