
    Loj                        % S SK Jr  S SKrS SKrS SKrS SKJrJr  S SKJ	r	  S SK
Jr  S2S jrS3S jr\R                  S:X  Gan  S SKrS S	KJr  \R"                  " S
SS9rS\S'   \R(                  /\R*                  l        \R.                  \R*                  l        \R2                  \R.                  \R2                  /\R4                  l        \R(                  \R4                  l        \R(                  \R6                  " \R8                  5      \R6                  " \R8                  5      \R6                  " \R8                  5      \R6                  " \R8                  5      /\R:                  l        \R.                  \R:                  l        SrS\S'   SrS\S'   Sr S\S'   Sr!S\S'   S4S jr"S5S jr#OS4S jr"\R                  S;   a  Sr$S\S'   S6S jr%\%" 5       r&S\S '   S5S! jr#Ol\R                  S":X  aW  S SKrS SK'r'\RP                  " SSS#9r)S$\S%'   S&r*S\S''   S(r+S\S)'   S&r,S\S*'   S+r-S,\S-'   \'R\                  " \-5      r/S\S.'   S5S/ jr#OS5S0 jr#/ S1Qr0g)7    )annotationsN)EPERMESRCH)Path)Finalc                 ,    [         R                  " 5       $ )zfThe hostname recorded alongside an owner, so a marker written on another machine is never probed here.)socketgethostname     L/mnt/workspace/venv-train/lib/python3.13/site-packages/filelock/_identity.py	host_namer      s    r   c                ~    U[        5       :w  a  g[        U 5      (       d  gUc  g[        U 5      nUSL=(       a    X2:g  $ )af  
Whether the recorded owner is provably gone, so reclaiming its marker cannot detach a live holder.

Fail closed: return ``True`` only when this process can prove the exact recorded owner is dead. A marker from
another host cannot be probed; a live PID whose start token still matches, or whose token cannot be read, is the
holder or is indistinguishable from it; a live PID whose start token differs is a recycled PID, so the process that
wrote the marker is gone. PostgreSQL, Qt ``QLockFile`` and Mercurial all break a stale lock only on proof of death
and treat an unreadable or foreign owner as still holding.
FTN)r   process_aliveprocess_start_token)pidhostnamestart_tokencurrents       r   owner_is_staler      sE     9;!#&G$97#99r   win32)wintypeskernel32T)use_last_errorzFinal[ctypes.WinDLL]	_KERNEL32i   z
Final[int]_WIN_SYNCHRONIZEi   &_WIN_PROCESS_QUERY_LIMITED_INFORMATIONW   _WIN_ERROR_INVALID_PARAMETERFzFinal[bool]_WIN_INHERIT_HANDLEc                    [         R                  [        [        U 5      nU(       a  [         R	                  U5        g[
        R                  " 5       [        :g  $ )zSWhether a process with this PID exists, treating an access denial as proof it does.T)r   OpenProcessr   r    CloseHandlectypesget_last_errorr   )r   handles     r   r   r   ;   sA    &&'79LcR!!&)$$&*FFFr   c           	        [         R                  [        [        U 5      nU(       d  gS [	        S5       5       u  p#pE [         R                  U[        R                  " U5      [        R                  " U5      [        R                  " U5      [        R                  " U5      5      (       d   [         R                  U5        g [         R                  U5        UR                  S-  UR                  -  $ ! [         R                  U5        f = f)zXThe process creation FILETIME as a 100ns tick count, or ``None`` when it cannot be read.Nc              3  L   #    U  H  n[         R                  " 5       v   M     g 7f)N)r   FILETIME).0_s     r   	<genexpr>&process_start_token.<locals>.<genexpr>H   s     6]T\qx7H7H7J7JT\s   "$       )r   r"   r   r    rangeGetProcessTimesr$   byrefr#   dwHighDateTimedwLowDateTime)r   r&   creation	exit_timekernel_time	user_times         r   r   r   C   s    &&'MObdgh6]TYZ[T\6]3[
	*,,X&Y'[)Y'  !!&) !!&)''2-1G1GGG !!&)s   A.C5 5Dc                     [         R                  " U S5        g! [         a8  nUR                  [        :X  a   SnAgUR                  [
        :X  a   SnAge SnAff = f)z_Whether a process with this PID exists, treating an access denial (``EPERM``) as proof it does.r   NFT)oskillOSErrorerrnor   r   )r   errors     r   r   r   X   sL    	GGCO   	{{e#{{e#	s    
AAAAA>   linuxandroid   _STARTTIME_INDEXc                      [        S5      R                  SS9n [        U R                  5       R	                  SS5      S5      $ ! [
        [        4 a     gf = f)Nz/proc/sys/kernel/random/boot_idascii)encoding-    r   )r   	read_textintstripreplacer<   
ValueError)boot_ids    r   _read_boot_idrO   k   sX    @AKKU\K]7==?223;R@@Z( s   AA AA_BOOT_IDc                ,    [        SU  S35      R                  5       nXR                  S5      S-   S R	                  5       n[        U5      [        ::  a  g [        U[           5      n[        S-  U-  $ ! [         a     gf = f! [         a     gf = f)zeThe ``/proc/<pid>/stat`` ``starttime`` folded with the boot id, or ``None`` when the process is gone.z/proc/z/statN   )   @   )
r   
read_bytesr<   rfindsplitlenrB   rJ   rM   rP   )r   datafields	starttimes       r   r   r   y   s    fSE/0;;= **T*Q.01779F6{..'7 89	 Ni//    s#   A6 B 6
BB
BBdarwin)	use_errnozFinal[ctypes.CDLL]_LIBCrS   	_CTL_KERN   
_KERN_PROC_KERN_PROC_PIDz<qiz
Final[str]_TIMEVAL_AT_ZERO_TIMEVAL_SIZEc                   [         R                  S-  " [        [        [        U 5      n[         R
                  " S5      n[        R                  USS[         R                  " U5      SS5      S:w  a  g[         R                  UR                  -  " 5       n[        R                  USU[         R                  " U5      SS5      S:w  d  UR                  [        :  a  g[        R                  " [        UR                  S5      u  pEUS-  U-   $ )zcThe process start time in microseconds from ``sysctl(KERN_PROC_PID)``, or ``None`` when it is gone.r.   r   Ni@B )r$   c_intr_   ra   rb   c_size_tr^   sysctlr2   c_charvaluerd   structunpack_fromrc   raw)r   miblengthbuffersecondsmicrosecondss         r   r   r      s    <<!#Y
NCPC__Q'F ||CD&,,v*>aHAMmmfll25F||CFFLL,@$JaOSYS_S_boSo$*$6$67GUV$W!GY&55r   c                    A g)z_No proven start-time source, so the owner carries no token and liveness rests on the PID alone.Nr   )r   s    r   r   r      s    r   )r   r   r   r   )returnstr)r   rJ   r   ru   r   
int | Nonert   bool)r   rJ   rt   rw   )r   rJ   rt   rv   )rt   rJ   )1
__future__r   r:   r	   sysr=   r   r   pathlibr   typingr   r   r   platformr$   r   WinDLLr   __annotations__HANDLEr#   argtypesBOOLrestypeDWORDr"   POINTERr)   r1   r   r   r   r    r   r   rB   rO   rP   rk   CDLLr^   r_   ra   rb   rc   calcsizerd   __all__r   r   r   <module>r      s   " 	  
    
:( <<7&,mmJt&TI#T&.oo%6I"$,MMI!&.nnhmmX^^%TI"$,OOI!x(()x(()x(()x(()*I& )1I%#+j+9?*J?/1 *1',,GH*
 ||++
 (**)
	  -*.	0  
	!$*KK$E!E !	:!!#
J#%&
& (-*,$*OO4D$EzE	6 	r   