
    ybj8&                       % 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  SrS\S'   \" \" S	S
5      5      \" S5      1-
  rS\S'   S9S jrS:S jr\R(                  S:X  Gan  S SKrS SKJr  \R.                  " SSS9rS\S'   \R2                  /\R4                  l        \R8                  \R4                  l        \R<                  \R8                  \R<                  /\R>                  l        \R2                  \R>                  l        \R2                  \R@                  " \RB                  5      \R@                  " \RB                  5      \R@                  " \RB                  5      \R@                  " \RB                  5      /\RD                  l        \R8                  \RD                  l        Sr#S\S'   Sr$S\S'   Sr%S\S'   Sr&S\S'   S;S  jr'S<S! jr(OS;S" jr'\R(                  S#;   a  S$r)S\S%'   S=S& jr*\*" 5       r+S\S''   S<S( jr(Ol\R(                  S):X  aW  S SKrS SK,r,\RZ                  " SSS*9r.S+\S,'   S-r/S\S.'   S/r0S\S0'   S-r1S\S1'   S2r2S3\S4'   \,Rf                  " \25      r4S\S5'   S<S6 jr(OS<S7 jr(/ S8Qr5g)>    )annotationsN)EPERMESRCH)Path)Final   z
Final[int]_HOST_NAME_LIMIT!      ?zFinal[frozenset[int]]_HOST_NAME_VERBATIMc                     Sn [         R                  " 5       R                  SS5       HC  nU[        ;   a  [	        U5      OSUS 3n[        U 5      [        U5      -   [        :  a    OX-  n ME     U =(       d    S$ )a  
The hostname recorded alongside an owner, so a marker written on another machine is never probed here.

Marker formats here hold the field to printable non-space ASCII, while ``socket.gethostname()`` reports whatever
the kernel stores: a space, a newline that forges an extra marker line, or a byte no codec encodes, which Python
hands back as a surrogate. A holder that publishes one raw writes a marker it cannot read back, and loses the lock
to the first peer that ages it out as malformed. ``?`` is illegal in a hostname, so escaping it along with every
out-of-grammar byte as ``?<hex>`` leaves a real name untouched and still keeps two hosts apart, which
:func:`owner_is_stale` relies on to refuse to probe a foreign PID.
 zutf-8surrogateescaper   02x)socketgethostnameencoder   chrlenr	   )namebytepieces      ڎ/tmp/claude-0/-home-danvics-docker-quiz/c1e0577a-e42c-4a3d-b1ea-3edd61103a4e/scratchpad/stt/lib/python3.13/site-packages/filelock/_identity.py	host_namer      sr     D""$++G5FG!%88D	$snt9s5z!$44	 H ;3    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   _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   P   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>]   s     6]T\qx7H7H7J7JT\s   "$       )r)   r0   r+   r.   rangeGetProcessTimesr2   byrefr1   dwHighDateTimedwLowDateTime)r    r4   creation	exit_timekernel_time	user_times         r   r   r   X   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   m   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   )r   	read_textintstripreplacerJ   
ValueError)boot_ids    r   _read_boot_idr\      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_bytesrJ   rfindsplitr   rP   rW   rZ   r]   )r    datafields	starttimes       r   r   r      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]_LIBCr`   	_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 )r2   c_intrk   rm   rn   c_size_trj   sysctlr@   c_charvaluerp   structunpack_fromro   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.N )r    s    r   r   r      s    r   )r   r$   r   r   )returnstr)r    rW   r!   r   r"   
int | Noner   bool)r    rW   r   r   )r    rW   r   r   )r   rW   )6
__future__r   rH   r   sysrK   r   r   pathlibr   typingr   r	   __annotations__	frozensetr>   ordr   r   r$   platformr2   r&   WinDLLr)   HANDLEr1   argtypesBOOLrestypeDWORDr0   POINTERr7   r?   r*   r+   r-   r.   r   r   rP   r\   r]   rw   CDLLrj   rk   rm   rn   ro   calcsizerp   __all__r   r   r   <module>r      s7   " 	  
     # * "-6uT47H-ISQTXJ-V * V*:( <<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   