Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
asyncio.cpython-313.pyc174 linesDownload Raw Back to __pycache__
1�

2�j�8��,�SrSSKJr SSKrSSKrSSKrSSKrSSKrSSKJ	r	 SSK3Jr SSKJ
r
 SSKJrJrJrJr SS	KJrJrJrJr SS4KJr SSKJr SSKJr SS
KJr \(a3SSK r SSK!J"r" SSK#J$r$ SSK%J&r& \ RNS:�aSSKJ(r( OSSK)J(r( \RT"S5r+\	"SS\55r,"SS\,\
5r-"SS5r.\"SSS9r/"SS\5r0"SS\\0S 9r1"S!S"\\15r2"S#S$\\15r3"S%S&\\15r4/S'Qr5g)(z1An asyncio-based implementation of the file lock.�)�annotationsN)�	dataclass)�iscoroutinefunction)�local)�
TYPE_CHECKING�Any�NoReturn�TypeVar�)�_UNSET_FILE_MODE�BaseFileLock�FileLockContext�FileLockMeta)�Timeout)�SoftFileLock)�UnixFileLock)�WindowsFileLock)�Callable)�futures)�
TracebackType)��)�Self�filelockc�D�\rSrSr%SrSrS\S'SrS\S'SrS	\S5'Sr	g)�AsyncFileLockContext�$zGA dataclass which holds the context for a ``BaseAsyncFileLock`` object.T�bool�run_in_executorN�futures.Executor | None�executor� asyncio.AbstractEventLoop | None�loop�)6�__name__�7__module__�__qualname__�__firstlineno__�__doc__r�__annotations__r!r#�__static_attributes__r$��BD:\code\apps\devtools\python\Lib\site-packages\filelock/asyncio.pyrr$s+��Q�!�O�T� �)-�H�%�,�.2�D�8*�1r,rc��\rSrSrSrSrg)�AsyncThreadLocalFileContext�2z8A thread local version of the ``FileLockContext`` class.r$N�r%r&r'r(r)r+r$r,r-r/r/2s��Br,r/c�F�\rSrSrSrSSjrS	SjrS9SjrSrg)�AsyncAcquireReturnProxy�6zDA context-aware object that will release the lock file when exiting.c��Xlg�N��lock)�selfr8s  r-�__init__� AsyncAcquireReturnProxy.__init__9s���	r,c��"# �UR$7fr6r7�r9s r-�10__aenter__�"AsyncAcquireReturnProxy.__aenter__<s����y�y��s�
c��T# �URR5IShv�N gN7fr6)r8�release�r9�exc_type�	exc_value�	tracebacks    r-�	__aexit__�!AsyncAcquireReturnProxy.__aexit__?s����i�i���!�!�!�s�(�&�(r7N)r8�BaseAsyncFileLock�return�None)rIrH�rC�type[BaseException] | NonerD�BaseException | NonerEzTracebackType | NonerIrJ)	r%r&r'r(r)r:r>rFr+r$r,r-r3r36s:��N���"�,�"�(�"�(�	"�1112�"r,r3�_ATrH)�boundc	�|^�\rSrSrS\S4SSSSSSSS.S13U4SjjjjrS	rU=r$)�AsyncFileLockMeta�K�����FT皙�����?N��blocking�is_singleton�
poll_interval�lifetimer#rr!c�h>�U(aU14(a
Sn[U5e[T
U]	UUUUUUUUU	U15US9$)Nz:run_in_executor is not supported when thread_local is True)�	lock_file�timeout�mode�thread_localrVrWrXrYr#rr!)�16ValueError�super�__call__)�clsr[r\r]r^rVrWrXrYr#rr!�msg�	__class__s             �r-ra�AsyncFileLockMeta.__call__LsQ����O�N�C��S�/�!��w�����%��%�'���+�� �17�	18r,r$)rbz	type[_AT]r[�str | os.PathLike[str]r\�floatr]�intr^rrVrrWrrXrgrY�float | Noner#r"rrr!r rIrN)r%r&r'r(rrar+�
__classcell__)rds@r-rQrQKs�����$�"�19��"�#�!%�15� $�,0�20�
�21�)�22��23��	24�25�26��27��28��29��30�/�31��32�*�33�34
�35�36r,rQc	�j�\rSrSrSrS\S4SSSSSSSS.SS	jjjr\SS37j5r\SSj5r	\	RSSj5r	\SS
j5rSSSS.SSjjjrSS Sjjr
S!SjrS"SjrS#SjrS$SjrS%SjrS&SjrSrg)'rH�mzD38Base class for asynchronous file locks.39 40.. versionadded:: 3.15.041 42rSFTrTNrUc43��X@lX`l[R"U5UUUUUU	U44US.	nU(a[O[45"S0UD6Ulg)a�46Create a new lock object.47 48:param lock_file: path to the file49:param timeout: default timeout when acquiring the lock, in seconds. It will be used as fallback value in the50    acquire method, if no timeout value (``None``) is given. If you want to disable the timeout, set it to a51    negative value. A timeout of 0 means that there is exactly one attempt to acquire the file lock.52:param mode: file permissions for the lockfile. When not specified, the OS controls permissions via umask and53    default ACLs, preserving POSIX default ACL inheritance in shared directories.54:param thread_local: Whether this object's internal context should be thread local or not. If this is set to55    ``False`` then the lock will be reentrant across threads.56:param blocking: whether the lock should be blocking or not57:param is_singleton: If this is set to ``True`` then only one instance of this class will be created per lock58    file. This is useful if you want to use the lock object for reentrant locking without needing to pass the59    same object around.60:param poll_interval: default interval for polling the lock file, in seconds. It will be used as fallback value61    in the acquire method, if no poll_interval value (``None``) is given.62:param lifetime: maximum time in seconds a lock can be held before it is considered expired. When set, a waiting63    process will break a lock whose file modification time is older than ``lifetime`` seconds. ``None`` (the64    default) means locks never expire.65:param loop: The event loop to use. If not specified, the running event loop will be used.66:param run_in_executor: If this is set to ``True`` then the lock will be acquired in an executor.67:param executor: The executor to use. If not specified, the default executor will be used.68 69)	r[r\r]rVrXrYr#rr!Nr$)�_is_thread_local�
_is_singleton�os�fspathr/r�_context)
r9r[r\r]r^rVrWrXrYr#rr!�kwargss
             r-r:�BaseAsyncFileLock.__init__us_��P!-��)��70���9�-��� �*� ��.� �71"72��O[�/J�`t�/t�/73��/74��
r,c�.�URR$)z":returns: whether run in executor.)rrrr=s r-r�!BaseAsyncFileLock.run_in_executor�s���}�}�,�,�,r,c�.�URR$)z:returns: the executor.�rrr!r=s r-r!�BaseAsyncFileLock.executor�s���}�}�%�%�%r,c�$�XRlg)z[75Change the executor.76 77:param futures.Executor | None value: the new executor or ``None``78 79Nrx)r9�values  r-r!ry�s��"'�
�
�r,c�.�URR$)z:returns: the event loop.)rrr#r=s r-r#�BaseAsyncFileLock.loop�s���}�}�!�!�!r,)rV�cancel_checkc	��# �UcURRnUcURRnUcURRnUR=RS-
sl[U5nURn[R"5nUR(dIUR5 [RSXV5 URUR5IShv�N UR(a[RSXV5 O\URUUUUUUS9(a[!U5eSn[RX�Xb5 ["R$"U5IShv�N M�[+US9$N�N![&a4 [)SURRS-805URlef=f7f)	a�81Try to acquire the file lock.82 83:param timeout: maximum wait time for acquiring the lock, ``None`` means use the default84    :attr:`~BaseFileLock.timeout` is and if ``timeout < 0``, there is no timeout and this method will block85    until the lock could be acquired86:param poll_interval: interval of trying to acquire the lock file, ``None`` means use the default87    :attr:`~BaseFileLock.poll_interval`88:param blocking: defaults to True. If False, function will return immediately if it cannot obtain a lock on the89    first attempt. Otherwise, this method will block until the timeout expires or the lock is acquired.90:param cancel_check: a callable returning ``True`` when the acquisition should be canceled. Checked on each poll91    iteration. When triggered, raises :class:`~Timeout` just like an expired timeout.92 93:returns: a context object that will unlock the file when the context is exited94 95:raises Timeout: if fails to acquire lock within the timeout period96 97.. code-block:: python98 99    # You can use this method in the context manager (recommended)100    with lock.acquire():101        pass102 103    # Or use an equivalent try-finally construct:104    lock.acquire()105    try:106        pass107    finally:108        lock.release()109 110Nrz#Attempting to acquire lock %s on %szLock %s acquired on %s)rVr~r\�111start_timez2Lock %s not acquired on %s, waiting %s seconds ...rr7)rrr\rVrX�lock_counter�idr[�time�perf_counter�	is_locked�_try_break_expired_lock�_LOGGER�debug�_run_internal_method�_acquire�_check_give_upr�asyncio�sleep�
BaseException�maxr3)	r9r\rXrVr~�lock_id�
lock_filenamer�rcs	         r-�acquire�BaseAsyncFileLock.acquire�s���P�?��m�m�+�+�G����}�}�-�-�H�� � �M�M�7�7�M�	
�
�
�"�"�a�'�"��T�(�����
��&�&�(�112�	���~�~��0�0�2��M�M�"G��`��3�3�D�M�M�B�B�B��>�>��M�M�":�G�S���&�&��!�%�!-�#�)�
'��"�-�0�0�J���
�
�c�M�I��m�m�M�2�2�2�'�.'�D�1�1�'C�3���	�),�Q��
�
�0J�0J�Q�0N�)O�D�M�M�&��	�sP�BG�AF�0F�1+F�G�AF�2F�3F�9	G�F�F�>G�Gc��# �UR(a�UR=RS-slURRS:XdU(aw[U5URp2[113R
SX#5 URUR5IShv�N SURl[114R
SX#5 gggN.7f)z�115Release the file lock. The lock is only completely released when the lock counter reaches 0. The lock file116itself is not automatically deleted.117 118:param force: If true, the lock counter is ignored and the lock is released in every case.119 120rrz#Attempting to release lock %s on %sNzLock %s released on %s)	r�rrr�r�r[r�r�r��_release)r9�forcer�r�s    r-rA�BaseAsyncFileLock.releases�����>�>��M�M�&�&�!�+�&��}�}�)�)�Q�.�%�)+�D��4�>�>���
�
�C�W�\��/�/��
�
�>�>�>�-.��
�
�*��
�
�6��O�
38��?�s�BC�C
�/Cc���# �[U5(aU"5IShv�N gUR(a8[R"5RURU5IShv�N gU"5 gNVN7fr6)rrr��get_running_loopr!)r9�methods  r-r��&BaseAsyncFileLock._run_internal_method.sR����v�&�&��(�N�N�
�
!�
!��*�*�,�<�<�T�]�]�F�S�S�S��H�	
�S�s"�A8�A4�AA8�&A6�'A8�6A8c��Sn[U5e)zTSync context manager entry is not supported because lock acquisition is a coroutine.�dUse `async with` — acquire/release are coroutines and cannot be awaited in a sync context manager.��NotImplementedError)r9rcs  r-�	__enter__�BaseAsyncFileLock.__enter__6s��t��!�#�&�&r,c��Sn[U5e)zOSync context manager exit is not supported because lock release is a coroutine.r�r�)r9rCrDrErcs     r-�__exit__�BaseAsyncFileLock.__exit__;s��u��!�#�&�&r,c��B# �UR5IShv�N U$N7f)z/121Acquire the lock.122 123:returns: the lock object124 125N)r�r=s r-r>�BaseAsyncFileLock.__aenter__Es ����l�l�n�����	�s���c��@# �UR5IShv�N gN7f)z�126Release the lock.127 128:param exc_type: the exception type if raised129:param exc_value: the exception value if raised130:param traceback: the exception traceback if raised131 132N)rArBs    r-rF�BaseAsyncFileLock.__aexit__Os����l�l�n���s���c�.�[R"[5 [R"5nUc133SSS5 gUR5(dURURSS95 OURURSS95 SSS5 g![134a_ URR(a?URRR5(dURROSnN�f=f!,(df   g=f)uRRelease on deletion — safe to call during GC even when no event loop is running.NT)r�)
�135contextlib�suppress�	Exceptionr�r��RuntimeErrorrrr#�	is_closed�136is_running�run_until_completerA�create_task)r9r#s  r-�__del__�BaseAsyncFileLock.__del___s���
�
 �
 ��
+�
q��/�/�1���|��,�
+��?�?�$�$��'�'����4��(@�A�� � ����D��!9�:�,�
+�� �
q�-1�]�]�-?�-?��
�
�HZ�HZ�Hd�Hd�Hf�Hf�t�}�}�)�)�lp��
q��,�
+�s4�D�B�D�AD�A&D�D�D�D�137D)rrrorn)r[rfr\rgr]rhr^rrVrrWrrXrgrYrir#r"rrr!r rIrJ)rIr)rIr )r{r rIrJ)rIr")NN)138r\rirXrirVzbool | Noner~zCallable[[], bool] | NonerIr3)F)r�rrIrJ)r�zCallable[[], Any]rIrJ)rIr	)rCrLrDrMrE�objectrIrJ)rIrrK)rIrJ)r%r&r'r(r)rr:�propertyrr!�setterr#r�rAr�r�r�r>rFr�r+r$r,r-rHrHms�����$�"�:139��"�#�!%�15� $�,0�:140�)�:141��:142��	:143�144�:145��:146��:147��:148��:149�/�:150��:151�*�:152�153�:154�x�-��-��&��&��_�_�'��'��"��"�!%�&*�O2�155!%�26�
O2��O2�$�O2�156�O2�0�
O2�157!�O2�bP�&�'�158'�,�'�(�'��	'�159160�'���,��(��(�	�161162�� 
;r,)�	metaclassc��\rSrSrSrSrg)�AsyncSoftFileLockioz.Simply watches the existence of the lock file.r$Nr1r$r,r-r�r�os��8r,r�c��\rSrSrSrSrg)�AsyncUnixFileLockiszHUses the :func:`fcntl.flock` to hard lock the lock file on unix systems.r$Nr1r$r,r-r�r�ss��Rr,r�c��\rSrSrSrSrg)�AsyncWindowsFileLockiwzNUses the :func:`msvcrt.locking` to hard lock the lock file on windows systems.r$Nr1r$r,r-r�r�ws��Xr,r�)r3r�r�r�rH)6r)�163__future__rr�r��loggingrpr��dataclassesr�inspectr�	threadingr�typingrrr	r164�_apirr
rr�_errorr�_softr�_unixr�_windowsr�sys�collections.abcr�165concurrentr�typesr�version_infor�typing_extensions�	getLoggerr�rr/r3rNrQrHr�r�r��__all__r$r,r-�<module>r�s��7�"����	��!�'��8�8�O�O����%���(�"�#�166���7�"��*��167�168�J�169'���1702�?�1712��1722�C�"6��C�"�"�$�e�.�/��173��174�D;��0A�;�D9��&7�9�S��&7�S�Y�?�,=�Y��r,
codekingpro/portable-devtools · Team Ai