§
    Ò¬¸j¼M  ã                  óì  — U d Z ddlmZ ddlZddlZddlmZ ddlmZ ddl	m
Z
 ddlmZmZmZmZ ddlmZ dd	lmZ erdd
lmZ ed         Zed         ZdZded<   dZded<   dZded<   dZded<   dZded<   dZded<   dZded<   dZ ded<    G d„ d e¦  «        Z! ed!¬"¦  «         G d#„ d$¦  «        ¦   «         Z"d9d)„Z#d:d-„Z$d;d.„Z%d<d1„Z& G d2„ d3¦  «        Z' G d4„ d5¦  «        Z( G d6„ d7¦  «        Z)g d8¢Z*dS )=aw  
The generation-log protocol behind :class:`~filelock.SoftReadWriteLock`.

The lock's whole state is a sequence of immutable snapshots, ``gen/<N>``, each naming the writer and the readers that
hold the lock at generation ``N``. Every transition is one atomic publication of the next snapshot: a participant reads
the latest generation, derives the successor it wants, and links a fully written temporary file to ``gen/<N+1>``. The
link fails if a peer got there first, so the participant re-reads and tries again. No step is ever half done: a crash
leaves at most an unlinked temporary file, never a state that another participant must repair before it can proceed.

Liveness rests on a nonce, not a clock. Each participant keeps ``holders/<token>`` and rewrites its nonce every
heartbeat. A contender records the bytes it read there and the moment it read them on its own monotonic clock; a
member whose bytes have not changed for ``stale_threshold`` is evicted by committing a snapshot without it. Two hosts
never compare clocks, so a skewed file server or a suspended virtual machine cannot make a live holder look dead.

The generation number is monotonic and unique to one transition, so the generation at which a hold was granted fences
it: a resource that rejects anything carrying a lower generation than the highest it has accepted refuses a holder
that paused past its expiry and resumed.
é    )ÚannotationsN)Úsuppress)Ú	dataclass)ÚPath)ÚTYPE_CHECKINGÚFinalÚLiteralÚProtocol)ÚSoftFileLockProtocolError)Ú	host_name)ÚCallable)ÚreadÚwrite)ÚokÚlostÚ	transientzfilelock-rw/1z
Final[str]Ú	_PROTOCOLé   z
Final[int]Ú_GENERATION_DIGITSé    Ú_TOKEN_HEX_LENGTHi   Ú_MAX_RECORD_SIZEé@   Ú_RETAINED_GENERATIONSÚgenÚ_GENERATIONS_DIRECTORYÚholdersÚ_HOLDERS_DIRECTORYz.commit-Ú_TEMPORARY_PREFIXc                  óJ   — e Zd ZdZdd„Zdd
„Zdd„Zdd„Zdd„Zdd„Z	dd„Z
dS )ÚFilesz`The filesystem operations the protocol runs on; :mod:`._storage` implements them over :mod:`os`.ÚpathÚstrÚreturnúbytes | Nonec                ó   — dS )z\The file's bytes, ``None`` when it does not exist, or ``b""`` when it is not a regular file.N© ©Úselfr"   s     úk/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/filelock/_soft_rw/_protocol.pyr   z
Files.read7   ó   € € € ó    ÚdataÚbytesÚNonec                ó   — dS )zdCreate the file exclusively with the whole record written; raise ``FileExistsError`` when it exists.Nr'   ©r)   r"   r-   s      r*   ÚcreatezFiles.create:   r+   r,   ÚsourceÚtargetÚboolc                ó   — dS )zjHard-link *source* to *target* without replacing; ``True`` when *target* names *source*'s file afterwards.Nr'   )r)   r3   r4   s      r*   Úlinkz
Files.link=   r+   r,   c                ó   — dS )zORewrite the file in place from offset zero; ``False`` when it no longer exists.Nr'   r1   s      r*   Ú	overwritezFiles.overwrite@   r+   r,   c                ó   — dS )z5Remove the file, tolerating one that is already gone.Nr'   r(   s     r*   ÚunlinkzFiles.unlinkC   r+   r,   ú	list[str]c                ó   — dS )zDThe names in the directory, or an empty list when it does not exist.Nr'   r(   s     r*   ÚlistdirzFiles.listdirF   r+   r,   Úrootc                ó   — dS )zgCreate the protocol directories under *root*, refusing anything at those paths that is not a directory.Nr'   )r)   r?   s     r*   ÚpreparezFiles.prepareI   r+   r,   N)r"   r#   r$   r%   )r"   r#   r-   r.   r$   r/   )r3   r#   r4   r#   r$   r5   )r"   r#   r-   r.   r$   r5   )r"   r#   r$   r/   )r"   r#   r$   r<   )r?   r#   r$   r/   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r2   r7   r9   r;   r>   rA   r'   r,   r*   r!   r!   4   sÄ   € € € € € ØjÐjðkð kð kð kðsð sð sð sðyð yð yð yð^ð ^ð ^ð ^ðDð Dð Dð DðSð Sð Sð Sðvð vð vð vð vð vr,   r!   T)Úfrozenc                  óR   — e Zd ZU dZded<   ded<   ded<   edd	„¦   «         Zdd„ZdS )ÚSnapshotzJThe lock's state at one generation: which token writes, which tokens read.ÚintÚ
generationú
str | NoneÚwriterúfrozenset[str]Úreadersr$   c                ó>   — | j         €| j        n| j        | j         hz  S )z"Every token this generation names.)rL   rN   ©r)   s    r*   ÚmemberszSnapshot.membersU   s"   € ð  $œ{Ð2ˆtŒ|ˆ|¸¼ÈÌÀ}Ñ8TÐTr,   r.   c                ó2  — t           d| j        › �g}| j        �|                     d| j        › �¦  «         |                     d„ t          | j        ¦  «        D ¦   «         ¦  «         d                     d„ |D ¦   «         ¦  «                             d¦  «        S )Nzgeneration=zwriter=c              3  ó    K  — | ]	}d |› �V — Œ
dS )zreader=Nr'   )Ú.0Útokens     r*   ú	<genexpr>z"Snapshot.encode.<locals>.<genexpr>^   s+   è è € ÐIÐI¨5Ð&˜uÐ&Ð&ÐIÐIÐIÐIÐIÐIr,   Ú c              3  ó    K  — | ]	}|› d �V — Œ
dS )ú
Nr'   )rT   Úlines     r*   rV   z"Snapshot.encode.<locals>.<genexpr>_   s(   è è € Ð5Ð5 t˜$�{�{�{Ð5Ð5Ð5Ð5Ð5Ð5r,   Úascii)	r   rJ   rL   ÚappendÚextendÚsortedrN   ÚjoinÚencode)r)   Úliness     r*   r`   zSnapshot.encodeZ   s–   € ÝÐ;¨$¬/Ð;Ð;Ð<ˆØŒ;Ð"Ø�LŠLÐ0 4¤;Ð0Ð0Ñ1Ô1Ð1Ø�ŠÐIÐIµF¸4¼<Ñ4HÔ4HÐIÑIÔIÑIÔIÐIØ�wŠwÐ5Ð5¨uÐ5Ñ5Ô5Ñ5Ô5×<Ò<¸WÑEÔEÐEr,   N)r$   rM   )r$   r.   )rB   rC   rD   rE   Ú__annotations__ÚpropertyrQ   r`   r'   r,   r*   rH   rH   M   sy   € € € € € € àTÐTà€O€O�OØÐÐÑØÐÐÑàðUð Uð Uñ „XðUðFð Fð Fð Fð Fð Fr,   rH   r-   r.   r$   úSnapshot | Nonec                óú  — | rt          | ¦  «        t          k    rdS 	 |                      d¦  «                             d¦  «        }n# t          $ r Y dS w xY w|d         t
          k    s|d         rdS d}d}t          ¦   «         }|dd…         D ]Ê}|                     d¦  «        \  }}}|dk    r^|€\t          |¦  «        t          k    rD| 	                    ¦   «         r0t          t          |¦  «        ¦  «        |k    rt          |¦  «        }Œ|d	k    r|€t          |¦  «        r|}Œ™|d
k    r)t          |¦  «        r||vr|                     |¦  «         ŒÈ dS |€dnt          ||t          |¦  «        ¬¦  «        S )zTThe snapshot a ``gen/<N>`` record encodes, or ``None`` when the record is malformed.Nr[   rY   r   éÿÿÿÿé   ú=rJ   rL   Úreader©rJ   rL   rN   )Úlenr   ÚdecodeÚsplitÚUnicodeDecodeErrorr   ÚsetÚ	partitionr   Úisdigitr#   rI   Úis_tokenÚaddrH   Ú	frozenset)	r-   ra   rJ   rL   rN   rZ   ÚkeyÚ_Úvalues	            r*   Úparse_snapshotrx   b   s�  € àð •3�t‘9”9Õ/Ò/Ð/ØˆtðØ—’˜GÑ$Ô$×*Ò*¨4Ñ0Ô0ˆˆøÝð ð ð ØˆtˆtðøøøàˆQ„x•9ÒÐ  b¤	ÐØˆtØ!€JØ€FÝ™œ€GØ�a˜�d”ð ð ˆØŸš sÑ+Ô+‰ˆˆQ�à�<ÒÐØÐ"Ý�E‘
”
Õ0Ò0Ð0Ø—’‘”ð 1å•C˜‘J”J‘” 5Ò(Ð(å˜U™œˆJˆJØ�HŠ_ˆ_  µH¸U±O´O ØˆFˆFØ�HŠ_ˆ_¥¨%¡¤ˆ_°UÀ'Ð5IÐ5IØ�KŠK˜ÑÔÐÐà�4�4ØÐ%ˆ4ˆ4­8¸zÐRXÕbkÐlsÑbtÔbtÐ+uÑ+uÔ+uÐus   ž(A Á
AÁArw   r#   r5   c                ód   — t          | ¦  «        t          k    ot          d„ | D ¦   «         ¦  «        S )zBWhether *value* is a claim token: exactly 32 lowercase hex digits.c              3  ó   K  — | ]}|d v V — Œ	dS )Ú0123456789abcdefNr'   )rT   Ú	characters     r*   rV   zis_token.<locals>.<genexpr>„   s)   è è € Ð2jÐ2jÐW`°9Ð@RÐ3RÐ2jÐ2jÐ2jÐ2jÐ2jÐ2jr,   )rk   r   Úall)rw   s    r*   rr   rr   ‚   s1   € åˆu‰:Œ:Õ*Ò*Ðj­sÐ2jÐ2jÐdiÐ2jÑ2jÔ2jÑ/jÔ/jÐjr,   c                 ó:   — t          j        t          dz  ¦  «        S )zA fresh claim token.é   )ÚsecretsÚ	token_hexr   r'   r,   r*   Ú	new_tokenr‚   ‡   s   € åÔÕ.°!Ñ3Ñ4Ô4Ð4r,   rU   Únoncec           
     óŽ   — t           › d| › dt          j        ¦   «         › dt          ¦   «         › d|› d�
                     d¦  «        S )zhThe ``holders/<token>`` record; only the nonce changes between heartbeats, so the length stays constant.z
token=z
pid=z
host=z
nonce=rY   r[   )r   ÚosÚgetpidr   r`   )rU   rƒ   s     r*   Úencode_holderr‡   Œ   sK   € åÐ`Ð` Ð`Ð`­b¬i©k¬kÐ`Ð`Å)Á+Ä+Ð`Ð`ÐW\Ð`Ð`Ð`×gÒgÐhoÑpÔpÐpr,   c                  ó*   — e Zd ZdZdd„Zdd„Zdd„ZdS )ÚLedgera�  
    How long each observed value has stayed the same, measured on this observer's monotonic clock.

    A value that has not changed for ``stale_threshold`` belongs to a participant that stopped refreshing it. The clock
    is the observer's own and only ever measures the gap between two of its own observations, which is what lets two
    hosts agree on liveness without agreeing on the time.
    ÚclockúCallable[[], float]r$   r/   c                ó"   — || _         i | _        d S ©N)Ú_clockÚ_seen)r)   rŠ   s     r*   Ú__init__zLedger.__init__š   s   € ØˆŒØ<>ˆŒ
ˆ
ˆ
r,   ru   r#   rw   r%   Úfloatc                ó¬   — |                       ¦   «         }| j                             |¦  «        x}�|d         |k    r||f| j        |<   dS ||d         z
  S )zCRecord *value* for *key* and return how long it has been unchanged.Nr   g        rg   )rŽ   r�   Úget)r)   ru   rw   ÚnowÚseens        r*   ÚobservezLedger.observež   sX   € à�kŠk‰mŒmˆØ”J—N’N 3Ñ'Ô'Ð'ˆDÐ0°D¸´G¸uÒ4DÐ4DØ$ c˜lˆDŒJ�s‰OØ�3Ø�T˜!”W‰}Ðr,   c                ó<   — | j                              |d ¦  «         d S r�   )r�   Úpop)r)   ru   s     r*   ÚforgetzLedger.forget¦   s   € ØŒ
�Š�s˜DÑ!Ô!Ð!Ð!Ð!r,   N)rŠ   r‹   r$   r/   )ru   r#   rw   r%   r$   r‘   )ru   r#   r$   r/   )rB   rC   rD   rE   r�   r–   r™   r'   r,   r*   r‰   r‰   ‘   sZ   € € € € € ðð ð?ð ?ð ?ð ?ðð ð ð ð"ð "ð "ð "ð "ð "r,   r‰   c                  ób   — e Zd ZdZdd	„Zdd„Zdd„Zdd„Zdd„Zdd„Z	d d„Z
ed d„¦   «         ZdS )!ÚGenerationLogzeThe ordered snapshots under ``gen/``, found by listing and probing, advanced by linking the next one.Úfilesr!   Ú	lock_filer#   r?   r$   r/   c                ód   — || _         || _        t          |t          ¦  «        | _        d | _        d S r�   )Ú_filesÚ
_lock_filer   r   Ú
_directoryÚ_latest)r)   rœ   r�   r?   s       r*   r�   zGenerationLog.__init__­   s-   € ØˆŒØ#ˆŒÝ˜tÕ%;Ñ<Ô<ˆŒØ(,ˆŒˆˆr,   rH   c                óº  — |                       ¦   «         }|                      |¦  «        x}€a|                       ¦   «         }|                      |¦  «        x}€6|rt          | j        dd¦  «        ‚t	          ddt          ¦   «         ¬¦  «        }|}|j        }d}|t          k     r1|dz  }|                      |¦  «        x}€|dz  }Œ-|}d}|t          k     °1|| _	        |S )a­  
        The newest snapshot.

        Lists the directory on every call, since opening it is what makes an NFS client revalidate what it has cached
        about the names inside, then starts from the newest readable generation the listing or memory names and probes
        forward by name across the retained window. A listing served stale, a generation compacted between the listing
        and the read, and a hole left by a committer that died before it compacted are all covered by the probe; only a
        listing that names generations of which none can be read is refused, because that is a client so far behind
        the log that nothing it reads can be trusted.
        Nz)generation log names no readable snapshotr   rj   rg   )
Ú_listÚ_startr   r    rH   rt   rJ   r   Ú_readr¢   )r)   ÚlistedÚstartÚlatestrJ   ÚgapÚsnapshots          r*   r©   zGenerationLog.latest³   sô   € ð —’‘”ˆØ—[’[ Ñ(Ô(Ð(ˆEÐ1ð —Z’Z‘\”\ˆFØŸš VÑ,Ô,Ð,�Ð5Øð xÝ3°D´OÀTÐKvÑwÔwÐwÝ ¨A°dÅIÁKÄKÐPÑPÔP�ØˆØÔ%ˆ
ØˆØÕ)Ò)Ð)Ø˜!‰OˆJØ ŸJšJ zÑ2Ô2Ð2�Ð;Ø�q‘�ØØˆFØˆCð Õ)Ò)Ð)ð ˆŒØˆr,   ú	list[int]c                ó(  — t          d„ | j                             t          | j        ¦  «        ¦  «        D ¦   «         ¦  «        }|d t
           …         D ]/}| j                             |                      |¦  «        ¦  «         Œ0|t
           d …         S )Nc              3  óŒ   K  — | ]?}|                      ¦   «         r)t          |¦  «        t          k    ¯.t          |¦  «        V — Œ@d S r�   )rq   rk   r   rI   )rT   Únames     r*   rV   z&GenerationLog._list.<locals>.<genexpr>Õ   sX   è è € ð 
ð 
àØ�|Š|‰~Œ~ð
õ #& d¡)¤)Õ/AÒ"AÐ"Aõ �‰IŒIà"AÐ"AÐ"AÐ"Að
ð 
r,   )r^   rŸ   r>   r#   r¡   r   r;   Ú_path)r)   r§   rJ   s      r*   r¤   zGenerationLog._listÔ   s¡   € Ýð 
ð 
àœ×+Ò+­C°´Ñ,@Ô,@ÑAÔAð
ñ 
ô 
ñ 
ô 
ˆð
 !Ð!8Õ#8Ð"8Ð!8Ô9ð 	7ð 	7ˆJØŒK×Ò˜tŸzšz¨*Ñ5Ô5Ñ6Ô6Ð6Ð6ØÕ,Ð,Ð-Ð-Ô.Ð.r,   r§   rd   c                ó�   — | j         }t          |¦  «        D ].}|�|j        |k    r|c S |                      |¦  «        x}�|c S Œ/|S r�   )r¢   ÚreversedrJ   r¦   )r)   r§   Ú
rememberedrJ   r«   s        r*   r¥   zGenerationLog._startÞ   sk   € Ø”\ˆ
Ý" 6Ñ*Ô*ð 	 ð 	 ˆJØÐ%¨*Ô*?À:Ò*MÐ*MØ!Ð!Ð!Ð!Ø ŸJšJ zÑ2Ô2Ð2�Ð?Ø���ð @àÐr,   rJ   rI   c                óö   — | j                              |                      |¦  «        ¦  «        x}€d S t          |¦  «        x}�|j        |k    r+|                      |¦  «        }t          | j        |d¦  «        ‚|S )Nzmalformed generation record)rŸ   r   r°   rx   rJ   Ú_namer   r    )r)   rJ   r-   r«   r¯   s        r*   r¦   zGenerationLog._readç   sz   € Ø”K×$Ò$ T§Z¢Z°
Ñ%;Ô%;Ñ<Ô<Ð<ˆDÐEØ�4Ý& tÑ,Ô,Ð,ˆHÐ5¸Ô9LÐPZÒ9ZÐ9ZØ—:’:˜jÑ)Ô)ˆDÝ+¨D¬O¸TÐC`ÑaÔaÐaØˆr,   Ú	successorr5   c                ó$  — t          | j        t          › t          ¦   «         › �z  ¦  «        }| j                             ||                     ¦   «         ¦  «         	 | j                             ||                      |j	        ¦  «        ¦  «        }| j         
                    |¦  «         n# | j         
                    |¦  «         w xY w|sdS || _        | j         
                    |                      |j	        t          z
  dz
  ¦  «        ¦  «         dS )aÄ  
        Publish *successor* as the next generation; ``False`` when a peer published that generation first.

        The record is complete before it gets its public name, and a no-replace hard link is the compare-and-swap: only
        one link to ``gen/<N+1>`` can ever succeed. The link's return code is not trusted, because an NFS retry can
        report a link that did land as failed; the file's identity after the call is what decides.
        Frg   T)r#   r¡   r   r‚   rŸ   r2   r`   r7   r°   rJ   r;   r¢   r   )r)   r¶   Ú	temporaryÚlinkeds       r*   ÚcommitzGenerationLog.commitï   sö   € õ ˜œÕ->Ð*MÅ	ÁÄÐ*MÐ*MÑMÑNÔNˆ	ØŒ×Ò˜9 i×&6Ò&6Ñ&8Ô&8Ñ9Ô9Ð9ð	*Ø”[×%Ò% i°·²¸IÔ<PÑ1QÔ1QÑRÔRˆFàŒK×Ò˜yÑ)Ô)Ð)Ð)øˆDŒK×Ò˜yÑ)Ô)Ð)Ð)øøøØð 	Ø�5Ø ˆŒØŒ×Ò˜4Ÿ:š: iÔ&:Õ=RÑ&RÐUVÑ&VÑWÔWÑXÔXÐXØˆts   Á3B) Â)Cc                óV   — t          | j        |                      |¦  «        z  ¦  «        S r�   )r#   r¡   rµ   )r)   rJ   s     r*   r°   zGenerationLog._path  s#   € Ý�4”? T§Z¢Z°
Ñ%;Ô%;Ñ;Ñ<Ô<Ð<r,   c                ó   — | dt           › d�›S )NÚ0Úd)r   )rJ   s    r*   rµ   zGenerationLog._name  s   € àÐ5Õ1Ð5Ð5Ð5Ð5Ð5r,   N)rœ   r!   r�   r#   r?   r#   r$   r/   )r$   rH   )r$   r¬   )r§   r¬   r$   rd   )rJ   rI   r$   rd   )r¶   rH   r$   r5   )rJ   rI   r$   r#   )rB   rC   rD   rE   r�   r©   r¤   r¥   r¦   rº   r°   Ústaticmethodrµ   r'   r,   r*   r›   r›   ª   sÇ   € € € € € ØoÐoð-ð -ð -ð -ðð ð ð ðB/ð /ð /ð /ðð ð ð ðð ð ð ðð ð ð ð(=ð =ð =ð =ð ð6ð 6ð 6ñ „\ð6ð 6ð 6r,   r›   c                  ór   — e Zd ZdZd,d„Zd-d„Zd.d„Zd/d„Zd/d„Zd0d„Z	d1d#„Z
d2d%„Zd3d&„Zd.d'„Zd4d)„Zd-d*„Zd+S )5ÚParticipanta0  
    One acquisition, from publishing a claim through holding the lock to leaving.

    ``advance`` is polled until it reports the lock granted, ``heartbeat`` runs on the holder's schedule, and ``leave``
    commits the participant out. None of them sleep: the caller owns the deadline and the poll interval. The ledger and
    the log outlive one acquisition: how long a peer's record has stayed unchanged is knowledge every attempt against
    the same lock shares, or a caller whose attempts are each shorter than the stale threshold could never evict.
    rœ   r!   r?   r#   ÚmodeÚModeÚstale_thresholdr‘   rŠ   r‹   Úledgerr‰   Úlogr›   r$   r/   c               ó  — t          ¦   «         | _        || _        d | _        || _        || _        || _        || _        || _        || _	        |  
                    | j        ¦  «        | _        d| _         |¦   «         | _        d S )NF)r‚   rU   rÂ   rJ   rŸ   Ú_rootÚ_stale_thresholdrŽ   Ú_ledgerÚ_logÚ_holder_pathÚ_holderÚ_enteredÚ_next_sweep)r)   rœ   r?   rÂ   rÄ   rŠ   rÅ   rÆ   s           r*   r�   zParticipant.__init__  sz   € õ "+¡¤ˆŒ
Ø!%ˆŒ	Ø&*ˆŒØˆŒØˆŒ
Ø /ˆÔØˆŒØˆŒØˆŒ	Ø×(Ò(¨¬Ñ4Ô4ˆŒØˆŒØ ˜5™7œ7ˆÔÐÐr,   c                óÂ   — | j                              | j        ¦  «         | j                              | j        t          | j        t          ¦   «         ¦  «        ¦  «         dS )zfCreate the holder record peers watch for liveness; it exists before the token appears in any snapshot.N)rŸ   rA   rÈ   r2   rÍ   r‡   rU   r‚   rP   s    r*   ÚpublishzParticipant.publish-  sJ   € àŒ×Ò˜DœJÑ'Ô'Ð'ØŒ×Ò˜4œ<­°t´zÅ9Á;Ä;Ñ)OÔ)OÑPÔPÐPÐPÐPr,   r5   c                óh  ‡ — t          d¦  «        D �]}‰ j                             ¦   «         }‰                      |¦  «         ‰                      |¦  «         t          ˆ fd„|j        ‰ j        hz
  D ¦   «         ¦  «        }|j        |v rdn|j        }|j	        |z
  }‰ j
        sC|�|r‰                      ||||¦  «          dS ‰ j        dk    r	‰ j        |fnd|‰ j        hz  f\  }}‰ j        dk    p| }‰ j
        r|s|s dS ‰                      ||||¦  «        x}€�Œd‰ _
        |r|‰ _        |c S dS )aö  
        Take the next step toward holding the lock; ``True`` once the lock is granted.

        A reader enters as soon as no live writer is named. A writer enters as soon as no live writer is named, which
        blocks every new reader, then waits for the named readers to leave. Stale members are evicted in the same commit
        that admits this participant, and a writer's final admission is itself a commit, so no admission can rest on a
        snapshot a peer is about to supersede.
        é   c              3  óF   •K  — | ]}‰                      |¦  «        ¯|V — Œd S r�   )Ú	_is_stale)rT   rU   r)   s     €r*   rV   z&Participant.advance.<locals>.<genexpr>A  s8   øè è € ÐhÐh¨ÐRV×R`ÒR`ÐafÑRgÔRgÐh˜eÐhÐhÐhÐhÐhÐhr,   NFr   r   T)ÚrangerË   r©   Ú_keep_claim_freshÚ_sweeprt   rQ   rU   rL   rN   rÎ   Ú_commitrÂ   rJ   )r)   rv   r©   ÚstalerL   rN   ÚgrantedrJ   s   `       r*   ÚadvancezParticipant.advance2  s†  ø€ õ �q‘”ð 	ñ 	ˆAØ”Y×%Ò%Ñ'Ô'ˆFØ×"Ò" 6Ñ*Ô*Ð*Ø�KŠK˜ÑÔÐÝÐhÐhÐhÐh°´À4Ä:À,Ñ1NÐhÑhÔhÑhÔhˆEØ#œ]¨eÐ3Ð3�T�T¸¼ˆFØ”n uÑ,ˆGØ”=ð tØÐ%àð EØŸš V¨V°W¸eÑDÔDÐDØ ˜5˜5Ø;?¼9ÈÒ;OÐ;O 4¤:¨wÐ"7Ð"7ÐVZÐ\cÐgkÔgqÐfrÑ\rÐUs‘�˜Ø”i 6Ò)Ð8°¨[ˆGØŒ}ð  Uð °7ð Ø�u�uØ"Ÿlšl¨6°6¸7ÀEÑJÔJÐJ�
ÐSÙØ ˆDŒMØð -Ø",�”ØˆNˆNˆNØˆur,   r©   rH   c           	     ó0  — | j         |j        v | _        |                      ¦   «         snt	          t
          ¦  «        5  | j                             | j        t          | j         t          ¦   «         ¦  «        ¦  «         d d d ¦  «         d S # 1 swxY w Y   d S d S r�   )rU   rQ   rÎ   Ú_refresh_noncer   ÚFileExistsErrorrŸ   r2   rÍ   r‡   r‚   )r)   r©   s     r*   r×   zParticipant._keep_claim_freshV  så   € ð
 œ
 f¤nÐ4ˆŒØ×"Ò"Ñ$Ô$ð 	YÝ�/Ñ*Ô*ð Yð YØ”×"Ò" 4¤<µ¸t¼zÍ9É;Ì;Ñ1WÔ1WÑXÔXÐXðYð Yð Yñ Yô Yð Yð Yð Yð Yð Yð Yð Yøøøð Yð Yð Yð Yð Yð Yð	Yð 	Ys   ¼A B	Â	BÂBc                óš  — |                       ¦   «         x}| j        k     rd S || j        dz  z   | _        t          | j        t
          ¦  «        }| j                             t          |¦  «        ¦  «        D ]N}|| j	        k    rA||j
        vr8t          |¦  «        r)|                      d|› �t          ||z  ¦  «        ¦  «         ŒOt          | j        t          ¦  «        }| j                             t          |¦  «        ¦  «        D ]E}|                     t          ¦  «        r)|                      d|› �t          ||z  ¦  «        ¦  «         ŒFd S )Nr   zholder:z
temporary:)rŽ   rÏ   rÉ   r   rÈ   r   rŸ   r>   r#   rU   rQ   rr   Ú_collectr   Ú
startswithr   )r)   r©   r”   r   r¯   Úgenerationss         r*   rØ   zParticipant._sweep`  sH  € ð —;’;‘=”=Ð ˆC DÔ$4Ò4Ð4ØˆFØ Ô!6¸Ñ!:Ñ:ˆÔÝ�t”zÕ#5Ñ6Ô6ˆØ”K×'Ò'­¨G©¬Ñ5Ô5ð 	Eð 	EˆDØ�t”zÒ!Ð! d°&´.Ð&@Ð&@ÅXÈdÁ^Ä^Ð&@Ø—’Ð.¨Ð.Ð.µ°G¸d±NÑ0CÔ0CÑDÔDÐDøÝ˜4œ:Õ'=Ñ>Ô>ˆØ”K×'Ò'­¨KÑ(8Ô(8Ñ9Ô9ð 	Lð 	LˆDØ�ŠÕ0Ñ1Ô1ð LØ—’Ð1¨4Ð1Ð1µ3°{ÀTÑ7IÑ3JÔ3JÑKÔKÐKøð	Lð 	Lr,   ru   r"   c                óê   — | j                              || j                             |¦  «        ¦  «        | j        k    r6| j                             |¦  «         | j                              |¦  «         d S d S r�   )rÊ   r–   rŸ   r   rÉ   r;   r™   )r)   ru   r"   s      r*   rá   zParticipant._collectp  sm   € ØŒ<×Ò  T¤[×%5Ò%5°dÑ%;Ô%;Ñ<Ô<ÀÔ@UÒUÐUØŒK×Ò˜tÑ$Ô$Ð$ØŒL×Ò Ñ$Ô$Ð$Ð$Ð$ð VÐUr,   rL   rK   rN   rM   rÚ   ú
int | Nonec                ó  — t          |j        dz   ||¬¦  «        }| j                             |¦  «        sd S |D ]I}| j                             |                      |¦  «        ¦  «         | j                             |¦  «         ŒJ|j        S )Nrg   rj   )	rH   rJ   rË   rº   rŸ   r;   rÌ   rÊ   r™   )r)   r©   rL   rN   rÚ   r¶   rU   s          r*   rÙ   zParticipant._commitu  s“   € õ ¨Ô(9¸AÑ(=ÀfÐV]Ð^Ñ^Ô^ˆ	ØŒy×Ò 	Ñ*Ô*ð 	Ø�4Øð 	'ð 	'ˆEØŒK×Ò˜t×0Ò0°Ñ7Ô7Ñ8Ô8Ð8ØŒL×Ò Ñ&Ô&Ð&Ð&ØÔ#Ð#r,   rU   c                ó    — | j                              || j                             |                      |¦  «        ¦  «        ¦  «        | j        k    S r�   )rÊ   r–   rŸ   r   rÌ   rÉ   ©r)   rU   s     r*   rÕ   zParticipant._is_stale€  sA   € ØŒ|×#Ò# E¨4¬;×+;Ò+;¸D×<MÒ<MÈeÑ<TÔ<TÑ+UÔ+UÑVÔVÐZ^ÔZoÒoÐor,   c                óR   — t          t          | j        t          |¦  «        ¦  «        S r�   )r#   r   rÈ   r   rè   s     r*   rÌ   zParticipant._holder_pathƒ  s   € Ý•4˜œ
Õ$6¸Ñ>Ô>Ñ?Ô?Ð?r,   c                ó€   — | j                              | j        t          | j        t          ¦   «         ¦  «        ¦  «        S r�   )rŸ   r9   rÍ   r‡   rU   r‚   rP   s    r*   rÞ   zParticipant._refresh_nonce†  s,   € ØŒ{×$Ò$ T¤\µ=ÀÄÍYÉ[Ì[Ñ3YÔ3YÑZÔZÐZr,   ú'tuple[HeartbeatOutcome, OSError | None]c                ó  — 	 |                       ¦   «         sdS n# t          $ r}d|fcY d}~S d}~ww xY w	 | j                             ¦   «         }|                      |¦  «         n# t          $ r Y dS w xY w| j        |j        v rdnddfS )aì  
        Refresh the nonce and confirm the latest snapshot still names this participant.

        ``lost`` means a peer evicted this participant or removed its holder record: the lock is no longer held, and the
        holder must stop using what it protects. ``transient`` is a filesystem error refreshing the nonce, worth
        retrying on the next tick. A failure to read the log or to sweep decides nothing about this holder's liveness,
        so it is not counted against it.
        )r   Nr   N)r   Nr   r   )rÞ   ÚOSErrorrË   r©   rØ   rU   rQ   )r)   Úerrorr©   s      r*   Ú	heartbeatzParticipant.heartbeat‰  sÊ   € ð	&Ø×&Ò&Ñ(Ô(ð $Ø#�|ð$øåð 	&ð 	&ð 	&Ø Ð%Ð%Ð%Ð%Ð%Ð%Ð%øøøøð	&øøøð	Ø”Y×%Ò%Ñ'Ô'ˆFØ�KŠK˜ÑÔÐÐøÝð 	ð 	ð 	Ø�:�:ð	øøøàœ
 f¤nÐ4Ð4��¸&À4ÐGÐGs%   ‚ ™
1£,¦1¬1µ.A$ Á$
A2Á1A2c                ó°  — | j         | j                             ¦   «         x}j        v r�t	          |j        dz   |j        | j         k    rdn|j        |j        | j         hz
  ¬¦  «        }| j                             |¦  «        rn'| j         | j                             ¦   «         x}j        v °�d| _	        d| _        | j
                             | j        ¦  «         dS )zRCommit this participant out of the latest snapshot, then remove its holder record.rg   Nrj   F)rU   rË   r©   rQ   rH   rJ   rL   rN   rº   rÎ   rŸ   r;   rÍ   )r)   r©   r¶   s      r*   ÚleavezParticipant.leavež  sÙ   € àŒj t¤y×'7Ò'7Ñ'9Ô'9Ð9˜VÔBÐBÐBÝ Ø!Ô,¨qÑ0Ø%œ}°´
Ò:Ð:�t�tÀÄØœ¨$¬*¨Ñ5ðñ ô ˆIð
 Œy×Ò 	Ñ*Ô*ð Øð Œj t¤y×'7Ò'7Ñ'9Ô'9Ð9˜VÔBÐBÐBð ˆŒØˆŒØŒ×Ò˜4œ<Ñ(Ô(Ð(Ð(Ð(r,   N)rœ   r!   r?   r#   rÂ   rÃ   rÄ   r‘   rŠ   r‹   rÅ   r‰   rÆ   r›   r$   r/   )r$   r/   )r$   r5   )r©   rH   r$   r/   )ru   r#   r"   r#   r$   r/   )
r©   rH   rL   rK   rN   rM   rÚ   rM   r$   rå   )rU   r#   r$   r5   )rU   r#   r$   r#   )r$   rë   )rB   rC   rD   rE   r�   rÑ   rÜ   r×   rØ   rá   rÙ   rÕ   rÌ   rÞ   rï   rñ   r'   r,   r*   rÁ   rÁ     s+  € € € € € ðð ð#ð #ð #ð #ð0Qð Qð Qð Qð
"ð "ð "ð "ðHYð Yð Yð YðLð Lð Lð Lð %ð %ð %ð %ð
	$ð 	$ð 	$ð 	$ðpð pð pð pð@ð @ð @ð @ð[ð [ð [ð [ðHð Hð Hð Hð*)ð )ð )ð )ð )ð )r,   rÁ   )r!   r›   ÚHeartbeatOutcomer‰   rÃ   rÁ   rH   r‡   rr   r‚   rx   )r-   r.   r$   rd   )rw   r#   r$   r5   )r$   r#   )rU   r#   rƒ   r#   r$   r.   )+rE   Ú
__future__r   r…   r€   Ú
contextlibr   Údataclassesr   Úpathlibr   Útypingr   r   r	   r
   Úfilelock._errorr   Úfilelock._identityr   Úcollections.abcr   rÃ   rò   r   rb   r   r   r   r   r   r   r   r!   rH   rx   rr   r‚   r‡   r‰   r›   rÁ   Ú__all__r'   r,   r*   ú<module>rü      sñ  ððð ð ð& #Ð "Ð "Ð "Ð "Ð "à 	€	€	€	Ø €€€Ø Ð Ð Ð Ð Ð Ø !Ð !Ð !Ð !Ð !Ð !Ø Ð Ð Ð Ð Ð Ø :Ð :Ð :Ð :Ð :Ð :Ð :Ð :Ð :Ð :Ð :Ð :à 5Ð 5Ð 5Ð 5Ð 5Ð 5Ø (Ð (Ð (Ð (Ð (Ð (àð )Ø(Ð(Ð(Ð(Ð(Ð(àˆÔ€ØÐ4Ô5Ð à'€	Ð 'Ð 'Ð 'Ñ 'Ø!#Ð Ð #Ð #Ð #Ñ #Ø "Ð Ð "Ð "Ð "Ñ "à&Ð Ð &Ð &Ð &Ñ &ð %'Ð Ð &Ð &Ð &Ñ &Ø%*Ð Ð *Ð *Ð *Ñ *Ø!*Ð Ð *Ð *Ð *Ñ *Ø *Ð Ð *Ð *Ð *Ñ *ðvð vð vð vð vˆHñ vô vð vð2 €�$ÐÑÔðFð Fð Fð Fð Fñ Fô Fñ ÔðFð(vð vð vð vð@kð kð kð kð
5ð 5ð 5ð 5ð
qð qð qð qð
"ð "ð "ð "ð "ñ "ô "ð "ð2^6ð ^6ð ^6ð ^6ð ^6ñ ^6ô ^6ð ^6ðB_)ð _)ð _)ð _)ð _)ñ _)ô _)ð _)ðDð ð €€€r,   