
    ; jx                    N   % 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)\
RT                  S:g  =(       a    \RV                  \RX                  ;   r-\" 5       r.S\/S'   \R`                  " 5       q1Sq2Sq3\" SS9 " S S5      5       r4\ " S S5      5       r5\" SS9 " S S5      5       r6\ " S S5      5       r7 " S  S!\85      r9 " S" S#\9S$9r: " S% S&\Rv                  5      r<SS'.S3S( jjr=SS'.S4S) jjr>S5S* jr?SS'.         S6S+ jjr@SS'.S7S, jjrASS'.S7S- jjrBS8S. jrCS9S/ jrDS:S0 jrES:S1 jrFS:S2 jrGS#/rHg);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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       h/root/GenerationalWealth/GenerationalWealth/venv/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)	_Locks4   threading.Lockinternaltransactionr   r   r   Nr   r   r&   r'   r)   r)   4   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'   r/   r/   ;   s    J	HMr&   r/   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)_HoldB   zYEverything that exists only while a lock is held; ``None`` when the instance has no lock.r2   level_Modemode
int | Nonewrite_thread_idr   marker_namebool	is_readerr1   _HeartbeatThreadheartbeat_threadthreading.Eventheartbeat_stopr   N)r    r!   r"   r#   __doc__r$   r%   r   r&   r'   r6   r6   B   s1    cJ
KOJ&&##r&   r6   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$ )_SoftRWMetaP   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)NrL   z$Singleton lock created with timeout=z, blocking=z, cannot be changed to timeout=)
super__call__r   resolverI   rH   gettimeoutrM   
ValueError)cls	lock_filerW   rM   rN   rO   rP   rQ   
normalizedinstancemsg	__class__s              r'   rT   _SoftRWMeta.__call__T   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   )rZ   str | os.PathLike[str]rW   floatrM   r>   rN   r>   rO   rc   rP   float | NonerQ   rc   returnSoftReadWriteLock)r    r!   r"   r#   r$   rT   r%   __classcell__r^   s   @r'   rF   rF   P   s    <<##
 *
 !$((,#*)* *
 * * "* &* * 
* *r&   rF   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S/S jrS-S jrS&S jrS r g)0rf      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   rH   TrJ   NrK   rL   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   ra   rW   r,   r-   r   F)rX   osfspathrZ   rW   rM   rO   rP   rQ   r   _pathsr   r)   	threadingLockr   r   _locks_readers_dir_fd_hold_fork_invalidated_closed_all_instances_lockr   r   rU   _register_hooks)	selfrZ   rW   rM   rN   rO   rP   rQ   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rM   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|   rW   rM   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   ru   r,   ry   rv   r   OSErrorrp   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      ?rn   dir_fd)ru   r,   rx   rw   rZ   idRuntimeErrorr8   rC   setrA   joinrO   r?   _unlinkr=   rv   )r|   r   holdr]   s       r'   r   SoftReadWriteLock.releaseP  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   )rY   rZ   rW   rM   s       r'   get_lockSoftReadWriteLock.get_lockz  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                  R                     U R                  b>  U R                  U5      sS S S 5        U R                  R                  R                  5         $  S S S 5        US:X  a  S OXt-   n	[         R"                  " S	5      n
US
:X  a  U R%                  XUS9u  pOU R'                  XUS9u  p[(        R*                  " 5       n[-        U R.                  U R0                  US[3        U 5      S 3S9nU R                  R                     [5        SUUS
:X  a  [(        R6                  " 5       OS UUU
UUS9U l        S S S 5        UR9                  5         [;        U S9U R                  R                  R                  5         $ ! , (       d  f       GNA= f! , (       d  f       GN<= f! , (       d  f       No= f! U R                  R                  R                  5         f = f)NzSoftReadWriteLock on z4 was invalidated by fork(); construct a new instancez has been closedFr   ra   T)rM   rW      r   deadlinerM   zfilelock-heartbeat-x)refreshinterval
stop_eventnamer   )r8   r:   r<   r=   r?   r1   rA   rC   lock)rW   rM   ru   r,   rx   rZ   r   ry   rw   _validate_reentranttimeperf_counterr-   acquirer   r   secrets	token_hex_acquire_writer_slot_acquire_reader_slotrs   Eventr@   _refresh_markerrO   r   r6   	get_identstartr   )r|   r:   rW   rM   effective_timeouteffective_blockingr]   r   acquiredr   r1   r=   r?   r   	heartbeats                  r'   r   SoftReadWriteLock._acquire  s    -4ODLL.6.>T]]H[[!!%%-dnn-==qr"3''||-dnn-==MN"3''zz%//5 "! & " !!#!{{..666FH"${{..666EH{{..66N_6`H$..)t3'	.%%::)33D9 &%L KK##++-K * &  1B6tE<UH%%b)Ew)-)B)B7I *C *&Y *.)B)B7I *C *& #*J(,,00%*2d8A,7	I %%"=AW_I$7$7$9RV +'%.#-	
 & OO%40KK##++-u "!( &%. &% KK##++-sO   A6K4.L) L"	L) B-L) >1L/ L) 4
L
LL) 
L&"L) )&M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   )
rw   r:   rZ   r   r   rs   r   r<   r8   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rP   nowFT)
ru   r   _break_stale_markerrr   r   rP   r   _file_exists_atomic_create_markerFileExistsError)r|   r1   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)
ru   r   r   r   _touchrr   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re   r>   )_open_readers_dir	_wait_forr   r   rr   r   )r|   r1   r   rM   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)	ru   r   r   rr   r   rP   r   r   r   )r   full_reader_pathreader_namer|   r1   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hexrp   getpidrv   r   r   rr   r   r   )r|   r1   r   rM   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   rZ   rQ   minmaxsleep)r|   	predicater   rM   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   rr   r   r   r   mkdirrp   lstatstatS_ISLNKst_modeS_ISDIRr   rv   _SUPPORTS_DIR_FDO_RDONLYgetattr_O_NOFOLLOWopen)r|   readers_pathstr]   flagss        r'   r   #SoftReadWriteLock._open_readers_dir@  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_readersN  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)	rv   rp   scandir_is_housekeeping_namer   r   rr   r   r   )r|   itentryr   s       r'   r  &SoftReadWriteLock._iter_reader_entriesS  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)rP   r   r   )r  appendrv   r   r   rP   )r|   r   namesr   dirfd_relativefds         r'   r   &SoftReadWriteLock._break_stale_readersf  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f = f)NFr   T)ru   r,   rw   r=   r1   r?   rv   _read_markerhmaccompare_digestr   FileNotFoundError)r|   r   r=   r1   r   read_resultinfo_mtimes           r'   r   !SoftReadWriteLock._refresh_markerp  s    [[!!::D| "! **KJJE-1^^T))F " #;v>" <t224::uEE	;. ) "!$ ! 		s"   B77B7-	C 7
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 )Nra   rn   ro   T)
r)   rs   rt   r   rr   r   ru   rw   rv   rx   r   s    r'   _reset_after_fork_in_child,SoftReadWriteLock._reset_after_fork_in_child  sQ     ^^%!(t{{00"=

 
#!%r&   )ry   rx   rw   ru   rr   rv   rM   rO   rZ   rQ   rP   rW   r`   )rZ   rb   rW   rc   rM   r>   rN   r>   rO   rc   rP   rd   rQ   rc   re   Noner   )rW   rd   rM   bool | Nonere   zGenerator[None])rW   rd   rM   r   re   r   re   r  )r   r>   re   r  )rZ   rb   rW   rc   rM   r>   re   rf   )r:   r9   rW   rd   rM   r   re   r   )r:   r9   re   r   )r1   r   r   rd   rM   r>   re   ztuple[str, bool])r   Callable[[], bool]r   rd   rM   r>   re   r  r   )re   zGenerator[tuple[str, bool]])r   rc   re   r  )!r    r!   r"   r#   rD   r
   rH   r$   rs   rt   rI   r}   r   r   r   r   r   r   r   classmethodr   r   r   r   r   r   r   r   r  r   r   r  r%   r   r&   r'   rf   rf      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.D. D.
 D. 
D.L-(&(&( 	&(
 &( 
&(POO 	O
 O 
O4"%" 	"
 " 
"(G
@&`.&r&   rf   )	metaclassc                  J   ^  \ rS rSr          SU 4S jjrSS jrSrU =r$ )r@   i  c                F   > [         TU ]  USS9  Xl        X l        X0l        g )NT)r   daemon)rS   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   rc   r   rB   r   r   re   r  r!  )r    r!   r"   r#   r}   r.  r%   rg   rh   s   @r'   r@   r@     sB    
&#
& 
& $	
&
 
& 

& r&   r@   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)rp   O_CREATO_EXCLO_WRONLYr   r   r   r   socketgethostnameencoder   r   )r   r1   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   )rp   r   r   r   r   r   fstatr   _MAX_MARKER_SIZEr   _parse_marker_bytesst_mtime)r   r   r  r  r   datas         r'   r  r    s     KK+%E4D4DI[RWWT0acahahimau	"B772/!34D 	t$bkk11    	
	 	s5   9B6 4C 6
CC
C)C, (C))C, ,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)	Nr2  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
        r3   
   ir1   r4   )r1   r3   r4   )	lenr<  decodeUnicodeDecodeErrorrematchVERBOSEr2   r/   )r?  textrF  r3   s       r'   r=  r=    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_SUFFIXrp   r   r   r   r   renamer   r   r  r  r1   )r   rP   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   rp   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 rU  )r   rp   utimerW  s     r'   r   r     s+    F.
tF+
tr&   c                     [         R                  " U 5      n[        R                  " UR
                  5      $ ! [         a     gf = f)NF)rp   r   r  r   S_ISREGr   )pathr   s     r'   r   r   &  s=    XXd^ <<

##  s   8 
AAc                D    U R                  S5      =(       d	    [        U ;   $ )Nr   )
startswithrL  )r   s    r'   r	  r	  .  s    ??38=D#88r&   c                     [         R                  " 5       q[        [        R                  5       5       H  n U R                  5         M     g r   )rs   rt   rz   listr   valuesr  r\   s    r'   _reset_all_after_forkrc  2  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   )r`  r   ra  r   	Exceptionr   rb  s    r'   _cleanup_all_instancesrf  <  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registerrf  _fork_registeredhasattrrp   rh  rc  r   r&   r'   r{   r{   B  sL    ./!,> ? ?
+@A !@r&   )r   r   r1   r   r   r;   re   r  )r   r   r   r;   re   z'tuple[_MarkerInfo | None, float] | None)r?  bytesre   z_MarkerInfo | None)
r   r   rP   rc   r   rc   r   r;   re   r>   )r   r   r   r;   re   r  )r\  r   re   r>   )r   r   re   r>   r!  )IrD   
__future__r   rk  r  rp   rE  r   r6  r   sysrs   r   r   
contextlibr   r   dataclassesr   pathlibr   typingr   r	   weakrefr
   filelock._apir   filelock._errorr   filelock._softr   filelock._utilr   collections.abcr   r   r9   rL  r<  r   r   platformr   supports_dir_fdr   r   r$   rt   rz   rj  rm  r   r)   r/   r6   typerF   rf   Threadr@   r   r  r=  r   r   r   r   r	  rc  rf  r{   __all__r   r&   r'   <module>r     s   ` "   	 	    
    / !  ) ' , # ' 23 	  b,* <<7*Lrww":L:L/L ?R?T< Tnn&    $      $   
$ 
$ 
$.$ .bQ&+ Q&hy'' ( JN  59 2&RF *
* * 
	*
 * 
*Z 04   /3 $9.)  r&   