
    3j                    b   % S r SSKJr  SSKrSSKrSSKrSSKrSSKrSSKrSSK	r	SSK
r
SSKrSSKrSSKrSSKJrJr  SSKJr  SSKJr  SSKJrJr  SSKJr  SS	KJr  SS
KJr  SSKJr  SSK J!r!  \(       a  SSK"J#r#J$r$  \S   r%Sr&Sr'\(" \SS5      r)\(" \SS5      r*\
RV                  S:g  =(       a    \RX                  \RZ                  ;   r.\" 5       r/S\0S'   \Rb                  " 5       q2Sq3Sq4\" SS9 " S S5      5       r5\ " S S5      5       r6\" SS9 " S S5      5       r7\ " S S 5      5       r8 " S! S"\95      r: " S# S$\:S%9r; " S& S'\Rx                  5      r=SS(.S4S) jjr>SS(.S5S* jjr?S6S+ jr@SS(.         S7S, jjrASS(.S8S- jjrBSS(.S8S. jjrCS9S/ jrDS:S0 jrES;S1 jrFS;S2 jrGS;S3 jrHS$/rIg)<zZCross-process and cross-host reader/writer lock built on :class:`SoftFileLock` primitives.    )annotationsN)contextmanagersuppress)	dataclass)Path)TYPE_CHECKINGLiteral)WeakValueDictionary)AcquireReturnProxy)Timeout)SoftFileLock)ensure_directory_exists)Callable	Generator)readwritez.breaki   
O_NOFOLLOW
O_NONBLOCKwin32,WeakValueDictionary[Path, SoftReadWriteLock]_all_instancesFT)frozenc                  4    \ rS rSr% S\S'   S\S'   S\S'   Srg)_Paths.   strstater   readers N__name__
__module____qualname____firstlineno____annotations____static_attributes__r       Q/home/wildlama/miniconda3/lib/python3.13/site-packages/filelock/_soft_rw/_sync.pyr   r   .   s    JJLr'   r   c                  4    \ rS rSr% S\S'   S\S'   S\S'   Srg)	_Locks5   threading.Lockinternaltransactionr   r   r   Nr    r   r'   r(   r*   r*   5   s    r'   r*   c                  4    \ rS rSr% S\S'   S\S'   S\S'   Srg)	_MarkerInfo<   r   tokenintpidhostnamer   Nr    r   r'   r(   r0   r0   <   s    J	HMr'   r0   c                  j    \ rS rSr% SrS\S'   S\S'   S\S'   S	\S
'   S\S'   S	\S'   S\S'   S\S'   Srg)_HoldC   zYEverything that exists only while a lock is held; ``None`` when the instance has no lock.r3   level_Modemode
int | Nonewrite_thread_idr   marker_namebool	is_readerr2   _HeartbeatThreadheartbeat_threadthreading.Eventheartbeat_stopr   N)r!   r"   r#   r$   __doc__r%   r&   r   r'   r(   r7   r7   C   s1    cJ
KOJ&&##r'   r7   c                  v   ^  \ rS rSr% S\S'   S\S'    SSSSSS	S
.               SU 4S jjjjrSrU =r$ )_SoftRWMetaQ   r   
_instancesr,   _instances_lockT      >@N      ?blockingis_singletonheartbeat_intervalstale_thresholdpoll_intervalc                 > U(       d  [         TU ]  UUUUUUUS9$ [        U5      R                  5       nU R                     U R
                  R                  U5      n	U	c"  [         TU ]  UUUUUUUS9n	XR
                  U'   OMU	R                  U:w  d  U	R                  U:w  a-  SU	R                   SU	R                   SU SU 3n
[        U
5      eU	sS S S 5        $ ! , (       d  f       g = f)NrM   z$Singleton lock created with timeout=z, blocking=z, cannot be changed to timeout=)
super__call__r   resolverJ   rI   gettimeoutrN   
ValueError)cls	lock_filerX   rN   rO   rP   rQ   rR   
normalizedinstancemsg	__class__s              r(   rU   _SoftRWMeta.__call__U   s    7#!)#5 /+ $   )_,,.
  ~~))*5H 7+%!-'9$3"/ ,  .6z*!!W,0A0AX0M:8;K;K:LKX`XiXiWj k55<I[
T  !o%' !  s   BC
C(r   )r[   str | os.PathLike[str]rX   floatrN   r?   rO   r?   rP   rd   rQ   float | NonerR   rd   returnSoftReadWriteLock)r!   r"   r#   r$   r%   rU   r&   __classcell__r_   s   @r(   rG   rG   Q   s    <<##
 *
 !$((,#*)* *
 * * "* &* * 
* *r'   rG   c                     \ rS rSr% Sr\" 5       rS\S'   \R                  " 5       r
 S"SSSSSS	.               S#S
 jjjr\S$SS.S%S jjj5       r\S$SS.S%S jjj5       rS$SS.S&S jjjrS$SS.S&S jjjrS'S jrSS.S(S jjr\ S"SS.       S)S jjj5       r        S*S jr          S+S jrS,S jr        S-S jr        S-S jr        S.S jrS'S jrS/S jrS0S jrS1S jrS/S jrS'S  jr S!r!g)2rg      uE
  
Cross-process and cross-host reader/writer lock built on :class:`SoftFileLock` primitives.

Use this class instead of :class:`~filelock.ReadWriteLock` when the lock file lives on a network
filesystem (NFS, Lustre with ``-o flock``, HPC cluster shared storage). ``ReadWriteLock`` is backed
by SQLite and cannot run on NFS because SQLite's ``fcntl`` locking is unreliable there.

Layout on disk for a lock at ``foo.lock``:

- ``foo.lock.state`` — a :class:`SoftFileLock` taken only during state transitions (microseconds).
- ``foo.lock.write`` — writer marker; its presence means a writer is claiming or holding the lock.
- ``foo.lock.readers/<host>.<pid>.<uuid>`` — one file per reader.

Each marker stores a random token (``secrets.token_hex(16)``), the holder's pid, and the holder's
hostname. A daemon heartbeat thread refreshes ``mtime`` on every held marker. A marker whose mtime
has not advanced in ``stale_threshold`` seconds may be evicted by any process on any host, giving
correct behavior when a compute node crashes with a lock held.

Writer acquire is two-phase and writer-preferring: phase 1 claims ``.write`` (blocking any new
reader), phase 2 waits for existing readers to drain. Writer starvation is impossible.

Reentrancy, upgrade/downgrade rules, thread pinning, and singleton caching by resolved path match
:class:`~filelock.ReadWriteLock`.

Forking while holding a lock invalidates the inherited instance in the child so the child cannot
double-own the lock with its parent; ``release()`` on a fork-invalidated instance is a no-op, and
the child must re-acquire if it needs a lock.

Trust boundary: protects against same-UID non-cooperating processes (one host or cross-host) and
same-host different-UID users via ``0o600`` / ``0o700`` permissions. Does not protect against root
compromise, NTP tampering on same-UID cross-host nodes, or multi-tenant mounts where hostile
co-tenants share the UID.

:param lock_file: path to the lock file; sidecar state/write/readers live next to it
:param timeout: maximum wait time in seconds; ``-1`` means block indefinitely
:param blocking: if ``False``, raise :class:`~filelock.Timeout` immediately on contention
:param is_singleton: if ``True``, reuse existing instances for the same resolved path
:param heartbeat_interval: seconds between heartbeat refreshes; default 30 s
:param stale_threshold: seconds of ``mtime`` inactivity before a marker is stale; defaults to
    ``3 * heartbeat_interval``, matching etcd's ``LeaseKeepAlive`` convention
:param poll_interval: seconds between acquire retries under contention; default 0.25 s

.. versionadded:: 3.27.0

r   rI   TrK   NrL   rM   c          	     ,   US::  a  SU 3n[        U5      eUc  US-  nXe::  a  SU SU S3n[        U5      eUS::  a  SU 3n[        U5      e[        R                  " U5      U l        X l        X0l        XPl        X`l        Xpl        [        U R                   S3U R                   S	3U R                   S
3S9U l
        [        U R                  5        [        [        R                  " 5       [        R                  " 5       [        U R                  R                   SS9S9U l        S U l        S U l        SU l        SU l        [,           U [.        [1        U R                  5      R3                  5       '   [5        5         S S S 5        g ! , (       d  f       g = f)Nr   z)heartbeat_interval must be positive, got    z0stale_threshold must exceed heartbeat_interval (z <= )z$poll_interval must be positive, got z.statez.writez.readers)r   r   r   rb   rX   r-   r.   r   F)rY   osfspathr[   rX   rN   rP   rQ   rR   r   _pathsr   r*   	threadingLockr   r   _locks_readers_dir_fd_hold_fork_invalidated_closed_all_instances_lockr   r   rV   _register_hooks)	selfr[   rX   rN   rO   rP   rQ   rR   r^   s	            r(   __init__SoftReadWriteLock.__init__   ss    "=>P=QRCS/!"014O0D_DUUYZlYmmnoCS/!A8HCS/! ii	2%&);&5$1^^$F+^^$F+~~&h/

 	 /^^%!(t{{00"=

 ,0#'
'," =AN4/779: !  s   5F
FrN   c             #  ~   #    U R                  XS9   Sv   U R                  5         g! U R                  5         f = f7f)a  
Context manager that acquires and releases a shared read lock.

Falls back to instance defaults for *timeout* and *blocking* when ``None``.

:param timeout: maximum wait time in seconds, or ``None`` to use the instance default
:param blocking: if ``False``, raise :class:`~filelock.Timeout` immediately; ``None`` uses the instance default

:raises RuntimeError: if a write lock is already held on this instance
:raises Timeout: if the lock cannot be acquired within *timeout* seconds

r   N)acquire_readreleaser}   rX   rN   s      r(   	read_lockSoftReadWriteLock.read_lock   s2      	'5	LLNDLLN   =( =:=c             #  ~   #    U R                  XS9   Sv   U R                  5         g! U R                  5         f = f7f)a  
Context manager that acquires and releases an exclusive write lock.

Falls back to instance defaults for *timeout* and *blocking* when ``None``.

:param timeout: maximum wait time in seconds, or ``None`` to use the instance default
:param blocking: if ``False``, raise :class:`~filelock.Timeout` immediately; ``None`` uses the instance default

:raises RuntimeError: if a read lock is already held, or a write lock is held by a different thread
:raises Timeout: if the lock cannot be acquired within *timeout* seconds

r   N)acquire_writer   r   s      r(   
write_lockSoftReadWriteLock.write_lock   s2      	76	LLNDLLNr   c               "    U R                  SXS9$ )u  
Acquire a shared read lock.

If this instance already holds a read lock, the lock level is incremented (reentrant). Attempting to acquire a
read lock while holding a write lock raises :class:`RuntimeError` (downgrade not allowed). On the 0→1
transition a daemon heartbeat thread is started that refreshes the reader marker's ``mtime`` every
``heartbeat_interval`` seconds so peers on other hosts do not evict the marker as stale.

:param timeout: maximum wait time in seconds, or ``None`` to use the instance default; ``-1`` means block
    indefinitely
:param blocking: if ``False``, raise :class:`~filelock.Timeout` immediately when the lock is unavailable;
    ``None`` uses the instance default

:returns: a proxy that can be used as a context manager to release the lock

:raises RuntimeError: if a write lock is already held on this instance, if this instance was invalidated by
    :func:`os.fork`, or if :meth:`close` was called
:raises Timeout: if the lock cannot be acquired within *timeout* seconds

r   r   _acquirer   s      r(   r   SoftReadWriteLock.acquire_read  s    * }}VW}@@r'   c               "    U R                  SXS9$ )a   
Acquire an exclusive write lock.

If this instance already holds a write lock from the same thread, the lock level is incremented (reentrant).
Attempting to acquire a write lock while holding a read lock raises :class:`RuntimeError` (upgrade not
allowed). Write locks are pinned to the acquiring thread: a different thread trying to re-enter also raises
:class:`RuntimeError`.

Writer acquisition runs in two phases. Phase 1 atomically claims ``<path>.write`` via ``O_CREAT | O_EXCL``,
which immediately blocks any new reader on any host. Phase 2 waits for existing readers to drain. Writer
starvation is impossible: new readers see ``<path>.write`` during phase 2 and wait behind the pending writer.

:param timeout: maximum wait time in seconds, or ``None`` to use the instance default; ``-1`` means block
    indefinitely
:param blocking: if ``False``, raise :class:`~filelock.Timeout` immediately when the lock is unavailable;
    ``None`` uses the instance default

:returns: a proxy that can be used as a context manager to release the lock

:raises RuntimeError: if a read lock is already held, if a write lock is held by a different thread, if this
    instance was invalidated by :func:`os.fork`, or if :meth:`close` was called
:raises Timeout: if the lock cannot be acquired within *timeout* seconds

r   r   r   r   s      r(   r   SoftReadWriteLock.acquire_write%  s    2 }}Wg}AAr'   c                   U R                  SS9  U R                  R                     U R                  (       a
   SSS5        gSU l        U R                  b?  [        [        5         [        R                  " U R                  5        SSS5        SU l        SSS5        g! , (       d  f       N= f! , (       d  f       g= f)u   
Release any held lock and release internal filesystem resources.

Idempotent. After calling this method the instance can no longer acquire locks — subsequent acquires raise
:class:`RuntimeError`. A fork-invalidated instance is closed without raising.
TforceN)	r   rv   r-   rz   rw   r   OSErrorrq   closer}   s    r(   r   SoftReadWriteLock.close@  s     	4 [[!!|| "!  DL##/g&HHT112 ''+$ "!
 '& "!s)   B/#B/%!BB/
B,	(B//
B=Fr   c                  U R                   R                     U R                  (       a  SU l         SSS5        gU R                  nUc8  U(       a
   SSS5        gSU R                   S[        U 5       S3n[        U5      eU(       a  SUl        OU=R                  S-  sl        UR                  S:  a
   SSS5        gSU l        SSS5        WR                  R                  5         UR                  R                  U R                  S-   S9  UR                  (       a  [        UR                  U R                   S	9  g[        UR                  5        g! , (       d  f       N= f)
a   
Release one level of the current lock.

When the lock level reaches zero the heartbeat thread is stopped and the held marker file is unlinked. On a
fork-invalidated instance (that is, the child of a :func:`os.fork` call made while the parent held a lock)
this method is a no-op so inherited ``with`` blocks can unwind cleanly in the child.

:param force: if ``True``, release the lock completely regardless of the current lock level

:raises RuntimeError: if no lock is currently held and *force* is ``False``

NzCannot release a lock on  (lock id: z) that is not heldr      g      ?ro   dir_fd)rv   r-   ry   rx   r[   idRuntimeErrorr9   rD   setrB   joinrP   r@   _unlinkr>   rw   )r}   r   holdr^   s       r(   r   SoftReadWriteLock.releaseQ  s    [[!!%%!
	 "!
 ::D| "! 2$..1ARPTXJVhi"3''


a
zzA~! "!" DJ# ", 	!""4+B+BS+H"I>>D$$T-A-ABD$$%7 "!s   EEAE?E
E"c                   U " XUS9$ )a  
Return the singleton :class:`SoftReadWriteLock` for *lock_file*.

:param lock_file: path to the lock file; sidecar state/write/readers live next to it
:param timeout: maximum wait time in seconds; ``-1`` means block indefinitely
:param blocking: if ``False``, raise :class:`~filelock.Timeout` immediately when the lock is unavailable

:returns: the singleton lock instance

:raises ValueError: if an instance already exists for this path with different *timeout* or *blocking* values

r   r   )rZ   r[   rX   rN   s       r(   get_lockSoftReadWriteLock.get_lock{  s    ( 999r'   c                  Uc  U R                   OUnUc  U R                  OUnU R                  R                     U R                  (       a  SU R
                   S3n[        U5      eU R                  (       a  SU R
                   S3n[        U5      eU R                  b  U R                  U5      sS S S 5        $  S S S 5        [        R                  " 5       nU(       d$  U R                  R                  R                  SS9nONUS:X  a$  U R                  R                  R                  SS9nO$U R                  R                  R                  SUS9nU(       d  [        U R
                  5      S e U R                  XXSS9U R                  R                  R!                  5         $ ! , (       d  f       N= f! U R                  R                  R!                  5         f = f)	NzSoftReadWriteLock on z4 was invalidated by fork(); construct a new instancez has been closedFr   rb   T)rN   rX   )rX   rN   rv   r-   ry   r[   r   rz   rx   _validate_reentranttimeperf_counterr.   acquirer   _do_acquire_innerr   )r}   r;   rX   rN   r^   startacquireds          r(   r   SoftReadWriteLock._acquire  s    #*/$,,w$,$44==([[!!%%-dnn-==qr"3''||-dnn-==MN"3''zz%//5 "! & " !!#{{..666FH]{{..666EH{{..66g6VH$..)t3	.))$)RKK##++-- "!, KK##++-s   A6F".F3 "
F03&Gc                  U R                   R                     U R                  b  U R                  U5      sS S S 5        $  S S S 5        US:X  a  S OX2-   n[        R
                  " S5      nUS:X  a  U R                  XeUS9u  pxOU R                  XeUS9u  px[        R                  " 5       n	[        U R                  U R                  U	S[        U 5      S 3S9n
U R                   R                     [        SUUS:X  a  [        R                  " 5       OS UUUU
U	S	9U l        S S S 5        U
R!                  5         [#        U S
9$ ! , (       d  f       GN= f! , (       d  f       N9= f)Nrb      r   deadlinerN   zfilelock-heartbeat-x)refreshinterval
stop_eventnamer   )r9   r;   r=   r>   r@   r2   rB   rD   lock)rv   r-   rx   r   secrets	token_hex_acquire_writer_slot_acquire_reader_slotrt   EventrA   _refresh_markerrP   r   r7   	get_identr   r   )r}   r;   effective_timeoutr   rN   r   r2   r>   r@   r   	heartbeats              r(   r   #SoftReadWriteLock._do_acquire_inner  sD    [[!!zz%//5 "!% " -248Q!!"%7?%)%>%>ubj%>%k"K%)%>%>ubj%>%k"K__&
$((,,!&r$xl3	
	 [[!!9=	 3 3 5d'#!*)	DJ " 	!t,,9 "!  "!s   D?-1E?
E
Ec                   U R                   nUc   eUR                  U:w  aD  US:X  a  SOSnUS:X  a  SOSnSU SU R                   S[        U 5       SU S	U S
3n[	        U5      eUS:X  aZ  [
        R                  " 5       =obR                  :w  a6  SU R                   S[        U 5       SU SUR                   3n[	        U5      eU=R                  S-  sl        [        U S9$ )Nr   r   	downgradeupgradezCannot acquire z	 lock on r   z): already holding a z lock (z not allowed)zCannot acquire write lock on z) from thread z while it is held by thread r   r   )
rx   r;   r[   r   r   rt   r   r=   r9   r   )r}   r;   r   opposite	directionr^   curs          r(   r   %SoftReadWriteLock._validate_reentrant  s   zz99"&&.wfH'+v~9I!$y0@BtH: V%%-Jgi[O  s##7?y':':'< <AUAUU//?{2d8* U"e#?@T@T?UW  s##

a
!t,,r'   c                 ^ ^ T R                  5         SU U4S jjnSU 4S jjnT R                  XBUS9   T R                  XRUS9  T R                  R
                  S4$ ! [         a!    [        T R                  R
                  5        e f = f)Nc                   > T R                   R                     [        T R                  R                  T R
                  [        R                  " 5       S9  [        T R                  R                  5      (       a
   S S S 5        g [        T R                  R                  T5         S S S 5        g! [         a     S S S 5        gf = f! , (       d  f       g= f)NrQ   nowFT)
rv   r   _break_stale_markerrs   r   rQ   r   _file_exists_atomic_create_markerFileExistsError)r}   r2   s   r(   try_claim_writer@SoftReadWriteLock._acquire_writer_slot.<locals>.try_claim_writer  s    ""#DKK$5$5tG[G[aeajajalm 1 122  #"!)$++*;*;UC #  ' !  #"! #" s*   A"C B..
C8CCC
Cc                 h  > T R                   R                     [        [        5         [	        T R
                  R                  5        S S S 5        T R                  [        R                  " 5       5        T R                  5       (       + sS S S 5        $ ! , (       d  f       NP= f! , (       d  f       g = fN)
rv   r   r   r   _touchrs   r   _break_stale_readersr   _any_readersr   s   r(   readers_drained_touchingHSoftReadWriteLock._acquire_writer_slot.<locals>.readers_drained_touching  sn    "" g&4;;,,- '))$))+6,,.. #" '& #"s#   B# BA B#
B 	B##
B1r   Frf   r?   )_open_readers_dir	_wait_forr   r   rs   r   )r}   r2   r   rN   r   r   s   ``    r(   r   &SoftReadWriteLock._acquire_writer_slot  s     	 		 			/ 	'XN	NN3QYNZ
 {{  %''	  	DKK%%&	s   A +Bc               V  ^ ^^^^ T R                  5         [        R                  " 5       R                   S[        R
                  " 5        3mT R                  m[        [        T R                  R                  5      T-  5      mSUUUU U4S jjnT R                  XBUS9  Tb  TS4$ TS4$ )N.c                 r  > TR                   R                     [        TR                  R                  TR
                  [        R                  " 5       S9  [        TR                  R                  5      (       a
   S S S 5        gT b  [        TTT S9  O[        TT5         S S S 5        g! , (       d  f       g = f)Nr   Fr   T)	rv   r   r   rs   r   rQ   r   r   r   )r   full_reader_pathreader_namer}   r2   s   r(   try_claim_reader@SoftReadWriteLock._acquire_reader_slot.<locals>.try_claim_reader!  s    ""#DKK$5$5tG[G[aeajajalm 1 122  #" %)+uVL)*:EB #""s   A"B(B((
B6r   Tr   )r   uuiduuid4hexrq   getpidrw   r   r   rs   r   r   )r}   r2   r   rN   r   r   r   r   s   ``   @@@r(   r   &SoftReadWriteLock._acquire_reader_slot  s     	 ))*!BIIK=9%%tDKK$7$78;FG		 		 	'XN%1$NN7G$NNr'   c               8    U" 5       (       a  g [         R                  " 5       nU(       d  [        U R                  5      eUb  XB:  a  [        U R                  5      eU R                  nUb  [        U[        X$-
  S5      5      n[         R                  " U5        M  )Ng        )r   r   r   r[   rR   minmaxsleep)r}   	predicater   rN   r   	sleep_fors         r(   r   SoftReadWriteLock._wait_for/  s     {{##%Cdnn--#dnn--**I#	3x~s+CD	JJy! r'   c                   [        U R                  R                  5      n[        [        5         UR                  SS9  S S S 5        [        R                  " U R                  R                  5      n[        R                  " UR                  5      (       d%  [        R                  " UR                  5      (       d$  U R                  R                   S3n[        U5      eU R                  cf  [        (       aZ  [        R                  [!        [        SS5      -  ["        -  n[        R$                  " U R                  R                  U5      U l        g g g ! , (       d  f       GN= f)Ni  )r;   zB exists but is not a directory or is a symlink; refusing to use itO_DIRECTORYr   )r   rs   r   r   r   mkdirrq   lstatstatS_ISLNKst_modeS_ISDIRr   rw   _SUPPORTS_DIR_FDO_RDONLYgetattr_O_NOFOLLOWopen)r}   readers_pathstr^   flagss        r(   r   #SoftReadWriteLock._open_readers_dirC  s    DKK//0o&E* ' XXdkk))*<<

##4<<

+C+C[[(())klCs##',<,<KK'"mQ"??+ME#%774;;+>+>#FD  -=' '&s   E
E"c                2    U R                  5        H  n  g   g)NTF)_iter_reader_entries)r}   _s     r(   r   SoftReadWriteLock._any_readersQ  s    **,A -r'   c              #  $  #    U R                   b_  [        R                  " U R                   5       nU H/  n[        UR                  5      (       a  M  UR                  S4v   M1     SSS5        g[        U R                  R                  5      n[        R                  " U5       nU H:  n[        UR                  5      (       a  M  [        X2R                  -  5      S4v   M<     SSS5        g! , (       d  f       g= f! , (       d  f       g= f7f)a  
Yield ``(name, dirfd_relative)`` pairs for every live reader marker.

``dirfd_relative`` is ``True`` when *name* should be passed to ``dir_fd=``-aware syscalls; ``False``
when *name* is a full path because dirfd-relative I/O is unavailable on this platform.
NTF)	rw   rq   scandir_is_housekeeping_namer   r   rs   r   r   )r}   itentryr  s       r(   r  &SoftReadWriteLock._iter_reader_entriesV  s      +D001RE0<<#jj$..   2 DKK//0ZZ%,UZZ88lZZ78%??  &% 21 %%s@   .DC.C.&>D$C?C?%	D.
C<8D?
D	Dc                    / n U R                  5        H*  u  p4UR                  X4(       a  U R                  OS 45        M,     U H  u  p5[	        X0R
                  XS9  M     g ! [         a     g f = f)N)rQ   r   r   )r  appendrw   r   r   rQ   )r}   r   namesr   dirfd_relativefds         r(   r   &SoftReadWriteLock._break_stale_readersi  sr    .0	(,(A(A(C$dND$8$8PTUV )D HD6J6JPS_   		s   >A" "
A/.A/c                   U R                   R                     U R                  nUc
   S S S 5        gUR                  nUR                  nUR
                  (       a  U R                  OS nS S S 5        [        WWS9nUc  gUu  pgUb&  [        R                  " UR                  W5      (       d  g [        X$S9  g! , (       d  f       NU= f! [         a     g[         a     gf = f)NFr   T)rv   r-   rx   r>   r2   r@   rw   _read_markerhmaccompare_digestr   FileNotFoundErrorr   )r}   r   r>   r2   r   read_resultinfo_mtimes           r(   r   !SoftReadWriteLock._refresh_markers  s    [[!!::D| "! **KJJE-1^^T))F " #;v>" <t224::uEE	;.
 7 "!. ! 	 		s(   B77B7-	C 7
C
C 	C C c           	         [        [        R                  " 5       [        R                  " 5       [        U R                  R
                  SS9S9U l        S U l        S U l        SU l	        g )Nrb   ro   rp   T)
r*   rt   ru   r   rs   r   rv   rx   rw   ry   r   s    r(   _reset_after_fork_in_child,SoftReadWriteLock._reset_after_fork_in_child  sQ     ^^%!(t{{00"=

 
#!%r'   )rz   ry   rx   rv   rs   rw   rN   rP   r[   rR   rQ   rX   ra   )r[   rc   rX   rd   rN   r?   rO   r?   rP   rd   rQ   re   rR   rd   rf   Noner   )rX   re   rN   bool | Nonerf   zGenerator[None])rX   re   rN   r#  rf   r   rf   r"  )r   r?   rf   r"  )r[   rc   rX   rd   rN   r?   rf   rg   )r;   r:   rX   re   rN   r#  rf   r   )
r;   r:   r   rd   r   rd   rN   r?   rf   r   )r;   r:   rf   r   )r2   r   r   re   rN   r?   rf   ztuple[str, bool])r   Callable[[], bool]r   re   rN   r?   rf   r"  r   )rf   zGenerator[tuple[str, bool]])r   rd   rf   r"  )"r!   r"   r#   r$   rE   r
   rI   r%   rt   ru   rJ   r~   r   r   r   r   r   r   r   classmethodr   r   r   r   r   r   r   r   r   r  r   r   r   r&   r   r'   r(   rg   rg      s_   ,\ @S?TJ<Tnn&O
 0
 !$((,#0)0 0
 0 0 "0 &0 0 
0d QU  & RV  &ATX A A.BUY B B6," (- (&T  :
 :): :
 : 
: :* . .  .
  . 
 .D$-$- !$- 	$- $- 
$-L-(&(&( 	&(
 &( 
&(POO 	O
 O 
O4"%" 	"
 " 
"(G
@&`<&r'   rg   )	metaclassc                  J   ^  \ rS rSr          SU 4S jjrSS jrSrU =r$ )rA   i  c                F   > [         TU ]  USS9  Xl        X l        X0l        g )NT)r   daemon)rT   r~   _refresh	_interval_stop_event)r}   r   r   r   r   r_   s        r(   r~   _HeartbeatThread.__init__  s'     	d40!%r'   c                   U R                   R                  U R                  5      (       d]  U R                  5       (       d  U R                   R	                  5         g U R                   R                  U R                  5      (       d  M\  g g r   )r-  waitr,  r+  r   r   s    r(   run_HeartbeatThread.run  sZ    ""''77==??  $$& ""''77r'   )r,  r+  r-  )
r   r%  r   rd   r   rC   r   r   rf   r"  r$  )r!   r"   r#   r$   r~   r1  r&   rh   ri   s   @r(   rA   rA     sB    
&#
& 
& $	
&
 
& 

& r'   rA   r   c                  [         R                  [         R                  -  [         R                  -  [        -  n[
        (       a  Ub  [         R                  " XSUS9nO[         R                  " XS5      n U S[         R                  " 5        S[        R                  " 5        S3R                  S5      n[         R                  " XE5        [         R                  " U5        g ! [         R                  " U5        f = f)Ni  r   
ascii)rq   O_CREATO_EXCLO_WRONLYr   r   r  r   socketgethostnameencoder   r   )r   r2   r   r  r  contents         r(   r   r     s     JJ"R[[0;>EF.WWT%7WWT%(G2biik]"V-?-?-A,B"ELLWU

s   7AC$ $C<c                  [         R                  [        -  [        -  n [        (       a  Ub  [         R
                  " XUS9O[         R
                  " X5      n  [         R                  " U5      n[         R                  " U[        S-   5      n [         R                  " U5        [        U5      UR                  4$ ! [         a     g f = f! [         a     [         R                  " U5        g f = f! [         R                  " U5        f = f)Nr   r   )rq   r   r   _O_NONBLOCKr   r  r   fstatr   _MAX_MARKER_SIZEr   _parse_marker_bytesst_mtime)r   r   r  r  r  datas         r(   r  r    s     KK+%3E4D4DI[RWWT0acahahimau	"B772/!34D 	t$bkk11    	
	 	s5   9B= 4C =
C
	C

C0C3 /C00C3 3Dc                   U (       a  [        U 5      [        :  a  g  U R                  S5      n[        R
                  " SU[        R                  5      nUc  g [        US   S5      nUS:  a  g [        US   X2S   S9$ ! [         a     g f = f)	Nr5  u  
        \A                                  # start of string
        (?P<token>    [0-9a-f]{32}     ) \n # 128-bit hex token
        (?P<pid>      [1-9][0-9]{0,9}  ) \n # decimal pid: no leading zero, ≤ 10 digits
        (?P<hostname> [\x21-\x7e]{1,253})   # printable non-whitespace ASCII (RFC 1123 hostname limit)
        \n*                                 # tolerate sloppy writers that append extra newlines
        \Z                                  # end of string
        r4   
   ir2   r5   )r2   r4   r5   )	lenr@  decodeUnicodeDecodeErrorrematchVERBOSEr3   r0   )rC  textrJ  r4   s       r(   rA  rA    s     3t9//{{7# HH	 	


E }
eElB
C
YU7^Z?PQQ'  s   A> >
B
Bc                  [        XS9nUc  gUu  pVX&-
  U::  a  gUc
  [        XS9  gU  [         S[        R                  " 5        S[
        R                  " S5       3n [        (       a  Ub  [        R                  " XX3S9  O[        U 5      R                  U5         [        XsS9nUc  gUu  pU	c
  [        XsS9  g[        R                  " UR                  U	R                  5      (       d  gX:  a  g[        XsS9  g! [         a     gf = f)Nr   FTr   r   )
src_dir_fd
dst_dir_fd)r  r   _BREAK_SUFFIXrq   r   r   r   r   renamer   r   r  r  r2   )r   rQ   r   r   r  info_beforemtime_before
break_name
read_after
info_aftermtime_afters              r(   r   r     s    t3K +K
_,$6-"))+a8I8I"8M7NOJ 2IId6MJj) j8J(J
*{00*2B2BCC!J&  s    #C> C> >
D
Dc                   [        [        5         [        (       a  Ub  [        R                  " XS9  O[        U 5      R	                  5         S S S 5        g ! , (       d  f       g = fNr   )r   r  r   rq   unlinkr   r   r   s     r(   r   r   !  s>    	#	$ 2IId*J 
%	$	$s   =A
A$c               |    [         (       a  Ub  [        R                  " U S US9  g [        R                  " U S 5        g rY  )r   rq   utimer[  s     r(   r   r   *  s+    F.
tF+
tr'   c                     [         R                  " U 5      n[        R                  " UR
                  5      $ ! [         a     gf = f)NF)rq   r   r  r   S_ISREGr   )pathr  s     r(   r   r   1  s=    XXd^ <<

##  s   8 
AAc                D    U R                  S5      =(       d	    [        U ;   $ )Nr   )
startswithrP  )r   s    r(   r  r  9  s    ??38=D#88r'   c                     [         R                  " 5       q[        [        R                  5       5       H  n U R                  5         M     g r   )rt   ru   r{   listr   valuesr   r]   s    r(   _reset_all_after_forkrg  =  s5    
 $..*..01++- 2r'   c                     [        [        R                  5       5       H*  n [        [        5         U R                  SS9  S S S 5        M,     g ! , (       d  f       M>  = f)NTr   )rd  r   re  r   	Exceptionr   rf  s    r(   _cleanup_all_instancesrj  G  sB    ..01i 4( !  2  s   A
A	c                     [         (       d  [        R                  " [        5        Sq [        (       d1  [        [        S5      (       a  [        R                  " [        S9  Sqg g g )NTregister_at_fork)after_in_child)	_atexit_registeredatexitregisterrj  _fork_registeredhasattrrq   rl  rg  r   r'   r(   r|   r|   M  sL    ./!,> ? ?
+@A !@r'   )r   r   r2   r   r   r<   rf   r"  )r   r   r   r<   rf   z'tuple[_MarkerInfo | None, float] | None)rC  bytesrf   z_MarkerInfo | None)
r   r   rQ   rd   r   rd   r   r<   rf   r?   )r   r   r   r<   rf   r"  )r`  r   rf   r?   )r   r   rf   r?   r$  )JrE   
__future__r   ro  r  rq   rI  r   r9  r   sysrt   r   r   
contextlibr   r   dataclassesr   pathlibr   typingr   r	   weakrefr
   filelock._apir   filelock._errorr   filelock._softr   filelock._utilr   collections.abcr   r   r:   rP  r@  r   r   r>  platformr  supports_dir_fdr   r   r%   ru   r{   rn  rq  r   r*   r0   r7   typerG   rg   ThreadrA   r   r  rA  r   r   r   r   r  rg  rj  r|   __all__r   r'   r(   <module>r     s   ` "   	 	    
    / !  ) ' , # ' 23 	  b,*b,* <<7*Lrww":L:L/L ?R?T< Tnn&    $      $   
$ 
$ 
$.$ .bZ&+ Z&zy'' ( JN  59 2(RF *
* * 
	*
 * 
*Z 04   /3 $9.)  r'   