
    ybj                    :   % 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JrJrJr  SSKJr  SSKJr  SSKJr  SSKJrJrJr  SS	KJr  SS
KJrJrJ r J!r!J"r"J#r#J$r$J%r%  SSK&J'r'  SSK(J)r)  SSK*J+r+  SSK,J-r-J.r.J/r/  \(       a  SSK0J1r1J2r2  \S   r3Sr4S\5S'   Sr6S\5S'   \7" \SS5      r8S\5S'   \7" \SS5      r9S\5S'   \	Rt                  S:g  =(       a    \Rv                  \Rx                  ;   r=S\5S'   \" 5       r>S\5S'   \
R~                  " 5       q@S \5S!'   \A" 5       rBS"\5S#'    " S$ S%\C5      rD " S& S'\DS(9rE " S) S*\
R                  5      rGSS+.SCS, jjrHSDS- jrISS+.SES. jjrJSS+.SFS/ jjrKSGS0 jrLSS+.SHS1 jjrMSS+.         SIS2 jjrNSS+.SJS3 jjrOSKS4 jrPSLS5 jrQSMS6 jrRSNS7 jrS\" S8S99 " S: S;5      5       rT\ " S< S=5      5       rU\" S8S99 " S> S?5      5       rV\ " S@ SA5      5       rWSOSB jrX\R                  " \X5        \"" \E5        S'/rZg)PzZCross-process and cross-host reader/writer lock built on :class:`SoftFileLock` primitives.    )annotationsN)closingcontextmanagersuppress)	dataclass)isfinite)Path)TYPE_CHECKINGFinalLiteral)WeakValueDictionary)AcquireReturnProxy_ensure_current_process_fork_transition_raise_grouped_errors_register_fork_class_register_fork_object_register_owned_descriptor_unregister_owned_descriptor)Timeout)	host_name)SoftFileLock)ensure_directory_existstouch	write_all)Callable	Generator)readwritez.breakz
Final[str]_BREAK_SUFFIXi   z
Final[int]_MAX_MARKER_SIZE
O_NOFOLLOW_O_NOFOLLOW
O_NONBLOCK_O_NONBLOCKwin32zFinal[bool]_SUPPORTS_DIR_FDz2Final[WeakValueDictionary[int, SoftReadWriteLock]]_ALL_INSTANCESthreading.Lock_ALL_INSTANCES_LOCKzFinal[set[Path]]_SINGLETONS_UNDER_CONSTRUCTIONc                  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$ )_SoftRWMeta7   ,WeakValueDictionary[Path, SoftReadWriteLock]
_instanceszthreading.RLock_instances_lockT      >@N      ?blockingis_singletonheartbeat_intervalstale_thresholdpoll_intervalc               8  > [        5         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  U[        ;   a  SU< 3n
[        U
5      e[        R                  " 5       n[        R                  U5         [        TU ]	  UUUUUUUS9n	[        R                  U5        [        R                  " 5       U:w  a  Sn
[        U
5      eXR                  U'   OYU	R                  U:w  d  U	R                  U:w  a-  SU	R                   SU	R                   SU SU 3n
[!        U
5      e[#        XVU5        U	sS S S 5        $ ! [        R                  U5        f = f! , (       d  f       g = f)Nr4   z2Singleton lock construction is already active for zOLock construction cannot continue after fork; construct a new lock in the childz$Singleton lock created with timeout=z, blocking=z, cannot be changed to timeout=)r   super__call__r	   resolver1   r0   getr+   RuntimeErrorosgetpidadddiscardtimeoutr5   
ValueError_validate_intervals)cls	lock_filerD   r5   r6   r7   r8   r9   
normalizedinstancemsgconstruction_pid	__class__s               ړ/tmp/claude-0/-home-danvics-docker-quiz/c1e0577a-e42c-4a3d-b1ea-3edd61103a4e/scratchpad/stt/lib/python3.13/site-packages/filelock/_soft_rw/_sync.pyr<   _SoftRWMeta.__call__;   s    	 !7#!)#5 /+ $   )_,,.
  ~~))*5H!??Nym\C&s++#%99; .22:>G$w/!!)%1+=(7&3  0  H 3:::F99;"22kC&s++-5z*!!W,0A0AX0M:8;K;K:LKX`XiXiWj k55<I[
T  !o%#$6WA ! & 3:::F' ! s&   A$F0E1B$F1FF
F )rH   str | os.PathLike[str]rD   floatr5   boolr6   rU   r7   rT   r8   float | Noner9   rT   returnSoftReadWriteLock)__name__
__module____qualname____firstlineno____annotations__r<   __static_attributes____classcell__rM   s   @rN   r-   r-   7   s    <<$$
 8
 !$((,#8)8 8
 8 8 "8 &8 8 
8 8    r-   c                  P   \ 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 j5       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S.       S,S jjj5       rS(S jrSS.S-S jjrSS.S.S jjr        S/S jr          S0S jrS1S jr        S2S jrS3S jrS3S jr        S2S jr        S4S jrS(S jrS5S  jr S6S! jr!S7S" jr"S5S# jr#S(S$ jr$S%r%g)8rX   v   u0
  
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 invalidates the inherited instance in the child so the child cannot double-own the lock with its parent;
``release()`` on that instance is a no-op, and the child must construct a new instance 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/   r0   Tr2   Nr3   r4   c          	        [         R                  " 5       U l        [        XVU5      n[         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        [0           U [2        [5        U 5      '   S S S 5        [7        U 5        g ! , (       d  f       N= f)	Nz.statez.writez.readers)stater   readersrR   rD   internaltransactionre   F)r@   rA   _creator_pidrF   fspathrH   rD   r5   r7   r8   r9   _Paths_pathsr   _Locks	threadingLockr   re   _locks_readers_dir_fd_readers_dir_fd_token_hold_closedr*   r(   idr   )selfrH   rD   r5   r6   r7   r8   r9   s           rN   __init__SoftReadWriteLock.__init__   s    IIK-.@S`a ii	2%&);&5$1^^$F+^^$F+~~&h/

 	 /^^%!(t{{00"=

 ,015"#'
" '+N2d8$ !d# ! s    E
Ec                    [         R                  " 5       q[        5       U l        [         R
                  " 5       U l        [        R                  5         g N)	rp   rq   r*   r   r0   RLockr1   r+   clear)rG   s    rN   _reset_class_after_fork)SoftReadWriteLock._reset_class_after_fork   s6     (nn.,.'oo/&,,.ra   r5   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rx   rD   r5   s      rN   	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      rN   
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      rN   r   SoftReadWriteLock.acquire_read   s    * }}VW}@@ra   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      rN   r   SoftReadWriteLock.acquire_write  s    2 }}Wg}AAra   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   rP   )rG   rH   rD   r5   s       rN   get_lockSoftReadWriteLock.get_lock2  s    ( 999ra   c                f   U R                   [        R                  " 5       :w  a  gU R                  SS9  U R                  R
                     U R                  (       a
   SSS5        gSU l        U R                  b}  [        5          U R                  b  [        U R                  5        SU l	        U R                  Ssol        [        [        5         [        R                  " U5        SSS5        SSS5        SSS5        g! , (       d  f       N= f! , (       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.
NTforce)rk   r@   rA   r   rr   ri   rv   rs   r   rt   r   r   OSErrorclose)rx   fds     rN   r   SoftReadWriteLock.closeH  s     		+4 [[!!|| "!  DL##/%'11=4T5O5OP15D./3/C/CT,B,!'* + ( "! +* (' "!sC   
D"&D"ADD 'D/D" 
D
D
D	D""
D0Fr   c                  U R                   [        R                  " 5       :w  a  gU R                  R                     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'                  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      ?rg   dir_fd)rk   r@   rA   rr   ri   ru   rH   rw   r?   levelheartbeat_stopsetheartbeat_threadjoinr7   	is_reader_unlinkmarker_namers   _unlink_writer_marker_if_ourstoken)rx   r   holdrK   s       rN   r   SoftReadWriteLock.release_  s    		+[[!!::D|	 "!
 2$..1ARPTXJVhi"3''


a
zzA~ "! DJ "" 	!""4+B+BS+H"I>>D$$T-A-AB..tzz:- "!s   EAEE
E*c                   U R                   R                  R                  US9   [        U R                  R
                  5      =nc
   S S S 5        g Uu  pEUbE  [        R                  " UR                  U5      (       a  [        U R                  R
                  5        S S S 5        g ! , (       d  f       g = f! [         a     g f = f)Nr   )rr   re   acquire_read_markerrn   r   hmaccompare_digestr   r   r   )rx   r   r5   r   info_s         rN   r   /SoftReadWriteLock._unlink_writer_marker_if_ours  s    		""**H*=():):;;DD >= #(;(;DJJ(N(NDKK--. >==  		s;   #B8 $B'	B8 AB'B8 '
B51B8 5B8 8
CCc                  U R                   [        R                  " 5       :w  a  SU R                   S3n[	        U5      e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                  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   rR   T)r5   rD   )rk   r@   rA   rH   r?   rD   r5   rr   ri   rv   ru   _validate_reentranttimeperf_counterrj   r   r   _do_acquire_innerr   )rx   moderD   r5   rK   startacquireds          rN   r   SoftReadWriteLock._acquire  s    		+)$..)99mnCs##")/$,,w$,$44==([[!!||-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   7A
F4 G 4
G&G+c               l   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
S nU R                   R                     [        SUUS:X  a  [        R                  " 5       OS UUUU
U	S	9U l         U
R!                  5         S S S 5        Ub.  U(       a  [%        XpR&                  S
9  UeU R)                  USS9  Ue[+        U S9$ ! , (       d  f       GN:= f! ["         a  nS U l        Un S nANlS nAff = f! , (       d  f       Nz= f)NrR      r   deadliner5   zfilelock-heartbeat-x)refreshinterval
stop_eventnamer   )r   r   write_thread_idr   r   r   r   r   r   Fr   lock)rr   ri   ru   r   secrets	token_hex_acquire_writer_slot_acquire_reader_slotrp   Event_HeartbeatThread_refresh_markerr7   rw   _Hold	get_identr   BaseExceptionr   rs   r   r   )rx   r   effective_timeoutr   r5   r   r   r   r   r   	heartbeatstart_errorerrors                rN   r   #SoftReadWriteLock._do_acquire_inner  s    [[!!zz%//5 "!% " -248Q!!"%7?%)%>%>ubj%>%k"K%)%>%>ubj%>%k"K__&
$((,,!&r$xl3	
	 -1[[!!9=	 3 3 5d'#!*)	DJ$! "  ",@,@A  22552I!t,,W "!D ! $!
#$ "!s;   E3/1F%!F3
F
F"	FF%F""F%%
F3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   )
ru   r   rH   rw   r?   rp   r   r   r   r   )rx   r   r   opposite	directionrK   curs          rN   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,,ra   c                  ^ ^ T R                  5         SU U4S jjnSU U4S jjnT R                  XBUS9   T R                  XRUS9  T R                  R
                  S4$ ! [         a    T R                  TSS9  e f = f)Nc                 &   > T R                  T5      $ r|   )_claim_writer_markerrx   r   s   rN   try_claim_writer@SoftReadWriteLock._acquire_writer_slot.<locals>.try_claim_writer	  s    ,,U33ra   c                    > T R                  T5      (       d  T R                  T5      (       d  gT R                  [        R                  " 5       5        T R	                  5       (       + $ NF)_touch_writer_marker_if_oursr   _break_stale_readersr   _any_readersr   s   rN   readers_drained_touchingHSoftReadWriteLock._acquire_writer_slot.<locals>.readers_drained_touching  sN    44U;;DD]D]^cDdDd%%diik2((***ra   r   Fr   rW   rU   )_open_readers_dir	_wait_forr   r   rn   r   )rx   r   r   r5   r   r   s   ``    rN   r   &SoftReadWriteLock._acquire_writer_slot  s     	 	4 	4	+ 	+ 	'XN	NN3QYNZ {{  %''  	..uu.E	s   A A:c                (   [        U R                  R                  U R                  [        R                  " 5       S9  [        U R                  R                  5      (       a  g [        U R                  R                  U5        g! [         a     gf = f)Nr8   nowFT)_break_stale_markerrn   r   r8   r   _file_exists_atomic_create_markerFileExistsErrorr   s     rN   r   &SoftReadWriteLock._claim_writer_marker  st     	DKK--t?S?SY]YbYbYde))**	!$++"3"3U;   		s   # B 
BBc                `   [        U R                  R                  5      nUc  g  [        R                  " U[
        S-   5      n[        U5      nUb&  [        R                  " UR                  U5      (       d   [        R                  " U5        g[        [        5         [        U R                  R                  US9  S S S 5         [        R                  " U5        g! [         a     [        R                  " U5        gf = f! , (       d  f       NL= f! [        R                  " U5        f = f)NFr   r   T)_open_markerrn   r   r@   r   r!   r   r   _parse_marker_bytesr   r   r   r   r   )rx   r   r   datar   s        rN   r   .SoftReadWriteLock._touch_writer_marker_if_ours(  s     $++++,:	wwr#3a#78 't,D|4#6#6tzz5#I#I
 HHRL	 '"dkk''B/ #HHRL   HHRL
 #" HHRLsG   C 4D D D>D 
D(D  DD 
DD D-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                    > [        TR                  R                  TR                  [        R                  " 5       S9  [        TR                  R                  5      (       a  gT b  [        TTT S9  g[        TT5        g)Nr   Fr   T)r   rn   r   r8   r   r   r   )r   full_reader_pathreader_namerx   r   s   rN   try_claim_reader@SoftReadWriteLock._acquire_reader_slot.<locals>.try_claim_readerI  sh     1 14CWCW]a]f]f]hiDKK--..!%k5H  &&6>ra   r   Tr   )r   uuiduuid4hexr@   rA   rs   strr	   rn   rf   r   )rx   r   r   r5   r  r   r  r  s   ``   @@@rN   r   &SoftReadWriteLock._acquire_reader_slot=  s     	 ))*!BIIK=9%%tDKK$7$78;FG	 	 	'XN%1$NN7G$NNra   c                    U R                   R                  R                  SS9   U" 5       (       a
   S S S 5        g  S S S 5        [        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  ! , (       d  f       N= f! [         a     Nf = f)NFr   g        )rr   re   r   r   r   r   rH   r9   minmaxsleep)rx   	predicater   r5   r   	sleep_fors         rN   r   SoftReadWriteLock._wait_forV  s     [[&&...> {{ ?>" ?
 ##%Cdnn--#dnn--**I#	3x~s+CD	JJy!!  ?>  s2   #C$ CC$ C$ 
C!C$ !C$ $
C10C1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                  c  [        (       a~  [        5          [        R                   " U R                  R                  [        R"                  [%        [        SS5      -  [&        -  5      n [)        U5      nX@l        XPl        S S S 5        g g g ! , (       d  f       GN?= f! [*         aA  n [        R,                  " U5        e ! [*         a  n[/        SUU5         S nAe S nAff = fS nAff = f! , (       d  f       g = f)Ni  )r   zB exists but is not a directory or is a symlink; refusing to use itO_DIRECTORYr   z>reader directory registration and descriptor close both failed)r	   rn   rf   r   r   mkdirr@   lstatstatS_ISLNKst_modeS_ISDIRr?   rs   r'   r   openO_RDONLYgetattrr#   r   r   r   r   rt   )rx   readers_pathstrK   r   r   registration_errorclose_errors           rN   r   #SoftReadWriteLock._open_readers_diro  sr   DKK//0o&E* ' XXdkk))*<<

##4<<

+C+C[[(())klCs##',<,<!#WWT[[00"++M[\@]2]`k2kl6r:E (*$-2* $# -=' '& % 	  ) -\.' 
 		 $#s`   E7AGF	 G7
F	
GF+*G+
G5GGGGGG
G%c                    [        U R                  5       5       nU H  n  S S S 5        g   S S S 5        g! , (       d  f       g= f)NTF)r   _iter_reader_entries)rx   entriesr   s      rN   r   SoftReadWriteLock._any_readers  s@    T..01W 21 2  21 s   55
A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.

A consumer that stops early must close this generator: while suspended it holds the ``scandir`` handle open,
and leaving that to the collector surfaces as an unraisable exception inside whatever runs next.
NTF)	rs   r@   scandir_is_housekeeping_namer   r	   rn   rf   r
  )rx   itentryr  s       rN   r$  &SoftReadWriteLock._iter_reader_entries  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       5       nU H*  u  pEUR                  XE(       a  U R                  OS 45        M,     S S S 5        U H  u  pF[        X@R                  XS9  M     g ! , (       d  f       N.= f! [         a     g f = f)N)r8   r   r   )r   r$  appendrs   r   r   r8   )rx   r   namesr%  r   dirfd_relativer   s          rN   r   &SoftReadWriteLock._break_stale_readers  s    .0	2245,3(DLL$(<(<TX!YZ -4 6
 HD6J6JPS_  65  		s.   B 1A6B 6
B B B 
BB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5      n[        U5      nUb&  [        R                  " UR                  W5      (       d   [        R                  " U5        g[!        [        5         [#        X%S9  S S S 5         [        R                  " U5        g! , (       d  f       N= f! [         a     g[         a     gf = f! [         a     [        R                  " U5        gf = f! , (       d  f       Nx= f! [        R                  " U5        f = f)NFr   Tr   )rr   ri   ru   r   r   r   rs   _open_marker_fdFileNotFoundErrorr   _read_marker_fdr@   r   r   r   r   r   r   )rx   r   r   r   r   r   r   r   s           rN   r   !SoftReadWriteLock._refresh_marker  s8   [[!!::D| "! **KJJE-1^^T))F "	 V<B
	&r* 't,D |4#6#6tzz5#I#I HHRL	 '"k) #HHRLM "!" ! 	 		
   HHRL #" HHRLsp   D7D1
D =D9 4E0 E0 #
E-E0 
D
D6*	D65D69
EE0 EE0 
E-)E0 0Fc                    [        [        R                  " 5       [        R                  " 5       U R                  R                  S9U l        S U l        S U l        S U l        g )Nrh   )ro   rp   rq   rr   re   ru   rs   rt   rx   s    rN   _reset_after_fork_in_child,SoftReadWriteLock._reset_after_fork_in_child  sH    ^^%!(++##

 
#%)"ra   )rv   rk   ru   rr   rn   rs   rt   r5   r7   rH   r9   r8   rD   rQ   )rH   rS   rD   rT   r5   rU   r6   rU   r7   rT   r8   rV   r9   rT   rW   NonerW   r;  r|   )rD   rV   r5   bool | NonerW   zGenerator[None])rD   rV   r5   r=  rW   r   )rH   rS   rD   rT   r5   rU   rW   rX   )r   rU   rW   r;  )r   r
  r5   rU   rW   r;  )r   _ModerD   rV   r5   r=  rW   r   )
r   r>  r   rT   r   rT   r5   rU   rW   r   )r   r>  rW   r   )r   r
  r   rV   r5   rU   rW   ztuple[str, bool])r   r
  rW   rU   )r  Callable[[], bool]r   rV   r5   rU   rW   r;  r   )rW   zGenerator[tuple[str, bool]])r   rT   rW   r;  )&rY   rZ   r[   r\   __doc__r   r0   r]   rp   r}   r1   ry   classmethodr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r$  r   r   r9  r^   rP   ra   rN   rX   rX   v   s   +Z @S?TJ<Too'O
 '$
 !$((,#'$)'$ '$
 '$ '$ "'$ &'$ '$ 
'$R / / QU  & RV  &ATX A A.BUY B B6  :
 :): :
 : 
: :*%. (- %;N MQ  . .  .
  . 
 .D3-3- !3- 	3- 3- 
3-j-((( 	(
 ( 
(:*OO 	O
 O 
O2"%" 	"
 " 
"238@,	`'R*ra   rX   )	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)r;   ry   _refresh	_interval_stop_event)rx   r   r   r   r   rM   s        rN   ry   _HeartbeatThread.__init__  s'     	d40!%ra   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|   )rH  waitrG  rF  r   r8  s    rN   run_HeartbeatThread.run  sZ    ""''77==??  $$& ""''77ra   )rG  rF  rH  )
r   r?  r   rT   r   threading.Eventr   r
  rW   r;  r<  )rY   rZ   r[   r\   ry   rL  r^   r_   r`   s   @rN   r   r     sB    
&#
& 
& $	
&
 
& 

& ra   r   r   c                  [        XS9nUc  g  [        R                  " U5      n[        R                  " UR
                  5      (       d$  S UR                  4[        R                  " U5        $ [        R                  " U[        S-   5      n [        R                  " U5        [        U5      UR                  4$ ! [         a     [        R                  " U5        g f = f! [        R                  " U5        f = f)Nr   r   )r   r@   fstatr  S_ISREGr  st_mtimer   r   r!   r   r   )r   r   r   r  r   s        rN   r   r     s    	d	*B	zXXb\
 ||BJJ''$
 		 wwr+a/0 	t$bkk11	  
 	s*   AB: .B: :
CC  CC   C8c                >    [         R                  " U [        S-   5      $ )Nr   )r@   r   r!   r   s    rN   r5  r5    s    772'!+,,ra   c                   [         R                  [        -  [        -  n[        (       a  Ub  [         R
                  " XUS9$ [         R
                  " X5      $ Nr   )r@   r  r#   r%   r'   r  )r   r   flagss      rN   r3  r3    sD     KK+%3E2B2BvGY2774v.s_a_f_fgk_ssra   c               6     [        XS9$ ! [         a     g f = frU  )r3  r   r   r   s     rN   r   r     s$    t33 s    
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)	Nasciiu  
        \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
        pid
   ir   hostname)r   r[  r]  )	lenr!   decodeUnicodeDecodeErrorrematchVERBOSEint_MarkerInfo)r   textrb  r[  s       rN   r   r   !  s     3t9//{{7# HH	 	


E }
eElB
C
YU7^Z?PQQ'  s   A> >
B
Bc                   [        [        5         [        (       a  Ub  [        R                  " XS9  O[        U 5      R	                  5         S S S 5        g ! , (       d  f       g = frU  )r   r4  r'   r@   unlinkr	   rX  s     rN   r   r   ?  s>    	#	$ 2IId*J 
%	$	$s   =A
A$c                  [        XS9=n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   r    r@   rA   r   r   r'   renamer	   r   r   r   r   )r   r8   r   r   read_resultinfo_beforemtime_before
break_name
read_after
info_aftermtime_afters              rN   r   r   H  s    $D88A +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          	     x   [         R                  [         R                  -  [         R                  -  [        -  n[
        (       a  Ub  [         R                  " XSUS9nO[         R                  " XS5      nS n [         R                  " U5      nUR                  UR                  4n[        XA S[         R                  " 5        S[        5        S3R                  S5      5        [         R                  " U5        g ! [         a3    [         R                  " U5        Ub  [!        XUS9(       a	  [#        XS9  e f = f)Ni  r   
rZ  )r@   O_CREATO_EXCLO_WRONLYr#   r'   r  rP  st_devst_inor   rA   r   encoder   r   
_same_filer   )r   r   r   rV  r   identityr  s          rN   r   r   t  s     JJ"R[[0;>EF.WWT%7WWT%( (,H
XXb\99bii'"r"))+bR@GGPQ 	  
Jtf$MD(	s   9A,C< <=D9c                    [         (       a  Ub  [        R                  " XS9O[        R                  " U 5      nUR                  UR
                  4U:H  $ ! [         a     gf = f)Nr   F)r'   r@   r  r   ry  rz  )r   r}  r   r  s       rN   r|  r|    s\    .>.>6CURXXd*[][c[cdh[i IIryy!X--  s   8A 
A"!A"c                     [         R                  " U 5      n[        R                  " UR
                  5      $ ! [         a     gf = fr   )r@   r  r4  r  rQ  r  )pathr  s     rN   r   r     s=    XXd^ <<

##  s   8 
AAc                D    U R                  S5      =(       d	    [        U ;   $ )Nr  )
startswithr    )r   s    rN   r)  r)    s    ??38=D#88ra   c                    [        U 5      (       a  U S::  a  SU  3n[        U5      eUc  U S-  n[        U5      (       a  X::  a  SU  SU 3n[        U5      e[        U5      (       a  US::  a  SU 3n[        U5      eU$ )Nr   z4heartbeat_interval must be positive and finite, got    z0stale_threshold must exceed heartbeat_interval (z) and be finite, got z/poll_interval must be positive and finite, got )r   rE   )r7   r8   r9   rK   s       rN   rF   rF     s    &''+=+BDEWDXYo,q0O$$(M>?Q>R S""1!24 	 oM""mq&8?Oora   T)frozenc                  4    \ rS rSr% S\S'   S\S'   S\S'   Srg)rm   i  r
  re   r   rf   rP   NrY   rZ   r[   r\   r]   r^   rP   ra   rN   rm   rm     s    JJLra   rm   c                  4    \ rS rSr% S\S'   S\S'   S\S'   Srg)	ro   i  r)   ri   rj   r   re   rP   Nr  rP   ra   rN   ro   ro     s    ra   ro   c                  4    \ rS rSr% S\S'   S\S'   S\S'   Srg)	re  i  r
  r   rd  r[  r]  rP   Nr  rP   ra   rN   re  re    s    J	HMra   re  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)r   i  zYEverything that exists only while a lock is held; ``None`` when the instance has no lock.rd  r   r>  r   
int | Noner   r
  r   rU   r   r   r   r   rN  r   rP   N)rY   rZ   r[   r\   r@  r]   r^   rP   ra   rN   r   r     s1    cJ
KOJ&&##ra   r   c                     [        [        R                  5       5       H*  n [        [        5         U R                  SS9  S S S 5        M,     g ! , (       d  f       M>  = f)NTr   )listr(   valuesr   	Exceptionr   )rJ   s    rN   _cleanup_all_instancesr    sB    ..01i 4( !  2  s   A
A	)r   r
  r   r  rW   z'tuple[_MarkerInfo | None, float] | None)r   rd  rW   bytes)r   r
  r   r  rW   rd  )r   r
  r   r  rW   r  )r   r  rW   z_MarkerInfo | None)r   r
  r   r  rW   r;  )
r   r
  r8   rT   r   rT   r   r  rW   rU   )r   r
  r   r
  r   r  rW   r;  )r   r
  r}  ztuple[int, int]r   r  rW   rU   )r  r
  rW   rU   )r   r
  rW   rU   )r7   rT   r8   rV   r9   rT   rW   rT   r<  )[r@  
__future__r   atexitr   r@   ra  r   r  sysrp   r   r  
contextlibr   r   r   dataclassesr   mathr   pathlibr	   typingr
   r   r   weakrefr   filelock._apir   r   r   r   r   r   r   r   filelock._errorr   filelock._identityr   filelock._softr   filelock._utilr   r   r   collections.abcr   r   r>  r    r]   r!   r  r#   r%   platformr  supports_dir_fdr'   r(   rq   r*   r   r+   typer-   rX   Threadr   r   r5  r3  r   r   r   r   r   r|  r   r)  rF   rm   ro   re  r   r  register__all__rP   ra   rN   <module>r     sZ   ` "   	 	   
    8 8 !   0 0 '	 	 	 $ ( ' D D3 	 $z $# * #!"lA6Z 6!"lA6Z 6 !$ 7 YBGGrGYGY<Y + YEXEZB Z&/nn&6 ^ 6365  0 8<$ <~m	*+ m	*`y'' ( 59 2(- 8< t 59 R< 04   )
) ) 
	)
 ) 
)X JN 0.$9$ $      $   
$ 
$ 
$) & ' & ' ra   