+
    ~jx                    x  a  0 t $ R t^ RIHt ^ RIt^ RIt^ RIt^ RIt^ RIt^ RI	t	^ RI
t
^ RIt^ RIt^ RIt^ RIt^ RIHtHt ^ RIHt ^ RIHt ^ RIHtHt ^ RIHt ^ RIHt ^ R	IHt ^ R
IH t  ^ RI!H"t" ]'       d	   ^ RI#H$t$H%t% ]R<,          t&Rt'Rt(])! ]R^ 4      t*]PV                  R8g  ;'       d    ]PX                  ]PZ                  9   t.]! 4       t/R]0R&   ]Pb                  ! 4       s2Rs3Rs4]! RR7       ! R R4      4       t5] ! R R4      4       t6]! RR7       ! R R4      4       t7] ! R R4      4       t8 ! R R]94      t: ! R  R!]:R"7      t; ! R# R$]Px                  4      t=R%R/R& R' llt>R%R/R( R) llt?R* R+ lt@R%R/R, R- lltAR%R/R. R/ lltBR%R/R0 R1 lltCR2 R3 ltDR4 R5 ltER6 R7 ltFR8 R9 ltGR: R; ltHR!.tIR# )=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	Generatorz.breaki   
O_NOFOLLOWwin32,WeakValueDictionary[Path, SoftReadWriteLock]_all_instancesFT)frozenc                  6    ] tR t^-t$ R]R&   R]R&   R]R&   RtR# )_Pathsstrstatewritereaders N__name__
__module____qualname____firstlineno____annotations____static_attributes__r       l/Users/mitch_tango/dev/rabbit-r1-livekit/agent/.venv/lib/python3.14/site-packages/filelock/_soft_rw/_sync.pyr   r   -   s    JJLr#   r   c                  6    ] tR t^4t$ R]R&   R]R&   R]R&   RtR# )_Locksthreading.Lockinternaltransactionr   r   r   Nr   r   r#   r$   r&   r&   4   s    r#   r&   c                  6    ] tR t^;t$ R]R&   R]R&   R]R&   RtR# )_MarkerInfor   tokenintpidhostnamer   Nr   r   r#   r$   r+   r+   ;   s    J	HMr#   r+   c                  l    ] tR t^Bt$ RtR]R&   R]R&   R]R&   R]R	&   R
]R&   R]R&   R]R&   R]R&   RtR# )_HoldzYEverything that exists only while a lock is held; ``None`` when the instance has no lock.r-   level_Modemode
int | Nonewrite_thread_idr   marker_namebool	is_readerr,   _HeartbeatThreadheartbeat_threadthreading.Eventheartbeat_stopr   N)r   r   r   r    __doc__r!   r"   r   r#   r$   r1   r1   B   s1    cJ
KOJ&&##r#   r1   c                  `   a  ] tR t^Pt$ R]R&   R]R&   RRRRRRR	R
RRR/R V 3R lllltRtV ;t# )_SoftRWMetar   
_instancesr'   _instances_lockblockingTis_singletonheartbeat_interval      >@stale_thresholdNpoll_interval      ?c               8    V ^8  d   QhRRRRRRRRRRR	R
RRRR/# )   	lock_filestr | os.PathLike[str]timeoutfloatrC   r8   rD   rE   rG   float | NonerH   returnSoftReadWriteLockr   )formats   "r$   __annotate___SoftRWMeta.__annotate__T   sZ     * *)* *
 * * "* &* * 
*r#   c               	  < V'       g   \         SV `  VVVVVVVR 7      # \        V4      P                  4       pV P                  ;_uu_ 4        V P
                  P                  V4      p	V	f&   \         SV `  VVVVVVVR 7      p	WP
                  V&   MOV	P                  V8w  g   V	P                  V8w  d.   RV	P                   RV	P                   RV RV 2p
\        V
4      hV	uuRRR4       #   + '       g   i     R# ; i))rC   rD   rE   rG   rH   Nz$Singleton lock created with timeout=z, blocking=z, cannot be changed to timeout=)
super__call__r   resolverB   rA   getrN   rC   
ValueError)clsrL   rN   rC   rD   rE   rG   rH   
normalizedinstancemsg	__class__s   &&&$$$$$   r$   rX   _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   )r   r   r   r    r!   rX   r"   __classcell__r`   s   @r$   r@   r@   P   sP    <<##*
 * "* %)* )-*  $* * *r#   r@   c                     ] tR t^t$ Rt]! 4       tR]R&   ]P                  ! 4       t
R6RRRRRRR	R
RR/R R lllt]R7RR
/R R lll4       t]R7RR
/R R lll4       tR7RR
/R R llltR7RR
/R R llltR R ltRR/R R llt]R6RR/R R lll4       tR R  ltR! R" ltR# R$ ltR% R& ltR' R( ltR) R* ltR+ R, ltR- R. ltR/ R0 ltR1 R2 ltR3 R4 ltR5t R
# )8rR   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   rA   rC   TrD   rE   rF   rG   NrH   rI   c               8    V ^8  d   QhRRRRRRRRRRR	R
RRRR/# )rK   rL   rM   rN   rO   rC   r8   rD   rE   rG   rP   rH   rQ   Noner   )rS   s   "r$   rT   SoftReadWriteLock.__annotate__   sZ     0 0)0 0
 0 0 "0 &0 0 
0r#   c          	     	f   V^ 8:  d   RV 2p\        V4      hVf
   V^,          pWe8:  d   RV RV R2p\        V4      hV^ 8:  d   RV 2p\        V4      h\        P                  ! V4      V n        W n        W0n        WPn        W`n        Wpn        \        V P                   R2V P                   R2V P                   R	2R
7      V n
        \        V P                  4       \        \        P                  ! 4       \        P                  ! 4       \        V P                  P                   RR7      R7      V n        RV n        RV n        RV n        RV n        \,        ;_uu_ 4        V \.        \1        V P                  4      P3                  4       &   \5        4        RRR4       R#   + '       g   i     R# ; i)    z)heartbeat_interval must be positive, got Nz0stale_threshold must exceed heartbeat_interval (z <= )z$poll_interval must be positive, got z.statez.writez.readers)r   r   r   rN   r(   r)   r   Frc   )r[   osfspathrL   rN   rC   rE   rG   rH   r   _pathsr   r&   	threadingLockr   r   _locks_readers_dir_fd_hold_fork_invalidated_closed_all_instances_lockr   r   rY   _register_hooks)	selfrL   rN   rC   rD   rE   rG   rH   r_   s	   &&&$$$$$ r$   __init__SoftReadWriteLock.__init__   sy    "=>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F0	c               $    V ^8  d   QhRRRRRR/# rK   rN   rP   rC   bool | NonerQ   zGenerator[None]r   )rS   s   "r$   rT   ri      s"       ; Zi r#   c             #     "   V P                  WR7        Rx  V P                  4        R#   T P                  4        i ; i5i)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

rC   N)acquire_readreleaser{   rN   rC   s   &&$r$   	read_lockSoftReadWriteLock.read_lock   s2      	'5	LLNDLLN   A, A>Ac               $    V ^8  d   QhRRRRRR/# r   r   )rS   s   "r$   rT   ri      s"      , K [j r#   c             #     "   V P                  WR7        Rx  V P                  4        R#   T P                  4        i ; i5i)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               $    V ^8  d   QhRRRRRR/# rK   rN   rP   rC   r   rQ   r
   r   )rS   s   "r$   rT   ri     s'     A AL Ak A]o Ar#   c               (    V P                  RWR7      # )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

readr   _acquirer   s   &&$r$   r   SoftReadWriteLock.acquire_read  s    * }}VW}@@r#   c               $    V ^8  d   QhRRRRRR/# r   r   )rS   s   "r$   rT   ri   $  s'     B B\ B{ B^p Br#   c               (    V P                  RWR7      # )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                   V ^8  d   QhRR/# rK   rQ   rh   r   )rS   s   "r$   rT   ri   ?  s     , ,t ,r#   c           	        V P                  RR7       V P                  P                  ;_uu_ 4        V P                  '       d    RRR4       R# RV n        V P                  eH   \        \        4      ;_uu_ 4        \        P                  ! V P                  4       RRR4       RV n        RRR4       R#   + '       g   i     L!; i  + '       g   i     R# ; i)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   rt   r(   rx   ru   r   OSErrorro   closer{   s   &r$   r   SoftReadWriteLock.close?  s     	4 [[!!!||| "!  DL##/g&&HHT112 ''+$ "!
 '& "!!s)   C,C;!B5	C5C CC	r   Fc                    V ^8  d   QhRRRR/# )rK   r   r8   rQ   rh   r   )rS   s   "r$   rT   ri   P  s     (& (& (& (&r#   c                  V P                   P                  ;_uu_ 4        V P                  '       d   RV n         RRR4       R# V P                  pVf;   V'       d    RRR4       R# RV P                   R\        V 4       R2p\        V4      hV'       d	   ^ Vn        MV;P                  ^,          un        VP                  ^ 8  d    RRR4       R# RV n        RRR4       XP                  P                  4        VP                  P                  V P                  R,           R7       VP                  '       d$   \        VP                  V P                   R7       R# \        VP                  4       R#   + '       g   i     L; i)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 heldg      ?rm   dir_fd)rt   r(   rw   rv   rL   idRuntimeErrorr2   r=   setr;   joinrE   r9   _unlinkr7   ru   )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)   E5E5E5'.E53E5E55F	c               (    V ^8  d   QhRRRRRRRR/# )	rK   rL   rM   rN   rO   rC   r8   rQ   rR   r   )rS   s   "r$   rT   ri   {  s2     : :): :
 : 
:r#   c                   V ! WVR7      # )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   )r\   rL   rN   rC   s   &&&$r$   get_lockSoftReadWriteLock.get_lockz  s    ( 999r#   c               (    V ^8  d   QhRRRRRRRR/# )	rK   r4   r3   rN   rP   rC   r   rQ   r
   r   )rS   s   "r$   rT   ri     s8     D. D.D. D.
 D. 
D.r#   c               	4   Vf   V P                   MTpVf   V P                  MTpV P                  P                  ;_uu_ 4        V P                  '       d   RV P
                   R2p\        V4      hV P                  '       d   RV P
                   R2p\        V4      hV P                  e   V P                  V4      uuR R R 4       #  R R R 4       \        P                  ! 4       pV'       g(   V P                  P                  P                  RR7      pMUVR8X  d(   V P                  P                  P                  RR7      pM'V P                  P                  P                  RVR7      pV'       g   \        V P
                  4      R h V P                  P                  ;_uu_ 4        V P                  e@   V P                  V4      uuR R R 4       V P                  P                  P                  4        #  R R R 4       VR8X  d   R MWt,           p	\         P"                  ! ^4      p
VR8X  d   V P%                  WVR	7      w  rMV P'                  WVR	7      w  r\(        P*                  ! 4       p\-        V P.                  V P0                  VR
\3        V 4      R 2R7      pV P                  P                  ;_uu_ 4        \5        ^TVR8X  d   \(        P6                  ! 4       MR VVV
VVR7      V n        R R R 4       VP9                  4        \;        V R7      V P                  P                  P                  4        #   + '       g   i     ELw; i  + '       g   i     EL^; i  + '       g   i     Lx; i  T P                  P                  P                  4        i ; i)NzSoftReadWriteLock on z4 was invalidated by fork(); construct a new instancez has been closedFr   T)rC   rN   r   deadlinerC   zfilelock-heartbeat-x)refreshinterval
stop_eventname)r2   r4   r6   r7   r9   r,   r;   r=   lockrc   )rN   rC   rt   r(   rw   rL   r   rx   rv   _validate_reentranttimeperf_counterr)   acquirer   r   secrets	token_hex_acquire_writer_slot_acquire_reader_slotrr   Eventr:   _refresh_markerrE   r   r1   	get_identstartr
   )r{   r4   rN   rC   effective_timeouteffective_blockingr_   r   acquiredr   r,   r7   r9   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##++-sU   ?L69L6M1 &M

M1 5CM1 95M.#M1 6M	
M		M1 M.	)M1 1&Nc                    V ^8  d   QhRRRR/# )rK   r4   r3   rQ   r
   r   )rS   s   "r$   rT   ri     s     - - -2D -r#   c                	   V P                   pVf   Q hVP                  V8w  dG   VR8X  d   RMRpVR8X  d   RMRpRV RV P                   R\        V 4       RV R	V R
2p\	        V4      hVR8X  d\   \
        P                  ! 4       ;qbP                  8w  d7   RV P                   R\        V 4       RV RVP                   2p\	        V4      hV;P                  ^,          un        \        V R7      # )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   )
rv   r4   rL   r   r   rr   r   r6   r2   r
   )r{   r4   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               (    V ^8  d   QhRRRRRRRR/# 	rK   r,   r   r   rP   rC   r8   rQ   ztuple[str, bool]r   )rS   s   "r$   rT   ri     s2     &( &(&( 	&(
 &( 
&(r#   c               	(  a a S P                  4        R  V V3R llpR V 3R llpS P                  WBVR7        S P                  WRVR7       S P                  P
                  R3#   \         d"    \        S P                  P
                  4       h i ; i)c                   V ^8  d   QhRR/# rK   rQ   r8   r   )rS   s   "r$   rT   <SoftReadWriteLock._acquire_writer_slot.<locals>.__annotate__  s     		 		$ 		r#   c                   < S P                   P                  ;_uu_ 4        \        S P                  P                  S P
                  \        P                  ! 4       R 7       \        S P                  P                  4      '       d    RRR4       R#  \        S P                  P                  S4        RRR4       R#   \         d     RRR4       R# i ; i  + '       g   i     R# ; i)rG   nowNFT)
rt   r   _break_stale_markerrq   r   rG   r   _file_exists_atomic_create_markerFileExistsError)r{   r,   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CCCC'	c                   V ^8  d   QhRR/# r   r   )rS   s   "r$   rT   r      s     	/ 	/$ 	/r#   c            	       < S P                   P                  ;_uu_ 4        \        \        4      ;_uu_ 4        \	        S P
                  P                  4       R R R 4       S P                  \        P                  ! 4       4       S P                  4       '       * uuR R R 4       #   + '       g   i     LS; i  + '       g   i     R # ; iN)
rt   r   r   r   _touchrq   r   _break_stale_readersr   _any_readersr   s   r$   readers_drained_touchingHSoftReadWriteLock._acquire_writer_slot.<locals>.readers_drained_touching   sw    """ g&&4;;,,- '))$))+6,,.. #" '& #""s#   B6 B#	A B6#B3.B66C	r   F)_open_readers_dir	_wait_forr   r   rq   r   )r{   r,   r   rC   r   r   s   ff$$  r$   r   &SoftReadWriteLock._acquire_writer_slot  s     	 		 			/ 	/ 	'XN	NN3QYNZ
 {{  %''	  	DKK%%&	s   A% %,Bc               (    V ^8  d   QhRRRRRRRR/# r   r   )rS   s   "r$   rT   ri     s8     O OO 	O
 O 
Or#   c               	h  a aaaa S P                  4        \        P                  ! 4       P                   R \        P
                  ! 4        2oS P                  o\        \        S P                  P                  4      S,          4      oR VVVV V3R llpS P                  WBVR7       Se   SR3# SR3# ).c                   V ^8  d   QhRR/# r   r   )rS   s   "r$   rT   <SoftReadWriteLock._acquire_reader_slot.<locals>.__annotate__  s     		 		$ 		r#   c                   < SP                   P                  ;_uu_ 4        \        SP                  P                  SP
                  \        P                  ! 4       R 7       \        SP                  P                  4      '       d    RRR4       R# S e   \        SSS R7       M\        SS4        RRR4       R#   + '       g   i     R# ; i)r   NFr   T)	rt   r   r   rq   r   rG   r   r   r   )r   full_reader_pathreader_namer{   r,   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::C	r   T)r   uuiduuid4hexro   getpidru   r   r   rq   r   r   )r{   r,   r   rC   r   r   r   r   s   ff$$ @@@r$   r   &SoftReadWriteLock._acquire_reader_slot  s     	 ))*!BIIK=9%%tDKK$7$78;FG		 		 	'XN%1$NN7G$NNr#   c               (    V ^8  d   QhRRRRRRRR/# )	rK   	predicateCallable[[], bool]r   rP   rC   r8   rQ   rh   r   )rS   s   "r$   rT   ri   ,  s2     " "%" 	"
 " 
"r#   c               	L    V! 4       '       d   R# \         P                  ! 4       pV'       g   \        V P                  4      hVe   WB8  d   \        V P                  4      hV P                  pVe   \        V\        W$,
          R4      4      p\         P                  ! V4       K  )TNg        )r   r   r   rL   rH   minmaxsleep)r{   r   r   rC   r   	sleep_fors   &&$$  r$   r   SoftReadWriteLock._wait_for,  s|     {{##%Cdnn--#dnn--**I#	3x~s+CD	JJy!r#   c                   V ^8  d   QhRR/# r   r   )rS   s   "r$   rT   ri   @  s     G G4 Gr#   c                	   \        V P                  P                  4      p\        \        4      ;_uu_ 4        VP                  R R7       RRR4       \        P                  ! V P                  P                  4      p\        P                  ! VP                  4      '       g'   \        P                  ! VP                  4      '       g%   V P                  P                   R2p\        V4      hV P                  fr   \        '       dd   \        P                  \!        \        R^ 4      ,          \"        ,          p\        P$                  ! V P                  P                  V4      V n        R# R# R#   + '       g   i     EL,; i)i  )r4   NzB exists but is not a directory or is a symlink; refusing to use itO_DIRECTORY)r   rq   r   r   r   mkdirro   lstatstatS_ISLNKst_modeS_ISDIRr   ru   _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                   V ^8  d   QhRR/# r   r   )rS   s   "r$   rT   ri   N  s      d r#   c                	6    V P                  4        F  p R # 	  R# )TF)_iter_reader_entries)r{   _s   & r$   r   SoftReadWriteLock._any_readersN  s    **,A -r#   c                   V ^8  d   QhRR/# )rK   rQ   zGenerator[tuple[str, bool]]r   )rS   s   "r$   rT   ri   S  s     @ @&A @r#   c              #  b  "   V P                   ej   \        P                  ! V P                   4      ;_uu_ 4       pV F0  p\        VP                  4      '       d   K   VP                  R3x  K2  	  RRR4       R# \        V P                  P                  4      p\        P                  ! V4      ;_uu_ 4       pV F?  p\        VP                  4      '       d   K   \        W2P                  ,          4      R3x  KA  	  RRR4       R#   + '       g   i     R# ; i  + '       g   i     R# ; i5i)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)	ru   ro   scandir_is_housekeeping_namer   r   rq   r   r   )r{   itentryr  s   &   r$   r  &SoftReadWriteLock._iter_reader_entriesS  s      +D0011RE0<<#jj$..   2 DKK//0ZZ%%,UZZ88lZZ78%??  &% 21 %%%sA   7D/DD0AD/7D#D=
D/D		D/D,	&	D/c                    V ^8  d   QhRRRR/# )rK   r   rO   rQ   rh   r   )rS   s   "r$   rT   ri   f  s     ` ` `$ `r#   c                	    . p V P                  4        F+  w  r4TP                  Y4'       d   V P                  MR 34       K-  	  T F  w  r5\	        Y0P
                  YR7       K  	  R #   \         d     R # i ; i)N)rG   r   r   )r  appendru   r   r   rG   )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' 'A65A6c                   V ^8  d   QhRR/# r   r   )rS   s   "r$   rT   ri   p  s       r#   c                	   V P                   P                  ;_uu_ 4        V P                  pVf    R R R 4       R# VP                  pVP                  pVP
                  '       d   V P                  MR pR R R 4       \        XXR7      pVf   R# Vw  rgVe(   \        P                  ! VP                  X4      '       g   R#  \        W$R7       R#   + '       g   i     Lc; i  \         d     R# i ; i)NFr   T)rt   r(   rv   r7   r,   r9   ru   _read_markerhmaccompare_digestr   FileNotFoundError)r{   r   r7   r,   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(   C)C%C C! C	!C0/C0c                   V ^8  d   QhRR/# r   r   )rS   s   "r$   rT   ri     s     & &D &r#   c           	     	    \        \        P                  ! 4       \        P                  ! 4       \        V P                  P
                  RR7      R7      V n        RV n        RV n        RV n	        R# )   rm   rn   NTrc   )
r&   rr   rs   r   rq   r   rt   rv   ru   rw   r   s   &r$   _reset_after_fork_in_child,SoftReadWriteLock._reset_after_fork_in_child  sQ     ^^%!(t{{00"=

 
#!%r#   )rx   rw   rv   rt   rq   ru   rC   rE   rL   rH   rG   rN   rb   r   )!r   r   r   r    r>   r	   rA   r!   rr   rs   rB   r|   r   r   r   r   r   r   r   classmethodr   r   r   r   r   r   r   r   r  r   r   r9  r"   r   r#   r$   rR   rR      s8   ,\ @S?TJ<Tnn&O0
 0 "0 %)0 )-0  $0 0d QU  & RV  &ATX A A.BUY B B6,"(&u (&T :
 : :*D.L-(&(PO4"(G
@&`.& &r#   rR   )	metaclassc                  :   a  ] tR tRtR V 3R lltR R ltRtV ;t# )r:   i  c          
     ,    V ^8  d   QhRRRRRRRRR	R
/# )rK   r   r   r   rO   r   r<   r   r   rQ   rh   r   )rS   s   "r$   rT   _HeartbeatThread.__annotate__  s<     
& 
&#
& 
& $	
&
 
& 

&r#   c                	N   < \         SV `  VR R7       Wn        W n        W0n        R# )T)r   daemonN)rW   r|   _refresh	_interval_stop_event)r{   r   r   r   r   r`   s   &&&&&r$   r|   _HeartbeatThread.__init__  s'     	d40!%r#   c                   V ^8  d   QhRR/# r   r   )rS   s   "r$   rT   r?    s      T r#   c                	    V P                   P                  V P                  4      '       g5   V P                  4       '       d   KC  V P                   P	                  4        R # R # r   )rD  waitrC  rB  r   r   s   &r$   run_HeartbeatThread.run  sB    ""''77==??  $$& 8r#   )rC  rB  rD  )r   r   r   r    r|   rI  r"   rd   re   s   @r$   r:   r:     s    
& 
& r#   r:   r   c               (    V ^8  d   QhRRRRRRRR/# )rK   r   r   r,   r   r5   rQ   rh   r   )rS   s   "r$   rT   rT     s)       C J RV r#   c               "   \         P                  \         P                  ,          \         P                  ,          \        ,          p\
        '       d   Ve   \         P                  ! WRVR7      pM\         P                  ! WR4      p V R\         P                  ! 4        R\        P                  ! 4        R2P                  R4      p\         P                  ! WE4       \         P                  ! V4       R #   \         P                  ! T4       i ; i)Ni  r   
ascii)ro   O_CREATO_EXCLO_WRONLYr  r  r  r   socketgethostnameencoder   r   )r   r,   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   AC6 6Dc               $    V ^8  d   QhRRRRRR/# )rK   r   r   r   r5   rQ   z'tuple[_MarkerInfo | None, float] | Noner   )rS   s   "r$   rT   rT     s"     2 2s 2z 2=d 2r#   c               0   \         P                  \        ,          p \        '       d   Ve   \         P                  ! WVR7      M\         P                  ! W4      p  \         P                  ! T4      p\         P                  ! T\        ^,           4      p \         P                  ! T4       \        T4      TP                  3#   \
         d     R # i ; i  \
         d     \         P                  ! T4       R # i ; i  \         P                  ! T4       i ; iNr   )ro   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    	
	 	s:   C 2C 8C CCC: C= 9C::C= =Dc                    V ^8  d   QhRRRR/# )rK   r]  bytesrQ   z_MarkerInfo | Noner   )rS   s   "r$   rT   rT     s     R Re R(: Rr#   c                L   V '       d   \        V 4      \        8  d   R #  V P                  R4      p\        P
                  ! RT\        P                  4      pTf   R # \        TR,          ^
4      pTR8  d   R # \        TR,          Y2R,          R7      #   \         d     R # i ; i)NrN  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
        r.   r,   r/   )r,   r.   r/   i)	lenrZ  decodeUnicodeDecodeErrorrematchVERBOSEr-   r+   )r]  textre  r.   s   &   r$   r[  r[    s     3t9//{{7# HH	 	


E }
eElB
C
YU7^Z?PQQ'  s   B B#"B#c          
     ,    V ^8  d   QhRRRRRRRRRR	/# )
rK   r   r   rG   rO   r   r   r5   rQ   r8   r   )rS   s   "r$   rT   rT     s<     * *
* * 
	*
 * 
*r#   c               n   \        WR 7      pVf   R# Vw  rVW&,
          V8:  d   R# Vf   \        WR 7       R# V  \         R\        P                  ! 4        R\
        P                  ! ^4       2p \        '       d   Ve   \        P                  ! WW3R7       M\        V 4      P                  V4        \        WsR 7      pVf   R# Vw  rV	f   \        WsR 7       R# \        P                  ! VP                  V	P                  4      '       g   R# W8  d   R# \        WsR 7       R#   \         d     R# i ; i)r   FTr   )
src_dir_fd
dst_dir_fd)r.  r   _BREAK_SUFFIXro   r   r   r   r  renamer   r   r/  r0  r,   )r   rG   r   r   r2  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   0D% <D% D% %D43D4c               $    V ^8  d   QhRRRRRR/# rK   r   r   r   r5   rQ   rh   r   )rS   s   "r$   rT   rT     s!        #  *    r#   c                   \        \        4      ;_uu_ 4        \        '       d   Ve   \        P                  ! WR7       M\        V 4      P	                  4        R R R 4       R #   + '       g   i     R # ; irX  )r   r1  r  ro   unlinkr   r   r   s   &$r$   r   r     sD    	#	$	$ 2IId*J 
%	$	$	$s   AA$$A5	c               $    V ^8  d   QhRRRRRR/# ru  r   )rS   s   "r$   rT   rT     s!        t r#   c                   \         '       d    Ve   \        P                  ! V R VR7       R # \        P                  ! V R 4       R # rX  )r  ro   utimerx  s   &$r$   r   r     s+    F.
tF+
tr#   c                    V ^8  d   QhRRRR/# )rK   pathr   rQ   r8   r   )rS   s   "r$   rT   rT   &  s     $ $s $t $r#   c                     \         P                  ! V 4      p\        P                  ! TP
                  4      #   \         d     R # i ; i)F)ro   r  r1  r  S_ISREGr  )r}  r  s   & r$   r   r   &  s=    XXd^ <<

##  s   8 AAc                    V ^8  d   QhRRRR/# )rK   r   r   rQ   r8   r   )rS   s   "r$   rT   rT   .  s     9 9 9 9r#   c                F    V P                  R 4      ;'       g
    \        V 9   # )r   )
startswithrl  )r   s   &r$   r!  r!  .  s    ??388=D#88r#   c                   V ^8  d   QhRR/# r   r   )rS   s   "r$   rT   rT   2  s     . .t .r#   c                     \         P                  ! 4       s\        \        P                  4       4       F  p V P                  4        K  	  R # r   )rr   rs   ry   listr   valuesr9  r^   s    r$   _reset_all_after_forkr  2  s5    
 $..*..01++- 2r#   c                   V ^8  d   QhRR/# r   r   )rS   s   "r$   rT   rT   <  s     ) ) )r#   c                     \        \        P                  4       4       F5  p \        \        4      ;_uu_ 4        V P                  R R7       RRR4       K7  	  R#   + '       g   i     KL  ; i)Tr   N)r  r   r  r   	Exceptionr   r  s    r$   _cleanup_all_instancesr  <  sH    ..01i  4( !  2   s   AA*c                   V ^8  d   QhRR/# r   r   )rS   s   "r$   rT   rT   B  s          r#   c                     \         '       g   \        P                  ! \        4       R s \        '       g8   \        \        R4      '       d    \        P                  ! \        R7       R sR# R# R# )Tregister_at_fork)after_in_childN)	_atexit_registeredatexitregisterr  _fork_registeredhasattrro   r  r  r   r#   r$   rz   rz   B  sL    ./!,> ? ?
+@A !@r#   )r   r   )J__conditional_annotations__r>   
__future__r   r  r/  ro   rd  r   rR  r  sysrr   r   r   
contextlibr   r   dataclassesr   pathlibr   typingr   r   weakrefr	   filelock._apir
   filelock._errorr   filelock._softr   filelock._utilr   collections.abcr   r   r3   rl  rZ  r  r  platformr  supports_dir_fdr  r   r!   rs   ry   r  r  r   r&   r+   r1   typer@   rR   Threadr:   r   r.  r[  r   r   r   r   r!  r  r  rz   __all__)r  s   @r$   <module>r     s   ` "   	 	    
    / !  ) ' , # ' 23 	  b,* <<7*LLrww":L:L/L ?R?T< Tnn&    $      $   
$ 
$ 
$.$ .bQ&+ Q&hy'' ( 2D 2&R<*
 *Z t  d $9.)  r#   