� u��g�0��,�dZddlmZddlZddlZddlZddlZddlZddlm Z ddl m Z ddl m Z mZmZmZmZddlmZmZmZdd lmZdd lmZdd lmZdd lmZe r(ddlZdd lm Z ddl!m"Z"ej#dkrddl m$Z$nddl%m$Z$ej&d��Z'e Gd�de����Z(Gd�de(e ��Z)Gd�d��Z*Gd�de��Z+Gd�dee+���Z,Gd�dee,��Z-Gd�d ee,��Z.Gd!�d"ee,��Z/gd#�Z0dS)$z1An asyncio-based implementation of the file lock.�)� annotationsN)� dataclass)�local)� TYPE_CHECKING�Any�Callable�NoReturn�cast�)� BaseFileLock�FileLockContext� FileLockMeta)�Timeout)� SoftFileLock)� UnixFileLock)�WindowsFileLock)�futures)� TracebackType)�� )�Self�filelockc�>�eZdZUdZdZded<dZded<dZded <dS) �AsyncFileLockContextzGA dataclass which holds the context for a ``BaseAsyncFileLock`` object.T�bool�run_in_executorN�futures.Executor | None�executor� asyncio.AbstractEventLoop | None�loop)�__name__� __module__� __qualname__�__doc__r�__annotations__rr ���`/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/filelock/asyncio.pyrr"sQ�������Q�Q�!�O� � � � �)-�H�,�,�,�,�.2�D�1�1�1�1�1�1r'rc��eZdZdZdS)�AsyncThreadLocalFileContextz8A thread local version of the ``FileLockContext`` class.N�r!r"r#r$r&r'r(r*r*0s������B�B�B�Br'r*c�*�eZdZdZdd�Zdd�Zdd�ZdS)�AsyncAcquireReturnProxyzDA context-aware object that will release the lock file when exiting.�lock�BaseAsyncFileLock�return�Nonec��||_dS�N�r.)�selfr.s r(�__init__z AsyncAcquireReturnProxy.__init__7s ���� � � r'c��K�|jSr3r4�r5s r(� __aenter__z"AsyncAcquireReturnProxy.__aenter__:s�����y�r'�exc_type�type[BaseException] | None� exc_value�BaseException | None� traceback�TracebackType | Nonec��HK�|j����d{V��dSr3)r.�release�r5r:r<r>s r(� __aexit__z!AsyncAcquireReturnProxy.__aexit__=s4���� �i���!�!�!�!�!�!�!�!�!�!�!r'N)r.r/r0r1)r0r/�r:r;r<r=r>r?r0r1)r!r"r#r$r6r9rCr&r'r(r-r-4sV������N�N���������"�"�"�"�"�"r'r-c�6��eZdZ ddddddd�d�fd�Z�xZS)�AsyncFileLockMeta������FTN��blocking� is_singletonr rr� lock_file�str | os.PathLike[str]�timeout�float�mode�int� thread_localrrJrKr rrrrr0r/c ���|r|rd} t| ���t���||||||||| �� � } td| ��S)Nz:run_in_executor is not supported when thread_local is True) rLrNrPrRrJrKr rrr/)� ValueError�super�__call__r ) �clsrLrNrPrRrJrKr rr�msg�instance� __class__s �r(rVzAsyncFileLockMeta.__call__Gsq��� � "�O� "�N�C��S�/�/� !��7�7�#�#����%��%��+��$�  �  ���'��2�2�2r'�rGrHF)rLrMrNrOrPrQrRrrJrrKrr rrrrrr0r/)r!r"r#rV� __classcell__)rZs@r(rFrFFsh���������"� 3��"�15� $�,0�3�3�3�3�3�3�3�3�3�3�3�3r'rFc���eZdZdZ d7dddddd�d8d�Zed9d���Zed:d���Zejd;d���Zed<d���Z d=dd �d>d%�Z d?d@d'�Z dAd*�Z dBd,�Z dCd.�ZdDd5�ZdEd6�ZdS)Fr/z'Base class for asynchronous file locks.rGrHFTNrIrLrMrNrOrPrQrRrrJrKr rrrrr0r1c��||_||_tj|��|||||| d�} |rtnt di| ��|_dS)a" Create a new lock object. :param lock_file: path to the file :param timeout: default timeout when acquiring the lock, in seconds. It will be used as fallback value in the acquire method, if no timeout value (``None``) is given. If you want to disable the timeout, set it to a negative value. A timeout of 0 means that there is exactly one attempt to acquire the file lock. :param mode: file permissions for the lockfile :param thread_local: Whether this object's internal context should be thread local or not. If this is set to ``False`` then the lock will be reentrant across threads. :param blocking: whether the lock should be blocking or not :param is_singleton: If this is set to ``True`` then only one instance of this class will be created per lock file. This is useful if you want to use the lock object for reentrant locking without needing to pass the same object around. :param loop: The event loop to use. If not specified, the running event loop will be used. :param run_in_executor: If this is set to ``True`` then the lock will be acquired in an executor. :param executor: The executor to use. If not specified, the default executor will be used. )rLrNrPrJr rrNr&)�_is_thread_local� _is_singleton�os�fspathr*r�_context) r5rLrNrPrRrJrKr rr�kwargss r(r6zBaseAsyncFileLock.__init__hsu��@!-���)��� ��9�-�-��� ��.� �" �" ��0u�l�/t�/J�/J�`t�/ �/ ��/ �/ �� � � r'c��|jjS)z"::return: whether run in executor.)rcrr8s r(rz!BaseAsyncFileLock.run_in_executor�s���}�,�,r'c��|jjS)z::return: the executor.�rcrr8s r(rzBaseAsyncFileLock.executor�s���}�%�%r'�valuec��||j_dS)z� Change the executor. :param value: the new executor or ``None`` :type value: futures.Executor | None Nrg)r5rhs r(rzBaseAsyncFileLock.executor�s��"'�� ���r'c��|jjS)z::return: the event loop.)rcr r8s r(r zBaseAsyncFileLock.loop�s���}�!�!r'皙�����?)rJ� float | None� poll_interval� bool | Noner-c��K�|� |jj}|� |jj}|jxjdz c_t |��}|j}t j��} |js<t� d||��|� |j ���d{V��|jrt� d||��n�|dur+t� d||��t|���d|cxkrt j��|z kr.nn+t� d ||��t|���d }t� ||||��tj|���d{V���� n6#t $r)t#d|jjdz ��|j_�wxYwt%|� ��S) aW Try to acquire the file lock. :param timeout: maximum wait time for acquiring the lock, ``None`` means use the default :attr:`~BaseFileLock.timeout` is and if ``timeout < 0``, there is no timeout and this method will block until the lock could be acquired :param poll_interval: interval of trying to acquire the lock file :param blocking: defaults to True. If False, function will return immediately if it cannot obtain a lock on the first attempt. Otherwise, this method will block until the timeout expires or the lock is acquired. :raises Timeout: if fails to acquire lock within the timeout period :return: a context object that will unlock the file when the context is exited .. code-block:: python # You can use this method in the context manager (recommended) with lock.acquire(): pass # Or use an equivalent try-finally construct: lock.acquire() try: pass finally: lock.release() Nr Tz#Attempting to acquire lock %s on %szLock %s acquired on %sFz+Failed to immediately acquire lock %s on %srz"Timeout on acquiring lock %s on %sz2Lock %s not acquired on %s, waiting %s seconds ...r4)rcrNrJ� lock_counter�idrL�time� perf_counter� is_locked�_LOGGER�debug�_run_internal_method�_acquirer�asyncio�sleep� BaseException�maxr-)r5rNrmrJ�lock_id� lock_filename� start_timerXs r(�acquirezBaseAsyncFileLock.acquire�s�����D �?��m�+�G� � ��}�-�H� � �"�"�a�'�"�"��T�(�(���� ��&�(�(� � � 3��~�C��M�M�"G��R_�`�`�`��3�3�D�M�B�B�B�B�B�B�B�B�B��>���M�M�":�G�]�S�S�S���u�$�$��M�M�"O�QX�Zg�h�h�h�!�-�0�0�0���B�B�B�B�$�"3�"5�"5� �"B�B�B�B�B�B��M�M�"F��Q^�_�_�_�!�-�0�0�0�J��� � �c�7�M�=�I�I�I��m�M�2�2�2�2�2�2�2�2�2� 3� ��� � � �),�Q�� �0J�Q�0N�)O�)O�D�M� &� � ����'�D�1�1�1�1s �D!F�3F3�forcec��bK�|jr�|jxjdzc_|jjdks|r~t|��|j}}t �d||��|�|j���d{V��d|j_t �d||��dSdSdS)a+ Releases the file lock. Please note, that the lock is only completely released, if the lock counter is 0. Also note, that the lock file itself is not automatically deleted. :param force: If true, the lock counter is ignored and the lock is released in every case/ r rz#Attempting to release lock %s on %sNzLock %s released on %s) rtrcrprqrLrurvrw�_release)r5r�r}r~s r(rAzBaseAsyncFileLock.release�s����� �>� P� �M� &� &�!� +� &� &��}�)�Q�.�.�%�.�)+�D���4�>���� � �C�W�m�\�\�\��/�/�� �>�>�>�>�>�>�>�>�>�-.�� �*�� � �6���O�O�O�O�O� P� P�/�.r'�method�Callable[[], Any]c���K�tj|��r|���d{V��dS|jr=|jptj��}|�|j|���d{V��dS|��dSr3)ry�iscoroutinefunctionrr �get_running_loopr)r5r�r s r(rwz&BaseAsyncFileLock._run_internal_method s����� � &�v� .� .� ��&�(�(�N�N�N�N�N�N�N�N�N� � !� ��9�:�� 8� :� :�D��&�&�t�}�f�=�=� =� =� =� =� =� =� =� =� =� �F�H�H�H�H�Hr'r c�$�d}t|���)z� Replace old __enter__ method to avoid using it. NOTE: DO NOT USE `with` FOR ASYNCIO LOCKS, USE `async with` INSTEAD. :return: none :rtype: NoReturn z>Do not use `with` for asyncio locks, use `async with` instead.)�NotImplementedError)r5rXs r(� __enter__zBaseAsyncFileLock.__enter__s��O��!�#�&�&�&r'rc��>K�|����d{V��|S)zF Acquire the lock. :return: the lock object N)r�r8s r(r9zBaseAsyncFileLock.__aenter__ s-�����l�l�n�n��������� r'r:r;r<r=r>r?c��>K�|����d{V��dS)z� Release the lock. :param exc_type: the exception type if raised :param exc_value: the exception value if raised :param traceback: the exception traceback if raised N)rArBs r(rCzBaseAsyncFileLock.__aexit__*s.�����l�l�n�n���������r'c�l�tjt��5|jpt j��}|���s*|�|�d�����n)|� |�d�����ddd��dS#1swxYwYdS)z'Called when the lock object is deleted.T)r�N) � contextlib�suppress� RuntimeErrorr ryr�� is_running�run_until_completerA� create_task)r5r s r(�__del__zBaseAsyncFileLock.__del__:s��� � �� .� .� ;� ;��9�:�� 8� :� :�D��?�?�$�$� ;��'�'�� � �4� �(@�(@�A�A�A�A�� � ����D��!9�!9�:�:�:�  ;� ;� ;� ;� ;� ;� ;� ;� ;� ;� ;� ;���� ;� ;� ;� ;� ;� ;s�BB)�)B-�0B-r[)rLrMrNrOrPrQrRrrJrrKrr rrrrrr0r1)r0r)r0r)rhrr0r1)r0r)Nrk)rNrlrmrOrJrnr0r-)F)r�rr0r1)r�r�r0r1)r0r )r0rrD)r0r1)r!r"r#r$r6�propertyrr�setterr r�rArwr�r9rCr�r&r'r(r/r/es�������1�1� ��"� 0 ��"�15� $�,0�0 �0 �0 �0 �0 �0 �d�-�-�-��X�-��&�&�&��X�&��_�'�'�'��_�'��"�"�"��X�"� !%�#�B2� !%� B2�B2�B2�B2�B2�B2�HP�P�P�P�P�&���� '� '� '� '��������� ;�;�;�;�;�;r'r/)� metaclassc��eZdZdZdS)�AsyncSoftFileLockz.Simply watches the existence of the lock file.Nr+r&r'r(r�r�Ds������8�8�8�8r'r�c��eZdZdZdS)�AsyncUnixFileLockzHUses the :func:`fcntl.flock` to hard lock the lock file on unix systems.Nr+r&r'r(r�r�Hs������R�R�R�Rr'r�c��eZdZdZdS)�AsyncWindowsFileLockzNUses the :func:`msvcrt.locking` to hard lock the lock file on windows systems.Nr+r&r'r(r�r�Ls������X�X�X�Xr'r�)r-r�r�r�r/)1r$� __future__rryr��loggingrarr� dataclassesr� threadingr�typingrrrr r �_apir r r�_errorr�_softr�_unixr�_windowsr�sys� concurrentr�typesr� version_infor�typing_extensions� getLoggerrurr*r-rFr/r�r�r��__all__r&r'r(�<module>r�s$��7�7�"�"�"�"�"�"������������� � � � � � � � �!�!�!�!�!�!�������?�?�?�?�?�?�?�?�?�?�?�?�?�?�=�=�=�=�=�=�=�=�=�=�������������������%�%�%�%�%�%��+��J�J�J�"�"�"�"�"�"�#�#�#�#�#�#� ��7�"�"��������*�*�*�*�*�*� �'� �J� '� '�� � 2� 2� 2� 2� 2�?� 2� 2� �� 2�C�C�C�C�C�"6��C�C�C�"�"�"�"�"�"�"�"�$3�3�3�3�3� �3�3�3�>\;�\;�\;�\;�\;� �0A�\;�\;�\;�\;�~9�9�9�9�9� �&7�9�9�9�S�S�S�S�S� �&7�S�S�S�Y�Y�Y�Y�Y�?�,=�Y�Y�Y� � � ���r'
Memory