
    \j                        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y)    )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                  Z    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<   y)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        C/root/.hermes/venv/lib/python3.12/site-packages/filelock/_marker.pyr   r      s2    5	HM
OE:#'NL'E:r%   r   c                  r    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y)MarkerSoftFileLockzAAn existence lock whose marker carries a protocol 2 owner record.r   _owner_modec                "    | j                         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%   c                B    | j                         x}dS |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-   r.   s     r&   r   zMarkerSoftFileLock.pid3   s&     "&!1!1!33<tK%))Kr%   c                    | j                         }|duxr: |j                  t        j                         k(  xr |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	   r0   s     r&   is_lock_held_by_usz%MarkerSoftFileLock.is_lock_held_by_us=   sC       "D _UYY"))+%=_%..T]T_B__r%   c                $    | j                          y)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 Y   y xY w)Nr   )r   OSError
ValueErrorparse_markerr   	lock_filer,   s    r&   r+   zMarkerSoftFileLock._read_ownerQ   s>    gz* 	D ? BC	D 	D 	Ds   !A  A	c                J    t        |t        | j                                      y )N)r   encode_marker_published_record)r-   fds     r&   _write_lock_infoz#MarkerSoftFileLock._write_lock_infoV   s    "mD$:$:$<=>r%   c           	         t        t        j                         t               | j                  t        t        j                                     S )N)r   r   r   r   )r   r2   r3   r	   r)   r
   r,   s    r&   r?   z$MarkerSoftFileLock._published_recordY   s4    		[!!%biik2	
 	
r%   N)returnOwnerRecord | None)rC   r   )rC   bool)rC   None)r@   r   rC   rF   )rC   r   )r   r    r!   r"   r#   propertyr.   r   r4   r7   r+   rA   r?   r$   r%   r&   r(   r(   #   s_    K " " L L ` `
?
r%   r(   c                   t         d| j                   d| j                   d| j                   g}| j                  |j                  d| j                          | j                  |j                  d| j                         | j                  |j                  d| j                          dj                  d |D              j                         S )	z>Render an owner record as the bytes a protocol 2 marker holds.zpid=zhost=zmode=ztoken=z	duration=zstart= c              3  &   K   | ]	  }| d   yw)
Nr$   ).0lines     r&   	<genexpr>z encode_marker.<locals>.<genexpr>k   s     14dV2;1s   )
r   r   r   r   r   appendr   r   joinencode)recordliness     r&   r>   r>   b   s    $vzzl+uV__4E-F%PVP[P[}H]^E||vfll^,-(y!6!6 9:;||vfll^,-77151188::r%   c                    | r,| j                         j                         x}r|d   t        k7  ryi }|dd D ]   }|j                  d      \  }}}|s y|||<   " 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)contentrS   fieldsrM   key	separatorvalues          r&   r;   r;   n   sx    GMMO$>$>$@@5@U1XQZEZFab	  $s 3Ys	
   r%   c                   | j                  d      x}y |dk(  rdnd}| j                  d      }|rd| vry 	 t        | d         }d| v rt        | d         nd }d| v rt        | d         nd }d|cxk  r	t        k  sy  y | j                  d	      }|dk(  r||t        j                  |      r|d
kD  sy t        ||||||      S # t        $ r Y y w xY w)Nr   r   r   hostr   durationr   r   r   r   )r   r   r   r   r   r   )getr   floatr:   r   mathisfiniter   )r[   	publishedr   r   r   ra   r   r   s           r&   rY   rY   {   s   
 ZZ''	0!*g!5g9Dzz&!HuF*&- 0:f0D5
+,$(/6(9F7O$t x  JJwE wEMX-=dmmT\F]bjmnbn3EZbjopp  s   6C 	CC)r(   r   r   r>   r;   )rR   r   rC   bytes)rZ   r   rC   rD   )r[   zdict[str, str]rC   rD   )
__future__r   rd   r2   
contextlibr   typingr   r   r   	_identityr	   r
   _softr   r   _utilr   r   r#   r   r   r   r(   r>   r;   rY   __all__r$   r%   r&   <module>ro      ss    "  	  - - 5 0 
 %	: $ *   &'	* <
 <
~	;
!q8r%   