+
    2jY(                        ^ RI Ht ^ RIt^ RIt^ RIt^ RIt^ RIHt ^ RIH	t	H
t
HtHt ^ RIHt ^RIHt ^RIHtHtHt Rt^WtR	tR
tRt ! R R]4      tR R ltR R ltR.tR# )    )annotationsN)suppress)EACCESEEXISTEPERMESRCH)Path)BaseFileLock)break_lock_fileensure_directory_existsraise_on_not_writable_filei   i   g       @i   c                      ] tR t^tRtR R ltR R lt]R R l4       t]R R	 l4       t	]R
 R l4       t
]R R l4       t]R R l4       tR R ltR R ltR R ltRtR# )SoftFileLocka  
Portable file lock based on file existence.

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. This makes it work on any filesystem but leaves stale lock files behind
if the process crashes without releasing the lock.

To mitigate stale locks, the lock file contains the PID and hostname of the holding process. On contention, if the
holder is on the same host and its PID no longer exists, the stale lock is broken automatically.

c                   V ^8  d   QhRR/#    returnNone )formats   ".lib/python3.14/site-packages/filelock/_soft.py__annotate__SoftFileLock.__annotate__#   s     6 6$ 6    c                	   \        V P                  4       \        V P                  4       \        P                  \        P
                  ,          \        P                  ,          \        P                  ,          p\        \        R R4      ;pe	   W,          p \        P                  ! V P                  WP                  4       4      pV P                  V4       W0P                  n        R#   \         d\   pTP                  \         8X  g,   TP                  \"        8X  d   \$        P&                  R8X  g   h T P)                  4         Rp?R# Rp?ii ; i)
O_NOFOLLOWNwin32)r   	lock_filer   osO_WRONLYO_CREATO_EXCLO_TRUNCgetattropen
_open_mode_write_lock_info_contextlock_file_fdOSErrorerrnor   r   sysplatform_try_break_stale_lock)selfflags
o_nofollowfile_handler	exceptions   &    r   _acquireSoftFileLock._acquire#   s    "4>>2/KKjjii jj 	 ""lD99JFE
	6774>>5//:KLL !!,/)5MM&  	)6)ioo.GCLL\cLc&&((	)s   /C* *E5AEEc                   V ^8  d   QhRR/# r   r   )r   s   "r   r   r   :   s     8 8t 8r   c                	   \        \        \        4      ;_uu_ 4        \        V P                  4      w  rp\        V4      pVfG   \        P                  ! 4       V,
          \        8  d   \        V P                  W#4        R R R 4       R # Vw  rVpV\        P                  ! 4       8w  d    R R R 4       R # V P                  V4      '       dK   \        P                  R8w  g   Vf    R R R 4       R # V P                  V4      pVe   W8X  d    R R R 4       R # \        V P                  W#4       R R R 4       R #   + '       g   i     R # ; iNr   )r   r*   
ValueError_read_lock_filer   _parse_lock_holdertime_MALFORMED_LOCK_AGE_THRESHOLDr   socketgethostname_is_process_aliver,   r-   _get_process_creation_time)	r/   contentmtimeinoholderpidhostnamecreation_timeactuals	   &        r   r.   "SoftFileLock._try_break_stale_lock:   s    gz**"1$.."AGC'0F~ 99;&*GG#DNNE? +* ,2(C=6--// +*  %%c**<<7*m.C% +*& 88=>V%<+ +*0 DNNE71 +***s*   A$D6 D65D6D60D6D66E	c                    V ^8  d   QhRRRR/# )r   rF   intr   boolr   )r   s   "r   r   r   V   s      s t r   c                	   \         P                  R 8X  dd   ^ RIpVP                  P                  pVP                  \        ^ V 4      pV'       d   VP                  V4       R# VP                  4       \        8g  #  \        P                  ! V ^ 4       R#   \         d=   pTP                  \        8X  d    Rp?R# TP                  \        8X  d    Rp?R# h Rp?ii ; i)r   NTF)r,   r-   ctypeswindllkernel32OpenProcess_WIN_SYNCHRONIZECloseHandleGetLastError_WIN_ERROR_INVALID_PARAMETERr   killr*   r+   r   r   )rF   rO   rQ   handleexcs   &    r   r@   SoftFileLock._is_process_aliveU   s    <<7"}}--H))*:AsCF$$V,((*.JJJ	GGCO   	yyE!yyE!	s$   :B CC9CCCc                    V ^8  d   QhRRRR/# )r   rF   rL   r   
int | Noner   )r   s   "r   r   r   k   s     H H H
 Hr   c           	        \         P                  R8w  d   R# ^ RIp^ RIHp VP                  P
                  pVP                  \        ^ V 4      pV'       g   R#  VP                  4       pVP                  4       pVP                  4       pVP                  4       pVP                  VVP                  V4      VP                  V4      VP                  V4      VP                  V4      4      '       g    VP                  V4       R#  VP                  V4       VP                  ^ ,          VP                  ,          #   TP                  T4       i ; i)zRReturn the process creation FILETIME as an integer on Windows, ``None`` otherwise.r   N)wintypes)r,   r-   rO   r^   rP   rQ   rR   &_WIN_PROCESS_QUERY_LIMITED_INFORMATIONFILETIMEGetProcessTimesbyrefrT   dwHighDateTimedwLowDateTime)	rF   rO   r^   rQ   rX   creation	exit_timekernel_time	user_times	   &        r   rA   'SoftFileLock._get_process_creation_timej   s    <<7"#==))%%&LaQTU	)((*H ))+I"++-K ))+I++X&Y'[)Y'    (   (''2-1G1GGG   (s   BD; ;Ec                    V ^8  d   QhRRRR/# )r   fdrL   r   r   r   )r   s   "r   r   r      s     ( (S (T (r   c                	   \        \        4      ;_uu_ 4        \        P                  ! 4        R \        P
                  ! 4        R 2p\        P                  R8X  d8   \        P                  \        P                  ! 4       4      ;pe   W R 2,          p\        P                  ! WP                  4       4       RRR4       R#   + '       g   i     R# ; i)
r   N)r   r*   r   getpidr>   r?   r,   r-   r   rA   writeencode)rk   infocts   &  r   r'   SoftFileLock._write_lock_info   s    giik]"V%7%7%9$:"=D||w&,2Y2YZ\ZcZcZe2f,fB+s$b	!HHR'	 s   BCC	c                   V ^8  d   QhRR/# )r   r   r\   r   )r   s   "r   r   r      s      Z r   c                    \        \        \        4      ;_uu_ 4        \        \	        V P
                  4      ^ ,          4      pVe   V^ ,          uuRRR4       #  RRR4       R#   + '       g   i     R# ; i)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

N)r   r*   r9   r;   r:   r   )r/   rE   s   & r   rF   SoftFileLock.pid   sY     gz**'(G(JKF!ay +*! + 	 +* s   2A%%A6	c                   V ^8  d   QhRR/# )r   r   rM   r   )r   s   "r   r   r      s      D r   c                Z   \        \        \        4      ;_uu_ 4        \        \	        V P
                  4      ^ ,          4      pVeH   Vw  r#pV\        P                  ! 4       8H  ;'       d    V\        P                  ! 4       8H  uuRRR4       #  RRR4       R#   + '       g   i     R# ; i)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

NF)
r   r*   r9   r;   r:   r   r   rn   r>   r?   )r/   rE   rF   rG   _s   &    r   is_lock_held_by_usSoftFileLock.is_lock_held_by_us   s     gz**'(G(JKF!#) qbiik)NNh&:L:L:N.N	 +*! +
  +*
 s   AB+BB*	c                   V ^8  d   QhRR/# r   r   )r   s   "r   r   r      s     * *D *r   c                    \        \        4      ;_uu_ 4        \        V P                  4      P	                  4        RRR4       R#   + '       g   i     R# ; i)zNForcibly break the lock by removing the lock file, regardless of who holds it.N)r   r*   r	   r   unlinkr/   s   &r   
break_lockSoftFileLock.break_lock   s1    g '') s   $AA	c                   V ^8  d   QhRR/# r   r   )r   s   "r   r   r      s     . .$ .r   c                	   V P                   P                  f   Q h\        P                  ! V P                   P                  4       R V P                   n        \        P
                  R8X  d   V P                  4        R # \        \        4      ;_uu_ 4        \        V P                  4      P                  4        R R R 4       R #   + '       g   i     R # ; ir8   )r(   r)   r   closer,   r-   _windows_unlink_with_retryr   r*   r	   r   r~   r   s   &r   _releaseSoftFileLock._release   s    }}))555
++,%)"<<7"++-'""T^^$++- #"""s   $CC	c                   V ^8  d   QhRR/# r   r   )r   s   "r   r   r      s      D r   c                	V   ^
pRp\        V4       F(  p \        V P                  4      P                  4         R# 	  R#   \         d`   pTP
                  \        \        09  d    Rp? R# Y1^,
          8  d&   \        P                  ! T4       T^,          p Rp?K   Rp?K  Rp?ii ; i)
   gMbP?N)
ranger	   r   r~   r*   r+   r   r   r<   sleep)r/   max_retriesretry_delayattemptrY   s   &    r   r   'SoftFileLock._windows_unlink_with_retry   s    [)G	T^^$++-  *  %99VUO31_,JJ{+1$K -%s   #>B(	B#+,B##B(r   N)__name__
__module____qualname____firstlineno____doc__r4   r.   staticmethodr@   rA   r'   propertyrF   rz   r   r   r   __static_attributes__r   r   r   r   r      s    6.86  ( H H8 ( (    *
. r   r   c                    V ^8  d   QhRRRR/# )r   pathstrr   ztuple[str | None, float, int]r   )r   s   "r   r   r      s     ( (# ("? (r   c           	        \         P                  ! V \         P                  \        \         R ^ 4      ,          \        \         R^ 4      ,          4      p \         P                  ! V4      \         P
                  ! V\        ^,           4      r2\         P                  ! V4       \        V4      \        8:  dK   \        \        4      ;_uu_ 4        VP                  R4      VP                  VP                  3uuRRR4       # RVP                  VP                  3#   \         P                  ! T4       i ; i  + '       g   i     LD; i)r   
O_NONBLOCKzutf-8N)r   r%   O_RDONLYr$   fstatread_MAX_LOCK_FILE_SIZEr   lenr   UnicodeDecodeErrordecodest_mtimest_ino)r   rk   stdatas   &   r   r:   r:      s     
r{{WRq%AAGBP\^_D``	aB88B<-@1-D!ED

4y''());;w'bii? *)bii''	 	))s   7D (D2D/2E	c                    V ^8  d   QhRRRR/# )r   rB   z
str | Noner   z"tuple[int, str, int | None] | Noner   )r   s   "r   r   r      s     ( (
 (/Q (r   c                D   V '       d/   \        V P                  4       P                  4       ;p4      R9  d   R#  \        V^ ,          4      p\        V4      ^8X  d   \        V^,          4      MRp^Tu;8:  d
   R8:  g    R#  R# Y!^,          T3#   \         d     R# i ; i)r   N>   r      i)r   strip
splitlinesrL   r9   )rB   linesrF   rH   s   &   r   r;   r;      s     c7==?#=#=#??%@N%(m),UqE!Hd  y  !a-''  s   6B BB)
__future__r   r   r>   r,   r<   
contextlibr   r+   r   r   r   r   pathlibr	   _apir
   _utilr   r   r   rS   rV   r_   r=   r   r   r:   r;   __all__r   r   r   <module>r      sl    " 	  
   . .   W W ! )/ & #  t< tn("(* r   