
    xj                        U d dl mZ d dlZd dlZd dlmZ d dlmZmZm	Z	 ddl
mZmZ ddlmZmZ ddlmZ d	Zd
ed<   dZded<   ed         Z G d de	          Z G d de          Zd dZd!dZd"dZg dZdS )#    )annotationsN)suppress)FinalLiteral
NamedTuple   )	host_nameprocess_start_token)SoftFileLock_read_lock_file)	write_allz
filelock/2z
Final[str]	_PROTOCOLiz
Final[int]_MAX_PID)leaseunknownc                  \    e Zd ZU dZded<   ded<   ded<   dZd	ed
<   dZded<   dZded<   dS )OwnerRecordz+The owner published in a protocol 2 marker.intpidstrhostname	OwnerModemodeN
str | Nonetokenzfloat | Nonelease_duration
int | Nonestart)__name__
__module____qualname____doc____annotations__r   r   r        V/home/agent/.hermes/hermes-agent/venv/lib/python3.11/site-packages/filelock/_marker.pyr   r      sf         55HHHMMMOOOE#'N''''Er%   r   c                      e Zd ZU dZded<   edd            Zedd            Zedd
            ZddZ	ddZ
ddZddZdS )MarkerSoftFileLockzAAn existence lock whose marker carries a protocol 2 owner record.r   _owner_modereturnOwnerRecord | Nonec                *    |                                  S )z
        The owner named by the marker on disk.

        :returns: the published record, or ``None`` when no marker exists or its record is malformed or protocol 1

        )_read_ownerselfs    r&   ownerzMarkerSoftFileLock.owner)   s     !!!r%   r   c                @    |                                  x}dn|j        S )z
        The PID of the process holding this lock, read from the marker.

        :returns: the PID, or ``None`` when no marker exists or its record is unreadable

        N)r-   r   r/   r0   s     r&   r   zMarkerSoftFileLock.pid3   s&     "&!1!1!3!33<tt%)Kr%   boolc                    |                                  }|duo2|j        t          j                    k    o|j        t                      k    S )z
        Whether the marker on disk names this process.

        :returns: ``True`` when the marker's PID and hostname match this process

        N)r-   r   osgetpidr   r	   r2   s     r&   is_lock_held_by_usz%MarkerSoftFileLock.is_lock_held_by_us=   sE       ""D _UY")++%=_%.T]T_T_B__r%   Nonec                .    |                                   dS )a-  
        Remove the marker whoever holds it, so a later contender can acquire.

        Forced breaking voids mutual exclusion: the previous holder keeps running and keeps using whatever the lock
        protects. Reserve it for an operator clearing a marker whose holder is known to be gone.
        N)
break_lockr.   s    r&   force_breakzMarkerSoftFileLock.force_breakH   s     	r%   c                    t          t          t                    5  t          t	          | j                  d                   cd d d            S # 1 swxY w Y   d S )Nr   )r   OSError
ValueErrorparse_markerr   	lock_filer.   s    r&   r-   zMarkerSoftFileLock._read_ownerQ   s    gz** 	D 	D ? ? BCC	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	Dts   'AAAfdr   c                d    t          |t          |                                                      d S )N)r   encode_marker_published_record)r/   rA   s     r&   _write_lock_infoz#MarkerSoftFileLock._write_lock_infoV   s,    "mD$:$:$<$<==>>>>>r%   r   c           	         t          t          j                    t                      | j        t          t          j                                        S )N)r   r   r   r   )r   r5   r6   r	   r)   r
   r.   s    r&   rD   z$MarkerSoftFileLock._published_recordY   s@    	[[!%bikk22	
 
 
 	
r%   N)r*   r+   )r*   r   )r*   r3   )r*   r8   )rA   r   r*   r8   )r*   r   )r   r    r!   r"   r#   propertyr0   r   r7   r;   r-   rE   rD   r$   r%   r&   r(   r(   #   s         KK " " " X" L L L XL ` ` ` X`      
? ? ? ?
 
 
 
 
 
r%   r(   recordr*   bytesc                   t           d| j         d| j         d| j         g}| j        |                    d| j                    | j        |                    d| j                   | j        |                    d| j                    d                    d	 |D                       	                                S )
z>Render an owner record as the bytes a protocol 2 marker holds.zpid=zhost=zmode=Nztoken=z	duration=zstart= c              3      K   | ]	}| d V  
dS )
Nr$   ).0lines     r&   	<genexpr>z encode_marker.<locals>.<genexpr>k   s(      114d;;;111111r%   )
r   r   r   r   r   appendr   r   joinencode)rH   liness     r&   rC   rC   b   s    +vz++-FV_-F-FH]PVP[H]H]^E|,fl,,---(:!6::;;;|,fl,,---771151111188:::r%   contentr   r+   c                    | r9|                                                                  x}r|d         t          k    rdS i }|dd         D ]%}|                    d          \  }}}|s dS |||<   &t	          |          S )zcReturn the owner a protocol 2 marker names, or ``None`` when the record is malformed or protocol 1.r   Nr   =)strip
splitlinesr   	partition_build_record)rU   rT   fieldsrO   key	separatorvalues          r&   r?   r?   n   s     GMMOO$>$>$@$@@5 U1XQZEZEZtFabb	   $s 3 3Y 	44s   r%   r\   dict[str, str]c                
   |                      d          x}d S |dk    rdnd}|                      d          }|rd| vrd S 	 t          | d                   }d| v rt          | d                   nd }d| v rt          | d                   nd }n# t          $ r Y d S w xY wd|cxk    rt          k    sn d S |                      d	          }|dk    r ||t          j        |          r|d
k    sd S t          ||||||          S )Nr   r   r   hostr   durationr   r   r   r   )r   r   r   r   r   r   )getr   floatr>   r   mathisfiniter   )r\   	publishedr   r   r   rc   r   r   s           r&   r[   r[   {   s]   
 ZZ'''	0t!*g!5!5gg9Dzz&!!H uF**t&-  0:f0D0D5
+,,,$(/6(9(9F7O$$$t   ttxtJJwE wEMX-=dmT\F]F]-=bjmnbnbnt3EZbjopppps   AB 
BB)r(   r   r   rC   r?   )rH   r   r*   rI   )rU   r   r*   r+   )r\   r`   r*   r+   )
__future__r   rf   r5   
contextlibr   typingr   r   r   	_identityr	   r
   _softr   r   _utilr   r   r#   r   r   r   r(   rC   r?   r[   __all__r$   r%   r&   <module>rp      sy   " " " " " " "  				       - - - - - - - - - - 5 5 5 5 5 5 5 5 0 0 0 0 0 0 0 0      
 %	 $ $ $ $          &'	    *   <
 <
 <
 <
 <
 <
 <
 <
~	; 	; 	; 	;
! 
! 
! 
!q q q q8  r%   