
    *pj                        % 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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*J+r+J,r,  \(       a  SSK-J.r.J/r/  \S   r0Sr1S\2S'   Sr3S\2S'   \4" \SS5      r5S\2S'   \4" \SS5      r6S\2S'   \
Rn                  S:g  =(       a    \Rp                  \Rr                  ;   r:S\2S'   \" 5       r;S\2S'   \Rx                  " 5       q=S\2S'   \>" 5       r?S \2S!'    " S" S#\@5      rA " S$ S%\AS&9rB " S' S(\R                  5      rDSS).S@S* jjrESAS+ jrFSS).SBS, jjrGSS).SCS- jjrHSDS. jrISS).SES/ jjrJSS).         SFS0 jjrKSS).SGS1 jjrLSHS2 jrMSIS3 jrNSJS4 jrO\" S5S69 " S7 S85      5       rP\ " S9 S:5      5       rQ\" S5S69 " S; S<5      5       rR\ " S= S>5      5       rSSKS? jrT\R                  " \T5        \!" \B5        S%/rVg)LzZCross-process and cross-host reader/writer lock built on :class:`SoftFileLock` primitives.    )annotationsN)closingcontextmanagersuppress)	dataclass)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)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$ )_SoftRWMeta6   ,WeakValueDictionary[Path, SoftReadWriteLock]
_instanceszthreading.RLock_instances_lockT      >@N      ?blockingis_singletonheartbeat_intervalstale_thresholdpoll_intervalc                  > [        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'   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        $ ! [        R                  U5        f = f! , (       d  f       g = f)Nr2   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   resolver/   r.   getr)   RuntimeErrorosgetpidadddiscardtimeoutr3   
ValueError)cls	lock_filerB   r3   r4   r5   r6   r7   
normalizedinstancemsgconstruction_pid	__class__s               S/var/www/html/pdf-tiff/venv/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%= ! & 3:::F' ! s&   A$E?0E%BE?%E<<E??
F )rE   str | os.PathLike[str]rB   floatr3   boolr4   rR   r5   rQ   r6   float | Noner7   rQ   returnSoftReadWriteLock)__name__
__module____qualname____firstlineno____annotations__r:   __static_attributes____classcell__rJ   s   @rK   r+   r+   6   s    <<$$
 6
 !$((,#6)6 6
 6 6 "6 &6 6 
6 6    r+   c                  H   \ 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 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)8rU   s   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-   r.   Tr0   Nr1   r2   c          	     2   [         R                  " 5       U l        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        [0           U [2        [5        U 5      '   S S S 5        [7        U 5        g ! , (       d  f       N= 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)stater   readersrO   rB   internaltransactionrd   F)r>   r?   _creator_pidrC   fspathrE   rB   r3   r5   r6   r7   _Paths_pathsr   _Locks	threadingLockr   rd   _locks_readers_dir_fd_readers_dir_fd_token_hold_closedr(   r&   idr   )	selfrE   rB   r3   r4   r5   r6   r7   rH   s	            rK   __init__SoftReadWriteLock.__init__   sw    IIK"=>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15"#'
" '+N2d8$ !d# ! s   !F
Fc                    [         R                  " 5       q[        5       U l        [         R
                  " 5       U l        [        R                  5         g N)	ro   rp   r(   r   r.   RLockr/   r)   clear)rD   s    rK   _reset_class_after_fork)SoftReadWriteLock._reset_class_after_fork   s6     (nn.,.'oo/&,,.r^   r3   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rw   rB   r3   s      rK   	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      rK   
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      rK   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      rK   r   SoftReadWriteLock.acquire_write  s    2 }}Wg}AAr^   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   rM   )rD   rE   rB   r3   s       rK   get_lockSoftReadWriteLock.get_lock9  s    ( 999r^   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)rj   r>   r?   r   rq   rh   ru   rr   r   rs   r   r   OSErrorclose)rw   fds     rK   r   SoftReadWriteLock.closeO  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      ?rf   dir_fd)rj   r>   r?   rq   rh   rt   rE   rv   r=   levelheartbeat_stopsetheartbeat_threadjoinr5   	is_reader_unlinkmarker_namerr   _unlink_writer_marker_if_ourstoken)rw   r   holdrH   s       rK   r   SoftReadWriteLock.releasef  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                h   U R                   R                     [        U R                  R                  5      =nc
   S S S 5        g Uu  p4Ub&  [
        R                  " UR                  U5      (       d
   S S S 5        g [        U R                  R                  5        S S S 5        g ! , (       d  f       g = fr{   )	rq   rd   _read_markerrm   r   hmaccompare_digestr   r   )rw   r   r   info_s        rK   r   /SoftReadWriteLock._unlink_writer_marker_if_ours  s     [[$T[[%6%677@  GD|4#6#6tzz5#I#I  DKK%%& s   $B#.B#;B##
B1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   rO   T)r3   rB   )rj   r>   r?   rE   r=   rB   r3   rq   rh   ru   rt   _validate_reentranttimeperf_counterri   acquirer   _do_acquire_innerr   )rw   moderB   r3   rH   startacquireds          rK   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               n   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5        Ue[+        U S9$ ! , (       d  f       GN;= f! ["         a  nS U l        Un S nANmS nAff = f! , (       d  f       N{= f)NrO      r   deadliner3   zfilelock-heartbeat-x)refreshinterval
stop_eventnamer   )r   r   write_thread_idr   r   r   r   r   r   lock)rq   rh   rt   r   secrets	token_hex_acquire_writer_slot_acquire_reader_slotro   Event_HeartbeatThread_refresh_markerr5   rv   _Hold	get_identr   BaseExceptionr   rr   r   r   )rw   r   effective_timeoutr   r3   r   r   r   r   r   	heartbeatstart_errorerrors                rK   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259!t,,W "!D ! $!
#$ "!s;   E4/1F&!F4
F
F#	FF&F##F&&
F4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   )
rt   r   rE   rv   r=   ro   r   r   r   r   )rw   r   r   opposite	directionrH   curs          rK   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 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5        e f = f)Nc                    > T R                   R                     T R                  T5      sS S S 5        $ ! , (       d  f       g = fr{   )rq   rd   _claim_writer_markerrw   r   s   rK   try_claim_writer@SoftReadWriteLock._acquire_writer_slot.<locals>.try_claim_writer  s*    ""007 #""s	   3
Ac                 D  > T R                   R                     T R                  T5      (       d   T R                  T5      (       d
   S S S 5        gT R	                  [
        R
                  " 5       5        T R                  5       (       + sS S S 5        $ ! , (       d  f       g = fNF)rq   rd   _touch_writer_marker_if_oursr   _break_stale_readersr   _any_readersr   s   rK   readers_drained_touchingHSoftReadWriteLock._acquire_writer_slot.<locals>.readers_drained_touching  sp    "" 88??HaHabgHhHh 	 #"
 ))$))+6,,.. #""s   .B8B
Br   FrT   rR   )_open_readers_dir	_wait_forr   r   rm   r   )rw   r   r   r3   r   r   s   ``    rK   r   &SoftReadWriteLock._acquire_writer_slot  s     	 	8 	8	/ 	/ 	'XN	NN3QYNZ {{  %''  	 ..u5		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r6   nowFT)_break_stale_markerrm   r   r6   r   _file_exists_atomic_create_markerFileExistsErrorr   s     rK   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_markerrm   r   r>   r   r   r   r   _parse_marker_bytesr   r   r   r   r   )rw   r   r   datar   s        rK   r   .SoftReadWriteLock._touch_writer_marker_if_ours6  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                 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)	rq   rd   r   rm   r   r6   r   r   r   )r   full_reader_pathreader_namerw   r   s   rK   try_claim_reader@SoftReadWriteLock._acquire_reader_slot.<locals>.try_claim_readerW  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hexr>   r?   rr   strr   rm   re   r   )rw   r   r   r3   r  r   r  r  s   ``   @@@rK   r   &SoftReadWriteLock._acquire_reader_slotK  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   rE   r7   minmaxsleep)rw   	predicater   r3   r   	sleep_fors         rK   r   SoftReadWriteLock._wait_fore  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                  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   rm   re   r   r   mkdirr>   lstatstatS_ISLNKst_modeS_ISDIRr=   rr   r%   r   openO_RDONLYgetattrr!   r   r   r   r   rs   )rw   readers_pathstrH   r   r   registration_errorclose_errors           rK   r   #SoftReadWriteLock._open_readers_diry  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)rw   entriesr   s      rK   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)	rr   r>   scandir_is_housekeeping_namer   r   rm   re   r	  )rw   itentryr  s       rK   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)r6   r   r   )r   r#  appendrr   r   r   r6   )rw   r   namesr$  r   dirfd_relativer   s          rK   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   )rq   rh   rt   r   r   r   rr   _open_marker_fdFileNotFoundErrorr   _read_marker_fdr>   r   r   r   r   r   r   )rw   r   r   r   r   r   r   r   s           rK   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 )Nrg   )rn   ro   rp   rq   rd   rt   rr   rs   rw   s    rK   _reset_after_fork_in_child,SoftReadWriteLock._reset_after_fork_in_child  sH    ^^%!(++##

 
#%)"r^   )ru   rj   rt   rq   rm   rr   rs   r3   r5   rE   r7   r6   rB   rN   )rE   rP   rB   rQ   r3   rR   r4   rR   r5   rQ   r6   rS   r7   rQ   rT   NonerT   r:  r{   )rB   rS   r3   bool | NonerT   zGenerator[None])rB   rS   r3   r<  rT   r   )rE   rP   rB   rQ   r3   rR   rT   rU   )r   rR   rT   r:  )r   r	  rT   r:  )r   _ModerB   rS   r3   r<  rT   r   )
r   r=  r   rQ   r   rQ   r3   rR   rT   r   )r   r=  rT   r   )r   r	  r   rS   r3   rR   rT   ztuple[str, bool])r   r	  rT   rR   )r  Callable[[], bool]r   rS   r3   rR   rT   r:  r   )rT   zGenerator[tuple[str, bool]])r   rQ   rT   r:  )&rV   rW   rX   rY   __doc__r   r.   rZ   ro   r|   r/   rx   classmethodr~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r#  r   r   r8  r[   rM   r^   rK   rU   rU   s   s   +Z @S?TJ<Too'O
 1$
 !$((,#1$)1$ 1$
 1$ 1$ "1$ &1$ 1$ 
1$f / / QU  & RV  &ATX A A.BUY B B6  :
 :): :
 : 
: :*%. (- %;N' . .  .
  . 
 .D3-3- !3- 	3- 3- 
3-j-( ( ( 	 (
  ( 
 (D*OO 	O
 O 
O4"%" 	"
 " 
"(38@,	`'R*r^   rU   )	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)r9   rx   _refresh	_interval_stop_event)rw   r   r   r   r   rJ   s        rK   rx   _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{   )rG  waitrF  rE  r   r7  s    rK   run_HeartbeatThread.run  sZ    ""''77==??  $$& ""''77r^   )rF  rE  rG  )
r   r>  r   rQ   r   threading.Eventr   r	  rT   r:  r;  )rV   rW   rX   rY   rx   rK  r[   r\   r]   s   @rK   r   r     sB    
&#
& 
& $	
&
 
& 

& r^   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        rK   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    rK   r4  r4    s    772'!+,,r^   c                   [         R                  [        -  [        -  n[        (       a  Ub  [         R
                  " XUS9$ [         R
                  " X5      $ Nr   )r>   r  r!   r#   r%   r  )r   r   flagss      rK   r2  r2    sD     KK+%3E2B2BvGY2774v.s_a_f_fgk_ssr^   c               6     [        XS9$ ! [         a     g f = frT  )r2  r   r   r   s     rK   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   rZ  r\  )	lenr   decodeUnicodeDecodeErrorrematchVERBOSEint_MarkerInfo)r   textra  rZ  s       rK   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rT  )r   r3  r%   r>   unlinkr   rW  s     rK   r   r   I  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>   r?   r   r   r%   renamer   r   r   r   r   )r   r6   r   r   read_resultinfo_beforemtime_before
break_name
read_after
info_aftermtime_afters              rK   r   r   R  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          	        [         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[        R                  " 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   
rY  )r>   O_CREATO_EXCLO_WRONLYr!   r%   r  rO  st_devst_inor   r?   socketgethostnameencoder   r   
_same_filer   )r   r   r   rU  r   identityr  s          rK   r   r   ~  s     JJ"R[[0;>EF.WWT%7WWT%( (,H
XXb\99bii'"r"))+b1C1C1E0FbIPPQXYZ 	  
Jtf$MD(	s   9A7D =E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   rx  ry  )r   r~  r   r  s       rK   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  r3  r  rP  r  )pathr  s     rK   r   r     s=    XXd^ <<

##  s   8 
AAc                D    U R                  S5      =(       d	    [        U ;   $ )Nr   )
startswithr   )r   s    rK   r(  r(    s    ??38=D#88r^   T)frozenc                  4    \ rS rSr% S\S'   S\S'   S\S'   Srg)rl   i  r	  rd   r   re   rM   NrV   rW   rX   rY   rZ   r[   rM   r^   rK   rl   rl     s    JJLr^   rl   c                  4    \ rS rSr% S\S'   S\S'   S\S'   Srg)	rn   i  r'   rh   ri   r   rd   rM   Nr  rM   r^   rK   rn   rn     s    r^   rn   c                  4    \ rS rSr% S\S'   S\S'   S\S'   Srg)	rd  i  r	  r   rc  rZ  r\  rM   Nr  rM   r^   rK   rd  rd    s    J	HMr^   rd  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.rc  r   r=  r   
int | Noner   r	  r   rR   r   r   r   r   rM  r   rM   N)rV   rW   rX   rY   r?  rZ   r[   rM   r^   rK   r   r     s1    cJ
KOJ&&##r^   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   )rG   s    rK   _cleanup_all_instancesr    sB    ..01i 4( !  2  s   A
A	)r   r	  r   r  rT   z'tuple[_MarkerInfo | None, float] | None)r   rc  rT   bytes)r   r	  r   r  rT   rc  )r   r	  r   r  rT   r  )r   r  rT   z_MarkerInfo | None)r   r	  r   r  rT   r:  )
r   r	  r6   rQ   r   rQ   r   r  rT   rR   )r   r	  r   r	  r   r  rT   r:  )r   r	  r~  ztuple[int, int]r   r  rT   rR   )r  r	  rT   rR   )r   r	  rT   rR   r;  )Wr?  
__future__r   atexitr   r>   r`  r   rz  r  sysro   r   r  
contextlibr   r   r   dataclassesr   pathlibr   typingr	   r
   r   weakrefr   filelock._apir   r   r   r   r   r   r   r   filelock._errorr   filelock._softr   filelock._utilr   r   r   collections.abcr   r   r=  r   rZ   r   r  r!   r#   platformr  supports_dir_fdr%   r&   rp   r(   r   r)   typer+   rU   Threadr   r   r4  r2  r   r   r   r   r   r}  r   r(  rl   rn   rd  r   r  register__all__rM   r^   rK   <module>r     sR   ` "   	 	    
    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:$ :zz	*+ z	*zy'' ( 59 2(- 8< t 59 R< 04   )
) ) 
	)
 ) 
)X JN 0.$9 $      $   
$ 
$ 
$) & ' & ' r^   