
    Loj2                    $   % S SK Jr  S SKrS SKrS SKrS SK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  SSKJr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  SrS\S'   Sr S\S'   Sr!S\S'   Sr"S\S'    " S S\5      r#SS jr$SS jr%SS jr&S/r'g)    )annotationsN)suppress)EACCESEEXISTEPERM)Path)Final   )BaseFileLock_raise_grouped_errors)	host_nameowner_is_staleprocess_start_token)STRICT_SOFT_SENTINEL_RECORD)break_lock_fileensure_directory_existsraise_on_not_writable_file	write_allg       @zFinal[float]_MALFORMED_LOCK_AGE_THRESHOLDi   z
Final[int]_MAX_LOCK_FILE_SIZE
   _UNLINK_MAX_RETRIES   #_MARKER_WITH_START_TOKEN_LINE_COUNTc                      \ rS rSr% SrSrS\S'   SrS\S'   S	rS\S
'   S	r	S\S'   SS jr
SS jrSS jr\SS j5       r\SS j5       r\SS j5       rSS jrSS jrSS jrSS jrSrg)SoftFileLock   aR  
Cooperative file lock based on a shared existence marker.

Unlike :class:`UnixFileLock <filelock.UnixFileLock>` and :class:`WindowsFileLock <filelock.WindowsFileLock>`, this
lock does not use OS-level locking primitives. Instead, it creates the lock file with ``O_CREAT | O_EXCL`` and
treats its existence as the lock indicator. The filesystem must provide coherent exclusive creation and directory
updates to each participating process. A crash can leave the marker behind.

The marker contains the holder's PID and hostname. A contender may remove it when it can no longer find a same-host
process with that PID. A configured :attr:`~filelock.BaseFileLock.lifetime` also permits removal based on marker
age, including while the holder remains alive. Age-based expiry can overlap protected operations and does not
provide strict mutual exclusion.

Tbool_lifetime_supported)StrictSoftFileLockSoftFileLeaseztuple[str, str] | None_lifetime_replacementsF_preserve_lock_file_supported_on_acquired_supportedc                z   [        U R                  5        [        U R                  5        [        R                  [        R
                  -  [        R                  -  [        R                  -  n[        [        SS 5      =nb  X-  n [        R                  " U R                  XR                  5       5      nU R%                  U5        U R'                  U5        g ! [         aW  nUR                  [        :X  d)  UR                  [        :X  a  [        R                   S:X  d  e U R#                  5          S nAg S nAff = f)N
O_NOFOLLOWwin32)r   	lock_filer   osO_WRONLYO_CREATO_EXCLO_TRUNCgetattropen
_open_modeOSErrorerrnor   r   sysplatform_try_break_stale_lock_mark_descriptor_pending_publish_held_marker)selfflags
o_nofollowfd	exceptions        H/mnt/workspace/venv-train/lib/python3.13/site-packages/filelock/_soft.py_acquireSoftFileLock._acquire3   s    "4>>2/ bjj(2994rzzA!"lD99JFE	0ABB 	%%b)!!"%  	6)ioo.GCLL\cLc&&(	s   /C 
D:#AD55D:c                   S n [        [        R                  " U5      5      nU R                  U5        U R                  X5        g ! [         a    U R                  5         [        R                  " U5        [        [        5         UbP  [        [        R                  " U R                  5      5      U:X  a#  [        U R                  5      R                  5         S S S 5        e ! , (       d  f       e = ff = fN)_file_identityr)   fstat_write_lock_infoBaseException_mark_descriptor_releasedcloser   r1   lstatr(   r   unlink_mark_descriptor_owned)r8   r;   identitys      r=   r7   !SoftFileLock._publish_held_markerG   s     ,0		%bhhrl3H!!"% 	##B1  	**,HHRL'"'N288DNN;S,TX`,`(//1 #  #" 	s$   0A ?C4AC"	C4"
C0	,C4c                   [        [        [        5         [        U R                  5      u  pnU[
        :X  a
   S S S 5        g [        U5      nUc@  [        R                  " 5       U-
  [        :  a  [        U R                  X#5         S S S 5        g [        U6 (       a  [        U R                  X#5        S S S 5        g ! , (       d  f       g = frA   )r   r1   
ValueError_read_lock_filer(   r   _parse_lock_holdertimer   r   r   )r8   contentmtimeinoholders        r=   r5   "SoftFileLock._try_break_stale_lockX   s    gz*"1$.."AGC55 +* (0F~ 99;&*GG#DNNE? +* v&; +**s   $B<AB<#B<<
C
c                    [         R                  " 5        S[        5        S3n[        [         R                  " 5       5      =nb  X S3-  n[	        XR                  5       5        g )N
)r)   getpidr   r   r   encode)r;   infotokens      r=   rD   SoftFileLock._write_lock_infoj   sP    
 ))+bR0(55EBgRL D"kkm$    c                    [        [        [        5         [        [	        U R
                  5      S   5      nUb  US   sSSS5        $  SSS5        g! , (       d  f       g= f)z
The PID of the process holding this lock, read from the lock file.

:returns: the PID as an integer, or ``None`` if the lock file does not exist or cannot be parsed

r   N)r   r1   rN   rP   rO   r(   )r8   rU   s     r=   pidSoftFileLock.pidt   sV     gz*'(G(JKF!ay +*! + 	 +* s   )A
A c                   [        [        [        5         [        [	        U R
                  5      S   5      nUb:  Uu  p#nU[        R                  " 5       :H  =(       a    U[        5       :H  sSSS5        $  SSS5        g! , (       d  f       g= f)z
Whether this lock is held by the current process.

:returns: ``True`` if the lock file exists and names the current process's PID and hostname

r   NF)	r   r1   rN   rP   rO   r(   r)   rY   r   )r8   rU   r`   hostname_s        r=   is_lock_held_by_usSoftFileLock.is_lock_held_by_us   ss     gz*'(G(JKF!#) qbiik)Eh)+.E	 +*! +
  +*
 s   AA>>
Bc                    [        [        5         [        U R                  5      R	                  5         SSS5        g! , (       d  f       g= f)zNForcibly break the lock by removing the lock file, regardless of who holds it.N)r   r1   r   r(   rI   )r8   s    r=   
break_lockSoftFileLock.break_lock   s+    g '') s	   $=
Ac                   U R                   R                  nUc   eS n[        [        5         [	        [
        R                  " U5      5      nS S S 5        U R                  5          U R                  USS9  U R                  U5        g ! , (       d  f       NA= f! [         a<  n U 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)NF)default_suppressesz4lock descriptor close and marker cleanup both failed)_contextlock_file_fdr   r1   rB   r)   rC   rF   _close_released_fdrE   _unlink_held_markerr   )r8   r;   rK   close_errorcleanup_errors        r=   _releaseSoftFileLock._release   s    ]]''~~ ,0g%bhhrl3H  	&&(	##B5#A 	  *%   		((2  ! %J! 
 		sG    B&B 
B
C$B65C6
C CCCCCc                J   Uc  g [         R                  S:X  a  U R                  U5        g [        [        5         [        [        R                  " U R                  5      5      U:X  a#  [        U R                  5      R                  5         S S S 5        g ! , (       d  f       g = f)Nr'   )r3   r4   _windows_unlink_if_oursr   r1   rB   r)   rH   r(   r   rI   )r8   rK   s     r=   ro    SoftFileLock._unlink_held_marker   sh    <<7"((2'"!"((4>>":;xG(//1 #""s   AB
B"c                   Sn[        [        5       HV  n [        [        R                  " U R
                  5      5      U:w  a    g [        U R
                  5      R                  5           g    g ! [         aY  nUR                  [        [        1;  a   S nA  g U[        S-
  :  a!  [        R                  " U5        US-  n S nAM   S nAM  S nAff = f)NgMbP?r
      )ranger   rB   r)   rH   r(   r   rI   r1   r2   r   r   rQ   sleep)r8   rK   retry_delayattemptexcs        r=   ru   $SoftFileLock._windows_unlink_if_ours   s    01G!"((4>>":;xGT^^$++-  2  %99VUO30144JJ{+1$K 5%s#   -A-#A--
C7C(CC N)returnNone)r;   intr   r   )r   z
int | None)r   r   )rK   ztuple[int, int] | Noner   r   )rK   tuple[int, int]r   r   )__name__
__module____qualname____firstlineno____doc__r   __annotations__r"   r#   r$   r>   r7   r5   staticmethodrD   propertyr`   re   rh   rr   ro   ru   __static_attributes__r   r^   r=   r   r      s      !%$ 6]2\ +0!4/ $)D(&(2"<$ % %    *
+62r^   r   c                2    U R                   U R                  4$ rA   )st_devst_ino)sts    r=   rB   rB      s     99biir^   c           	        [         R                  " U 5      n[        R                  " UR                  5      (       d  S UR
                  UR                  4$ [         R                  " U [         R                  [        [         SS5      -  [        [         SS5      -  5      n [         R                  " U5      n[        R                  " UR                  5      (       d/  S UR
                  UR                  4[         R                  " U5        $ [         R                  " U[        S-   5      n[         R                  " U5        [        U5      [        ::  aA  [        [         5         UR#                  S5      UR
                  UR                  4sS S S 5        $ S UR
                  UR                  4$ ! [         R                  " U5        f = f! , (       d  f       NB= f)Nr&   r   
O_NONBLOCKr
   zutf-8)r)   rH   statS_ISREGst_modest_mtimer   r/   O_RDONLYr.   rC   rG   readr   lenr   UnicodeDecodeErrordecode)pathr   r;   datas       r=   rO   rO      s8   
 
$B<<

##R[["))++ 
r{{WRq%AAGBP\^_D``	aBXXb\||BJJ''bii/ 	 wwr.23

4y''();;w'bii? *)bii''	 	))s   AF* 	F* (G*G
Gc                    U (       a-  [        U R                  5       R                  5       =n5      S;  a  g  [        US   5      n[        U5      [        :X  a  [        US   5      OS nSUs=::  a  S::  d   g   g X!S   U4$ ! [
         a     g f = f)N>   rx   r   r   rx   r
   i)r   strip
splitlinesr   r   rN   )rR   linesr`   start_tokens       r=   rP   rP      s    
 c7==?#=#=#??%@N%(m'*5z5X'Xc%(m^b  y  !a+%%  s   1B   
BB)r   zos.stat_resultr   r   )r   strr   ztuple[str | None, float, int])rR   z
str | Noner   z"tuple[int, str, int | None] | None)(
__future__r   r)   r   r3   rQ   
contextlibr   r2   r   r   r   pathlibr   typingr	   _apir   r   	_identityr   r   r   _soft_protocolr   _utilr   r   r   r   r   r   r   r   r   r   rB   rO   rP   __all__r   r^   r=   <module>r      s    " 	  
   ' '   5 E E 7 b b.1 | 1"& Z &"$ Z $23 #Z 3t< tn (2&, r^   