
    ^j'                        U d Z ddlmZ ddlZddlZddlZddlZddlZddlm	Z	 ddl
mZ ddlmZ ddlmZmZmZmZmZ dd	lmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$ dd
l%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z- ddl.m/Z/ ddl0m1Z1 ddl2m3Z3 ddl4m5Z5 ddl6m7Z7 ddl8m9Z9 er8ddl:Z:ddl;m<Z<m=Z=m>Z>m?Z? ddl@mAZA ddlBmCZC e:j                  dk\  rddlmEZE nddlFmEZE  ej                  d      ZHdeId<   dZJdeId<   dZKdeId<   dZLdeId<   g ZMd eId!<    ed"d#$      ZN G d% d&e      ZO G d' d#eeO(      ZPe	 G d) d*e             ZQ G d+ d,eQe      ZR G d- d.      ZS G d/ d0e3eP      ZT G d1 d2e5eP      ZU G d3 d4e1eP      ZV G d5 d6e7eP      ZW G d7 d8e9eP      ZXg d9ZYy):z1An asyncio-based implementation of the file lock.    )annotationsN)	dataclass)iscoroutinefunction)local)TYPE_CHECKINGFinalNoReturnTypeVarcast   )_UNSET_FILE_MODEBaseFileLockCloseErrorPolicyContextErrorPolicyFileLockContextFileLockMeta_append_exception_context
_canonical_ExtraValue_fork_transition_grouped_errors_raise_body_and_release_raise_chained_errors_raise_cleanup_errors_raise_grouped_errors_register_fork_object)_AsyncTransitionGate _AsyncTransitionUnavailableError_BackendOutcome_capture_awaitable_capture_call_drain_future_future_result_wait_until_done)Timeout)SoftFileLease)SoftFileLock)StrictSoftFileLock)UnixFileLock)WindowsFileLock)	AwaitableCallable	CoroutineHashable)futures)TracebackType)      )SelffilelockzFinal[logging.Logger]_LOGGERz9lock release cancellation and backend release both failedz
Final[str]"_ASYNC_RELEASE_CANCELLATION_ERRORSz>context body, release cancellation, and backend release failed_ASYNC_CONTEXT_RELEASE_ERRORS$_filelock_async_release_cancellation'_ASYNC_RELEASE_CANCELLATION_MARKER_ATTRzFinal[list[None]]"_ASYNC_RELEASE_CANCELLATION_MARKER_ATBaseAsyncFileLock)boundc                       e Zd Zdedfddddddddddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d
 fd	Z xZS )AsyncFileLockMetaFT皙?Nchaindefaultblockingis_singletonpoll_intervallifetimecontext_error_policyclose_error_policyfallback_to_softpreserve_lock_fileon_acquiredlooprun_in_executorexecutorc                   |r|rd}t        |      t        |   di |i d|d|d|d|d|d|d|d	|d
|	d|
d|d|d|d|d|d|S )Nz:run_in_executor is not supported when thread_local is True	lock_filetimeoutmodethread_localrE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP    )
ValueErrorsuper__call__)clsrR   rS   rT   rU   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   kwargsmsg	__class__s                      [/var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/filelock/asyncio.pyrY   zAsyncFileLockMeta.__call__H   s    * ONCS/!w 


 
 	

 &
 
 &
 (
 
 "6
  2
 .
  2
 $
 
  ,!
" #
 	
    )&rZ   z	type[_AT]rR   str | os.PathLike[str]rS   floatrT   intrU   boolrE   rc   rF   rc   rG   ra   rH   float | NonerI   r   rJ   r   rK   rc   rL   rc   rM   Callable[[int], None] | NonerN    asyncio.AbstractEventLoop | NonerO   rc   rP   futures.Executor | Noner[   r   returnr;   )__name__
__module____qualname__r   rY   __classcell__)r]   s   @r^   r?   r?   G   s     $"*
 "#!%3:/8!%#(4815 $,0%*
*
)*
 *
 	*

 *
 *
 *
 *
 *
 1*
 -*
 *
 !*
 2*
  /!*
" #*
$ *%*
& '*
( 
)*
 *
r_   r?   c                  Z   e Zd ZU dZdZded<   dZded<   ed.d       Zd	e	d
fdd
dddddd
ddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d/dZ
ed0d       Zed1d       Zej                  d2d       Zed3d       Z	 	 d4ddd	 	 	 	 	 	 	 	 	 d5dZ	 	 	 	 	 	 	 	 	 	 	 	 d6dZ	 	 	 	 	 	 	 	 	 	 	 	 d7dZd8dZd9dZd:dZ	 d;	 	 	 	 	 	 	 	 	 d<dZd=d>dZd>dZd8d Z	 	 	 	 d?d!Zd@d"Zd8d#ZdAd$ZdBd%Zd8d&Zd8d'Z dCd(Z!	 	 	 	 	 	 	 	 dDd)Z"dEd*Z#	 	 	 	 	 	 	 	 dDd+Z$	 	 	 	 dFd,Z%d8d-Z&y)Gr<   zP
    Base class for asynchronous file locks.

    .. versionadded:: 3.15.0

    z'BaseAsyncFileLock instance in this taskstr_deadlock_holder_desc   rb   (_constructor_lifetime_warning_stacklevelc                 *    t        j                         S N)asynciocurrent_taskrV   r_   r^   _deadlock_scopez!BaseAsyncFileLock._deadlock_scope   s     ##%%r_   r@   FTrA   NrB   rC   rD   c               6   t        j                         | _        || _        || _        |	| _        |
| _        || _        || _        || _	        t               | _         |rt        nt        t        j                  |      ||||||||	      | _        t!        |        y)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. When not specified, the OS controls permissions via umask and
            default ACLs, preserving POSIX default ACL inheritance in shared directories.
        :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. When ``True`` (the default), **all fields of the
            lock's internal context are per-thread**, including the configuration values ``poll_interval``, ``timeout``,
            ``blocking``, ``mode``, and ``lifetime``. Setting one of these properties from one thread does not change
            the value seen by another thread; threads that did not perform the write continue to see the value supplied
            at construction time. If you need configuration values to be visible across threads, construct the lock
            with ``thread_local=False``.
        :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 poll_interval: default interval for polling the lock file, in seconds. It will be used as fallback value
            in the acquire method, if no poll_interval value (``None``) is given.
        :param lifetime: for :class:`AsyncSoftFileLock`, the age in seconds after which a waiting process may delete
            the marker, even while its holder remains alive. This legacy expiry mode does not provide strict mutual
            exclusion. ``None`` (the default) disables age-based expiry. Native OS locks (:class:`AsyncFileLock`)
            cannot be revoked by file age and ignore a non-``None`` ``lifetime`` with a warning.
        :param context_error_policy: how a context manager reconciles a failure in its body with a failure while
            releasing on exit. ``"chain"`` (the default) keeps Python's behavior: the release error propagates with the
            body error in its ``__context__``. ``"group"`` raises a :class:`BaseExceptionGroup` holding the body error
            first and the release error second, so neither hides the other.
        :param close_error_policy: for native locks (:class:`AsyncFileLock`), what to do with an ``os.close`` failure
            after the OS unlock has already committed. ``"default"`` keeps each platform's historical behavior,
            ``"raise"`` always propagates the ``OSError``, and ``"suppress"`` always ignores it.
        :param fallback_to_soft: for :class:`AsyncFileLock`, whether to fall back to soft existence locking when
            ``flock`` returns ``ENOSYS``. ``True`` (default) keeps the fallback; ``False`` propagates the error.
        :param preserve_lock_file: for native locks (:class:`AsyncFileLock`), whether filelock promises not to unlink
            the lock pathname on release. ``False`` (default) keeps each backend's cleanup; ``True`` keeps a stable file
            identity (Windows skips its unlink, Unix refuses the ``ENOSYS`` soft fallback). :class:`AsyncSoftFileLock`
            rejects ``True``.
        :param on_acquired: for native locks (:class:`AsyncFileLock`), a callable invoked with the borrowed lock
            descriptor once per physical acquisition, after the lock is held but before
            :meth:`~BaseAsyncFileLock.acquire` returns. With ``run_in_executor=True`` (the default) it runs in the
            backend executor. It must not close or unlock the descriptor; a raise rolls the acquisition back.
            :class:`AsyncSoftFileLock` rejects it.
        :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.

        )	rR   rS   rT   rE   rG   rH   rN   rO   rP   N)osgetpid_creator_pid_is_thread_local_is_singleton_context_error_policy_close_error_policy_fallback_to_soft_preserve_lock_file_on_acquiredr   _transition_gateAsyncThreadLocalFileContextAsyncFileLockContextfspath_contextr   )selfrR   rS   rT   rU   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   s                    r^   __init__zBaseAsyncFileLock.__init__   s    J IIK ,)%9"#5 !1#5 '=Q=S/tl/J`tii	*'+
/
 	d#r_   c                .    | j                   j                  S )zWhether run in executor.)r   rO   r   s    r^   rO   z!BaseAsyncFileLock.run_in_executor   s     }},,,r_   c                .    | j                   j                  S )zThe executor.r   rP   r   s    r^   rP   zBaseAsyncFileLock.executor   s     }}%%%r_   c                &    || j                   _        y)zs
        Change the executor.

        :param futures.Executor | None value: the new executor or ``None``

        Nr   )r   values     r^   rP   zBaseAsyncFileLock.executor   s     "'r_   c                .    | j                   j                  S )zThe event loop.)r   rN   r   s    r^   rN   zBaseAsyncFileLock.loop   s     }}!!!r_   )rE   cancel_checkc               j  K   | j                          || j                  j                  }|| j                  j                  }|| j                  j                  }t        j                         }	 | j                  |||||       d{   S 7 # t        $ r t        | j                        dw xY ww)a  
        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, ``None`` means use the default
            :attr:`~BaseFileLock.poll_interval`
        :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.
        :param cancel_check: a callable returning ``True`` when the acquisition should be canceled. Checked on each poll
            iteration. When triggered, raises :class:`~Timeout` just like an expired timeout.

        :returns: a context object that will unlock the file when the context is exited

        :raises Timeout: if fails to acquire lock within the timeout period

        .. 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()

        NrE   r   rS   rG   
start_time)_raise_if_inheritedr   rS   rE   rG   timeperf_counter_acquire_with_admissionr   r%   rR   )r   rS   rG   rE   r   r   s         r^   acquirezBaseAsyncFileLock.acquire   s     N 	  "?mm++G}}--H  MM77M&&(
		455!)+% 6     0 	4$..)t3	4s0   A-B30B 	B
B B3B  B00B3c               ~  K   | j                   j                  |||dk  rd n||z   |      4 d {    t        | j                        }| j                  xj
                  dz  c_        | j                  |||       || j                  _        	 | j                  |||||       d {    	 d | j                  _        | j                  |       t        |       cd d d       d {    S 7 7 F# t        $ r | j                  |        w xY w# d | j                  _        w xY w7 ># 1 d {  7  sw Y   y xY ww)Nr   )rE   r   deadlinerG   r   )rS   rE   r   lock)r   hold_for_acquirer   rR   r   lock_counter_raise_if_would_deadlock
claim_root_async_poll_until_acquiredBaseException_reconcile_failed_acquire_commit_acquireAsyncAcquireReturnProxy)r   rE   r   rS   rG   r   	canonicals          r^   r   z)BaseAsyncFileLock._acquire_with_admission:  s:     ((99%$q[Tj7.B'	 : 
 	6 	6 #4>>2IMM&&!+&)))Wx)X'0DMM$055%!-#"/) 6    ,0(  +*53	6 	6 	6 ! ..y9 ,0(/	6 	6 	6 	6s{   .D=C-D=AD(C1(C/)C1.-D(D='D&(D=/C11DDD##D(&D=(D:.D1/D:6D=c                 K   t        |       }| j                  }	 | j                          | j                  sO| j	                          t
        j                  d||       | j                          d {    | j                          | j                  rt
        j                  d||       y | j                  ||||      rt        |      t
        j                  d|||       t        j                  |       d {    7 7 w)Nz#Attempting to acquire lock %s on %szLock %s acquired on %s)rE   r   rS   r   z2Lock %s not acquired on %s, waiting %s seconds ...)idrR   r   	is_locked_try_break_expired_lockr5   debug_run_acquire_attempt_check_give_upr%   rt   sleep)r   rE   r   rS   rG   r   lock_idlock_filenames           r^   r   z,BaseAsyncFileLock._async_poll_until_acquired^  s      T($$&>>,,.CWm\//111((*~~6O""!)%	 #  m,,MMNPWYfhuv--...% 
 2 /s%   A/D1D 2BD:D;DDc                  K   | j                  t        | j                        r| j                  n| j                        }	 t        |       d {    	 t        |       y 7 # t        j                  $ r}d }	 t        |       d {  7   n# t        $ r}|}Y d }~nd }~ww xY wd }| j                  r<	 t        | j                                d {  7   n# t        $ r}|}Y d }~nd }~ww xY w|)|| j                  d|||       | j                  d||       || j                  d||        d }~ww xY w# t        j                  $ r$}| j                  |       d {  7   Y d }~y d }~ww xY ww)NzClock acquisition cancellation, backend attempt, and rollback failedz=lock acquisition cancellation and backend attempt both failedz6lock acquisition cancellation and rollback both failed)_start_internal_methodr   _acquire!_acquire_with_fork_tracking_async_acquire_with_fork_trackingr$   rt   CancelledErrorr"   r   r   _start_tracked_release_raise_cancelled_errorsr#   #_rollback_backend_cancelled_acquire)r   acquire_futurecancellationacquire_errorerrorrollback_errors         r^   r   z&BaseAsyncFileLock._run_acquire_attempt}  sp    44"4==1 2211

	">222>	J>*A 3%% 	26M&#N333  & %& 48N~~+'(C(C(EFFF$ +%*N+ (!-00]$%&	 ,,SUacp ),,Ll\j ;	@ %% 	J::=III	Js   =E2 A" A A" D8 E2 A" "D55D08BB	BD0	B"BD0B""D04CCCD0	C, C'"D0'C,,AD00D55E28E/E*E" E*%E2*E//E2c                   K   | j                   r$	 t        | j                                d {    ||7 # t        $ r}| j	                  ||       Y d }~|d }~ww xY wwrs   )r   r"   r   r   _raise_acquire_rollback_errorsr   r   r   s      r^   r   z5BaseAsyncFileLock._rollback_backend_cancelled_acquire  sg     >>S#D$?$?$ABBB m C  S33M>RRSs7   A 7 57 A 7 	A AA AA c                T    | j                   dk(  rt        d||       t        ||       y )Ngroupz1lock acquisition backend and rollback both failed)r}   r   r   r   s      r^   r   z0BaseAsyncFileLock._raise_acquire_rollback_errors  s)    %%0!"UWdftum^<r_   c                   | j                   dk(  r8|t        k(  rt        t        fnd }|t	        ||||       t	        |||||       |j
                  x}%||ur!|j
                  x}t        ||       ||_        ||_        t        ||       y )Nr   )marker)r}   r6   r9   r:   r   __context__r   r   )r   messager   first_errorsecond_errorr   contextcancellation_contexts           r^   r   z)BaseAsyncFileLock._raise_cancelled_errors  s     %%0 @@ 9:\] 
 #%g|[QWX!'<l[ab"...G;|@[(4(@(@@$M)'3GH'.L$".k<8r_   c                8  K   | j                   t        j                         k7  s| j                  sy| j                  j                         4 d{    | j                  |       d{    ddd      d{    y7 /7 7 	# 1 d{  7  sw Y   yxY ww)a1  
        Release the file lock. The lock is only completely released when the lock counter reaches 0. The lock file
        itself may be deleted automatically, the behavior is platform-specific.

        :param force: If true, the lock counter is ignored and the lock is released in every case.

        Nforce)rz   rx   ry   r   r   hold_release_serialized)r   r   s     r^   releasezBaseAsyncFileLock.release  s      		+4>>((--/ 	8 	8***777	8 	8 	87	8 	8 	8 	8sZ   ABA?BB)B*B.B9B:BBBBBBBc                 K   | j                   sy |s9| j                  j                  dkD  r | j                  xj                  dz  c_        y t        |       | j                  }}t
        j                  d||       | j                         }	 t        |       d {    	 t#        |       | j!                          t
        j                  d||       y 7 8# t        j                  $ ri}	 t        |       d {  7   n=# t        $ r1}| j                          | j                  t        ||       Y d }~nd }~ww xY w| j!                           d }~ww xY w# t        $ r | j                           w xY ww)Nr   z#Attempting to release lock %s on %szLock %s released on %s)r   r   r   r   rR   r5   r   r   r$   rt   r   r"   r   _commit_release_if_releasedr   r6   _commit_releaser#   )r   r   r   r   release_futurer   release_errors          r^   r   z%BaseAsyncFileLock._release_serialized  s?    ~~33a7MM&&!+&!#D4>>;WmT446		">222	>* 	.G 3%% 	n#N333  n002,,-OQ]_lmmn   "	  	,,.	s~   BE0
C CC E )(E0C E'C<5C86C<;E
<	D6'D1,E
1D66E

EE0E--E0c                >    | j                   s| j                          y y rs   )r   r   r   s    r^   r   z-BaseAsyncFileLock._commit_release_if_released  s     ~~  " r_   c           	     d   t        |      r-t        j                  t         t	        d|                         S t        j
                         }t	        d|      }| j                  r!|j                  | j                  t        |      S |j                         }|j                  t        |             |S )Nz)Callable[[], Coroutine[None, None, None]]zCallable[[], None])r   rt   create_taskr    r   get_running_looprO   rP   r!   create_future
set_result)r   methodrN   sync_methodfutures        r^   r   z(BaseAsyncFileLock._start_internal_method  s     v&&&'9:s$?jlr:s:u'vww'')/8''}kRR8<8J8J8L-45r_   c                    | j                  t        | j                        r| j                        S | j                        S rs   )r   r   _release!_release_with_fork_tracking_async_release_with_fork_trackingr   s    r^   r   z(BaseAsyncFileLock._start_tracked_release  sA    **"4==1 22
 	
 11
 	
r_   c                  K   t        |       5  	  t        d| j                                d {    	 | j                          	 d d d        | j                  r| j                          d {    y y 7 D# t        $ r }| j	                  |       d {  7    d }~ww xY w# t        $ r }| j                  |       d {  7    d }~ww xY w# 1 sw Y   xY w7 lwNzCallable[[], Awaitable[None]])	r   r   r   r   _rollback_failed_acquire_async_register_context_descriptor#_rollback_failed_registration_asyncr   _invoke_on_acquired_async)r   acquisition_errorregistration_errors      r^   r   z3BaseAsyncFileLock._acquire_with_fork_tracking_async  s     d# 
	Jd:DMMJLLL113
	 >>00222  M  99:KLLL
 ! >>?QRRR
	 
	 3s   CCA5A3A5B!'C,C-C3A55	B>BBBBC!	C
*C>C?CC

CCCc                  K   | j                   sy d }d }	 | j                          	 t	        | j                                d {    |t        d|||       y y # t        $ r6}|}	 | j                          n# t        $ r}|}Y d }~nd }~ww xY wY d }~nd }~ww xY w7 X# t        $ r/}||| j                  ||       t        d||||       Y d }~d }~ww xY ww)Nzlock acquisition cleanup failed)r   r   r   '_register_unverified_context_descriptorr"   r   r   r   )r   r   r   tracking_errorr   r   s         r^   r   z0BaseAsyncFileLock._rollback_failed_acquire_async  s     ~~37/3	'--/	 ; ; =>>> )!13DFXZh *'  	'!&'<<>  '!&'	' ? 		!)n.D334E~V!1!" 		s   CA B BB C	B"B%A65B6	B?BBBBCBCB 	C&%CCCCc                  K   d }	 | j                          	 t        | j                                d {    |t	        d||       y y # t        $ r}|}Y d }~Cd }~ww xY w7 -# t        $ r}t	        d|||       Y d }~Gd }~ww xY ww)Nz&descriptor registration cleanup failed)r   r   r"   r   r   )r   r   r   r   r   s        r^   r   z5BaseAsyncFileLock._rollback_failed_registration_async=  s     /3	#88:	 ; ; =>>>
 %!"JL^`no &  	#"N	# ? 	!8:Ln^l 	s`   BA	 A# A!A# B		AABAB!A# #	B,A?:B?BBc                  K   | j                   | j                  j                  dk7  ry 	 | j                  t        d| j                  j                               y # t
        $ re}|j                  }	 t        | j                                d {  7   ||_         # t
        $ r}t        ||       Y d }~||_         d }~ww xY wd }~ww xY ww)Nr   rb   )
r   r   r   r   lock_file_fdr   r   r"   r   r   )r   callback_errorcallback_contextr   s       r^   r   z+BaseAsyncFileLock._invoke_on_acquired_asyncM  s     $(B(Ba(G		d5$--*D*DEF 	-99G#D$?$?$ABBB *:N& ! G'FF)9N&G		s^   'C/A C	C#C0BBBC	C #B;/C;C  CCCc                   K   t        |       5  	  t        d| j                                d {    | j                          	 d d d        y 7 # | j                          w xY w# 1 sw Y   y xY wwr   )r   r   r   _unregister_released_descriptorr   s    r^   r   z3BaseAsyncFileLock._release_with_fork_tracking_async[  sc     d# 	77Jd:DMMJLLL446		7 	7L446		7 	7sB   A0A$AAAA$	A0AA!!A$$A-)A0c                    d}t        |      )zTSync context manager entry is not supported because lock acquisition is a coroutine.aUse `async with`: acquire/release are coroutines and cannot be awaited in a sync context manager.NotImplementedError)r   r\   s     r^   	__enter__zBaseAsyncFileLock.__enter__b  s    q!#&&r_   c                    d}t        |      )zOSync context manager exit is not supported because lock release is a coroutine.r   r   )r   exc_type	exc_value	tracebackr\   s        r^   __exit__zBaseAsyncFileLock.__exit__g  s     r!#&&r_   c                B   K   | j                          d{    | S 7 w)zG
        Acquire the lock.

        :returns: the lock object

        N)r   r   s    r^   
__aenter__zBaseAsyncFileLock.__aenter__q  s!      lln 	s   c                B   K   | j                  |       d{    y7 w)a%  
        Release the lock, reconciling a release failure with any body failure per :attr:`context_error_policy`.

        :param exc_type: the exception type if raised
        :param exc_value: the exception value if raised
        :param traceback: the exception traceback if raised

        N)_release_in_contextr   r   r   r   s       r^   	__aexit__zBaseAsyncFileLock.__aexit__{  s      &&y111s   c                p  K   	 | j                          d {    y 7 # t        $ r}| | j                  dk(  rt        ||        t	        |t
        t        t        f      x}	 8|  r4 dk(  r/\  xt        j                  d x\   }}t        t        |||       n   t        ||       Y d }~y d }~ww xY ww)NrB      rV   )r   r   r}   r   r   r6   r9   r:   rt   r   r   r7   r   )r   
body_errorr   errorsr   backend_errors         r^   r  z%BaseAsyncFileLock._release_in_context  s     	?,,.   	?!))W4)-D)!6<>`a 
  RRB'002R-.KZYegtu S#J>>#	?s7   B6  B6 	B3BB.)B6.B33B6c                j   t        |       j                  d      t        j                         k7  ryt	        j
                  t              5  	 t        j                         }|
	 ddd       y|j                         s"|j                  | j                  d             n!|j!                  | j                  d             ddd       y# t        $ rU | j                  j                  r:| j                  j                  j                         s| j                  j                  nd}Y w xY w# 1 sw Y   yxY w)zORelease on deletion; safe to call during GC even when no event loop is running.rz   NTr   )varsgetrx   ry   
contextlibsuppress	Exceptionrt   r   RuntimeErrorr   rN   	is_closed
is_runningrun_until_completer   r   )r   rN   s     r^   __del__zBaseAsyncFileLock.__del__  s    :>>.)RYY[8  + 
	;q//1 |
	; 
	; ??$''4(@A  D!9:
	; 
	;   q-1]]-?-?HZHZHdHdHft}}))lpq
	; 
	;s8   
D)C D),AD)AD&#D)%D&&D))D2)rh   zHashable | None)"rR   r`   rS   ra   rT   rb   rU   rc   rE   rc   rF   rc   rG   ra   rH   rd   rI   r   rJ   r   rK   rc   rL   rc   rM   re   rN   rf   rO   rc   rP   rg   rh   None)rh   rc   )rh   rg   )r   rg   rh   r  )rh   rf   )NN)
rS   rd   rG   rd   rE   zbool | Noner   Callable[[], bool] | Nonerh   r   )rE   rc   r   r  rS   ra   rG   ra   r   ra   rh   r   )rE   rc   r   r  rS   ra   rG   ra   r   ra   rh   r  )rh   r  )r   asyncio.CancelledErrorrh   r	   )r   r   r   r   rh   r	   rs   )
r   rn   r   r  r   r   r   BaseException | Nonerh   r	   )F)r   rc   rh   r  )r   z>Callable[[], None] | Callable[[], Coroutine[None, None, None]]rh   %asyncio.Future[_BackendOutcome[None]])rh   r  )r   r   rh   r  )r   r   rh   r  )rh   r	   r   ztype[BaseException] | Noner   r  r   zTracebackType | Nonerh   r  )rh   r3   )r  r  rh   r  )'ri   rj   rk   __doc__ro   __annotations__rq   staticmethodrv   r   r   propertyrO   rP   setterrN   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  rV   r_   r^   r<   r<   u   sT    "K3J45,c5& & $"Z$ "#!%3:/8!%#(4815 $,0%Z$)Z$ Z$ 	Z$
 Z$ Z$ Z$ Z$ Z$ 1Z$ -Z$ Z$ !Z$ 2Z$  /!Z$" #Z$$ *%Z$& 
'Z$x - - & & __' ' " " !%&*;4
 !%26;4;4 $;4
 ;4 0;4 
!;4z"6 "6 0	"6
 "6 "6 "6 
!"6H/ / 0	/
 / / / 
/>)JV= .299 -9 #	9
 +9 
9.8H8#T	.
3>p 7'
',' (' (	'
 
'2,2 (2 (	2
 
2 ?.?	?2;r_   )	metaclassc                  <    e Zd ZU dZdZded<   dZded<   dZded	<   y)
r   zGA dataclass which holds the context for a ``BaseAsyncFileLock`` object.Trc   rO   Nrg   rP   rf   rN   )ri   rj   rk   r  rO   r  rP   rN   rV   r_   r^   r   r     s+    Q !OT  )-H%, .2D
*1r_   r   c                      e Zd ZdZy)r   z8A thread local version of the ``FileLockContext`` class.Nri   rj   rk   r  rV   r_   r^   r   r     s    Br_   r   c                  8    e Zd ZdZddZddZ	 	 	 	 	 	 	 	 ddZy)	r   zDA context-aware object that will release the lock file when exiting.c                    || _         y rs   r   )r   r   s     r^   r   z AsyncAcquireReturnProxy.__init__  s	    	r_   c                "   K   | j                   S wrs   r   r   s    r^   r  z"AsyncAcquireReturnProxy.__aenter__  s     yys   c                V   K   | j                   j                  |       d {    y 7 wrs   )r   r  r  s       r^   r  z!AsyncAcquireReturnProxy.__aexit__  s       ii++I666s   )')N)r   r<   rh   r  )rh   r<   r  )ri   rj   rk   r  r   r  r  rV   r_   r^   r   r     s:    N7,7 (7 (	7
 
7r_   r   c                       e Zd ZU dZdZded<   y)AsyncSoftFileLockz.Simply watches the existence of the lock file.)AsyncStrictSoftFileLockAsyncSoftFileLeaseztuple[str, str] | None_lifetime_replacementsN)ri   rj   rk   r  r-  r  rV   r_   r^   r*  r*    s    85f2fr_   r*  c                      e Zd ZdZy)r+  z?Run strict owner-claim locking without blocking the event loop.Nr$  rV   r_   r^   r+  r+    s    Ir_   r+  c                      e Zd ZdZy)r,  z_Existence lock whose claim expires, so a peer may take it while the previous holder still runs.Nr$  rV   r_   r^   r,  r,    s    ir_   r,  c                      e Zd ZdZy)AsyncUnixFileLockzHUses the :func:`fcntl.flock` to hard lock the lock file on unix systems.Nr$  rV   r_   r^   r1  r1    s    Rr_   r1  c                      e Zd ZdZy)AsyncWindowsFileLockzNUses the :func:`msvcrt.locking` to hard lock the lock file on windows systems.Nr$  rV   r_   r^   r3  r3    s    Xr_   r3  )r   r,  r*  r+  r1  r3  r<   )Zr  
__future__r   rt   r  loggingrx   r   dataclassesr   inspectr   	threadingr   typingr   r   r	   r
   r   _apir   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   _asyncr   r   r   r    r!   r"   r#   r$   _errorr%   _leaser&   _softr'   _strictr(   _unixr)   _windowsr*   syscollections.abcr+   r,   r-   r.   
concurrentr/   typesr0   version_infor3   typing_extensions	getLoggerr5   r  r6   r7   r9   r:   r;   r?   r<   r   r   r   r*  r+  r,  r1  r3  __all__rV   r_   r^   <module>rJ     s   7 "    	  ! '  @ @    $	 	 	  !  '  %HH"#
7"* "3!2!2:!>	 >1l "J l,l z l6\ ' \8: "$5 :e./+
 +
\};0A };@ 
2? 
2 
2C"6 C7 7$g&7 gJ02C Jj(9 jS&7 SY?,= Yr_   