Ë
    ­Ó^jÓ8  ã                  óä  — d dl mZ d dlZd dlZd dl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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mZ er,d dlZd dl m!Z! ddl"m#Z# ejH                  dk\  rd dlm%Z% nd dl&m%Z% ed   Z'ed   Z( ed¬«       G d„ d«      «       Z) ed¬«       G d„ d«      «       Z*e G d„ d«      «       Z+ G d„ d«      Z, G d„ de,e«      Z- G d„ d e«      Z.g d!¢Z/y)"é    )ÚannotationsN)Úsuppress)Ú	dataclass)ÚEventÚThreadÚcurrent_threadÚlocal)ÚTYPE_CHECKINGÚLiteralé   )ÚLeaseSettingsMismatch)Úowner_is_stale)ÚMarkerSoftFileLockÚ	OwnerModeÚOwnerRecordÚparse_marker)Ú_read_lock_file)Úbreak_lock_fileÚtouch)ÚCallable)ÚLockOptions)é   é   )ÚUnpack)úmarker-missingúowner-changedúrefresh-failed)ÚokÚlostÚ	transientT)Úfrozenc                  ó>   — e Zd ZU dZded<   ded<   ded<   dZded	<   y)
ÚLeaseCompromisez6Why a held lease stopped being this process's to hold.ÚstrÚ	lock_fileÚtokenÚCompromiseReasonÚreasonNúOSError | NoneÚerror)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú__annotations__r*   © ó    úZ/var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/filelock/_lease.pyr#   r#   !   s   … á@àƒNØƒJØÓØ €Eˆ>Ô r1   r#   c                  ó&   — e Zd ZU dZded<   ded<   y)Ú
_HeartbeatzPA running heartbeat and the event that stops it, which only ever exist together.r   Úthreadr   ÚstopN)r+   r,   r-   r.   r/   r0   r1   r2   r4   r4   +   s   … áZàƒNØ
„Kr1   r4   c                  ó<   — e Zd ZU dZdZded<   dZded<   dZded<   y)	Ú_LeaseClaimzNThe state of one claim: its token, its heartbeat, and how that claim was lost.Nú
str | Noner&   úLeaseCompromise | NoneÚ
compromisez_Heartbeat | NoneÚ	heartbeat)r+   r,   r-   r.   r&   r/   r;   r<   r0   r1   r2   r8   r8   3   s%   … áXà€Eˆ:ÓØ)-€JÐ&Ó-Ø#'€IÐ Ô'r1   r8   c                  ó   — e Zd ZdZdd„Zy)Ú_LeaseClaimHolderz,Holds the claim its owning context acquired.c                ó"   — t        «       | _        y ©N)r8   Úclaim©Úselfs    r2   Ú__init__z_LeaseClaimHolder.__init__B   s   € Ü “]ˆ�
r1   N©ÚreturnÚNone)r+   r,   r-   r.   rD   r0   r1   r2   r>   r>   <   s
   „ Ù6ô
#r1   r>   c                  ó   — e Zd ZdZy)Ú_ThreadLocalLeaseClaimHolderz:A thread local version of the ``_LeaseClaimHolder`` class.N)r+   r,   r-   r.   r0   r1   r2   rI   rI   F   s   „ ÚDr1   rI   c                  óX  ‡ — e Zd ZU dZdZded<   dZded<   dZd	ed
<   ddddœ	 	 	 	 	 	 	 	 	 	 	 dˆ fd„Ze	dd„«       Z
e	dd„«       Ze	d d„«       Ze	d!d„«       Zd"ˆ fd„Zd"ˆ fd„Zd#ˆ fd„Zd"ˆ fd„Zd$d„Zd%d„Zd"d„Z	 	 	 	 	 	 	 	 	 	 	 	 d&d„Z	 	 	 	 	 	 	 	 	 	 d'd„Z	 	 	 	 	 	 	 	 	 	 d(d„Zˆ xZS ))ÚSoftFileLeaseaÝ  
    Existence lock whose claim expires, so a peer may take it while the previous holder still runs.

    A lease trades mutual exclusion for progress. The holder publishes a claim and refreshes it every
    ``heartbeat_interval`` seconds; a contender takes the marker once it is ``lease_duration`` seconds stale. Nothing
    stops the expired holder: it keeps running, and it keeps using whatever the lock protects. Treat the lease as a hint
    about who *should* be working, not as a guarantee that only one worker is.

    To make a protected resource reject a superseded holder, that resource must be linearizable and must fence on a
    monotonic generation it controls. :attr:`token` names a claim; it does not fence one. Where overlap is unacceptable,
    use :class:`StrictSoftFileLock <filelock.StrictSoftFileLock>` instead.

    Every contender for a path must agree on ``lease_duration``. A contender that finds a claim published under a
    different duration raises :class:`LeaseSettingsMismatch <filelock.LeaseSettingsMismatch>` rather than apply its own
    expiry to a peer that never agreed to it.

    Expiry reclaims less on Windows, which refuses to rename or delete a file another process holds open. A peer there
    takes an expired claim only once the previous holder's process exits and its handle closes; a holder that lives on
    but stops refreshing keeps the marker. Unix reclaims the marker either way.

    ``on_compromise`` fires from the heartbeat thread when a refresh fails, or when the marker vanishes or names another
    owner. The holder should stop touching the protected resource when it runs. Because it runs on that thread, a
    ``release()`` inside it only takes effect when the lease was built with ``thread_local=False``; the default
    thread-local context hides the claim from every thread but the one that acquired it, so the release does nothing.
    Signal the acquiring thread instead when the context stays thread-local.

    .. versionadded:: 3.30.0

    Úleaser   Ú_owner_modeFÚboolÚ_lifetime_supportedz(lease_duration sets when a lease expiresr$   Ú_lifetime_unsupported_reasong      >@N)Úlease_durationÚheartbeat_intervalÚon_compromisec               ó"  •— |dk  rd|›�}t        |«      ‚|€|dz  }d|cxk  r|k  sn d|›�}t        |«      ‚t        ‰| �  |fi |¤Ž || _        || _        || _         | j                  «       rt        «       | _	        yt        «       | _	        y)a  
        Create a lease.

        :param lease_duration: seconds of marker staleness after which a contender may take the claim. Every contender
            for the path must pass the same value.
        :param heartbeat_interval: seconds between refreshes. Defaults to a third of ``lease_duration``, leaving room
            for two missed refreshes before a peer may take the claim. Must be shorter than ``lease_duration``.
        :param on_compromise: called from the heartbeat thread with a :class:`LeaseCompromise` when the claim is lost.
        :param kwargs: every other :class:`BaseFileLock <filelock.BaseFileLock>` option, ``timeout`` and ``mode`` among
            them. The metaclass passes them all by keyword, and taking them here lets
            :class:`AsyncSoftFileLease <filelock.AsyncSoftFileLease>` add the async plumbing a fixed signature would
            hide.

        r   z%lease_duration must be positive, got Nr   zBheartbeat_interval must be positive and below lease_duration, got )
Ú
ValueErrorÚsuperrD   Ú_lease_durationÚ_heartbeat_intervalÚ_on_compromiseÚis_thread_localrI   r>   Ú_claims)rC   r%   rQ   rR   rS   ÚkwargsÚmsgÚ	__class__s          €r2   rD   zSoftFileLease.__init__o   s®   ø€ ð. ˜QÒØ9¸.Ð9KÐLˆCÜ˜S“/Ð!ØÐ%Ø!/°!Ñ!3ÐØÐ%Ô6¨Ô6ØVÐWiÐVlÐmˆCÜ˜S“/Ð!Ü‰Ñ˜Ñ- fÒ-Ø-ˆÔØ#5ˆÔ Ø+ˆÔð Z¨D×,@Ñ,@Ô,BÔ(ó+ˆ�ÜHYó+ˆ�r1   c                ó.   — | j                   j                  S r@   )r[   rA   rB   s    r2   Ú_claimzSoftFileLease._claim˜   s   € à�|‰|×!Ñ!Ð!r1   c                ó   — | j                   S )zEThe staleness in seconds after which a contender may take this claim.)rW   rB   s    r2   rQ   zSoftFileLease.lease_durationœ   s   € ð ×#Ñ#Ð#r1   c                ó.   — | j                   j                  S )z½
        The token naming the claim this process published.

        :returns: the token while the lease is held, ``None`` otherwise. It identifies a claim; it does not fence one.

        )r`   r&   rB   s    r2   r&   zSoftFileLease.token¡   s   € ð �{‰{× Ñ Ð r1   c                ó.   — | j                   j                  S )z•
        The loss of claim the heartbeat observed.

        :returns: the :class:`LeaseCompromise`, or ``None`` while the claim still holds

        )r`   r;   rB   s    r2   r;   zSoftFileLease.compromise«   s   € ð �{‰{×%Ñ%Ð%r1   c                ó.  •— | j                   }| j                  «        t        j                  d«      x|_        }d |_        t        ‰| �  «        | j                  j                  x}�/| j                  j                  x}	 �| j                  ||||«       y y y )Né   )r`   Ú_stop_heartbeatÚsecretsÚ	token_hexr&   r;   rV   Ú_acquireÚ_contextÚlock_file_fdÚlock_file_fd_identityÚ_start_heartbeat)rC   rA   r&   ÚfdÚidentityr^   s        €r2   ri   zSoftFileLease._acquireµ   s‘   ø€ Ø—‘ˆØ×ÑÔÜ%×/Ñ/°Ó3Ð3ˆŒ�eØˆÔÜ‰ÑÔð —-‘-×,Ñ,Ð,ˆBÐ9ØŸ™×;Ñ;Ð;ˆHØð?ð ×!Ñ! %¨¨X°uÕ=ð?Ð9r1   c                ód   •— | j                  «        d | j                  _        t        ‰| �  «        y r@   )rf   r`   r&   rV   Ú_release©rC   r^   s    €r2   rq   zSoftFileLease._releaseÂ   s&   ø€ Ø×ÑÔØ ˆ�‰ÔÜ‰ÑÕr1   c                ó~   •— t         ‰| �  «       j                  | j                  j                  | j
                  ¬«      S )N)r&   rQ   )rV   Ú_published_recordÚ_replacer`   r&   rW   rr   s    €r2   rt   zSoftFileLease._published_recordÇ   s2   ø€ Ü‰wÑ(Ó*×3Ñ3¸$¿+¹+×:KÑ:KÐ\`×\pÑ\pÐ3ÓqÐqr1   c                ód  •— | j                  «       x}€t        ‰| �	  «        y |\  }}}|j                  dk7  ry |j                  | j
                  k7  r4| j                  › d|j                  ›d| j
                  ›d�}t        |«      ‚t        t        «      5  t        |j                  |j                  |j                  «      r!t        | j                  ||«       	 d d d «       y t        j                  «       |z
  | j
                  k\  rt        | j                  ||«       d d d «       y # 1 sw Y   y xY w)NrL   z holds a lease of z s but this contender configured z:s; every contender for a path must agree on lease_duration)Ú
_read_peerrV   Ú_try_break_stale_lockÚmoderQ   rW   r%   r   r   ÚOSErrorr   ÚpidÚhostnameÚstartr   Útime)rC   ÚpeerÚownerÚmtimeÚinor]   r^   s         €r2   rx   z#SoftFileLease._try_break_stale_lockÊ   s  ø€ Ø—O‘OÓ%Ð%ˆDÐ.ô
 ‰GÑ)Ô+ØØ Ñˆˆu�cð �:‰:˜Ò ØØ×Ñ 4×#7Ñ#7Ò7à—>‘>Ð"Ð"4°U×5IÑ5IÐ4LÐLlØ×'Ñ'Ð*Ð*dðfð ô (¨Ó,Ð,ô ”gÓñ 	<ô ˜eŸi™i¨¯©¸¿¹ÔEÜ §¡°°sÔ;Ø÷	<ð 	<ô �y‰y‹{˜UÑ" d×&:Ñ&:Ò:Ü §¡°°sÔ;÷	<÷ 	<ñ 	<ús   ÂAD&Ã";D&Ä&D/c                óÀ   — t        t        t        «      5  t        | j                  «      \  }}}t        |«      x}�|||fcd d d «       S 	 d d d «       y # 1 sw Y   y xY wr@   )r   rz   rU   r   r%   r   )rC   Úcontentr�   r‚   r€   s        r2   rw   zSoftFileLease._read_peerè   sb   € Ü”gœzÓ*ñ 	)Ü"1°$·.±.Ó"AÑˆG�U˜CÜ% gÓ.Ð.�Ð;Ø˜e SÐ(÷	)ñ 	)à;÷	)ð ÷		)ð ús   •+AÁAc                óÀ   — t        «       }t        | j                  |||||fdt        j                  «       › �d¬«      }t        ||«      |_        |j                  «        y )Nzfilelock-lease-T)ÚtargetÚargsÚnameÚdaemon)r   r   Ú_refresh_until_stoppedÚosÚgetpidr4   r<   r}   )rC   rA   rn   ro   r&   r6   r5   s          r2   rm   zSoftFileLease._start_heartbeatï   sX   € ô ‹wˆÜØ×.Ñ.Ø˜˜X u¨dÐ3Ø"¤2§9¡9£; -Ð0Øô	
ˆô % V¨TÓ2ˆŒØ�‰�r1   c                óö   — | j                   }|j                  x}€y |j                  j                  «        d |_        |j                  t        «       ur'|j                  j                  | j                  ¬«       y y )N)Útimeout)r`   r<   r6   Úsetr5   r   ÚjoinrX   )rC   rA   r<   s      r2   rf   zSoftFileLease._stop_heartbeatü   sg   € Ø—‘ˆØŸ™Ð(ˆIÐ1ØØ�‰×ÑÔØˆŒà×Ñ¤>Ó#3Ñ3Ø×Ñ×!Ñ!¨$×*BÑ*BÐ!ÕCð 4r1   c                ó–  — t        j                  «       }|j                  | j                  «      sš| j	                  ||||«      \  }}|dk(  ry |dk(  rt        j                  «       }nFt        j                  «       |z
  | j
                  | j                  z
  k\  r| j                  |d||«       y |j                  | j                  «      sŒ™y y )Nr   r   r   )r~   Ú	monotonicÚwaitrX   Ú_refresh_claimrW   Ú_report_compromise)	rC   rA   rn   ro   r&   r6   Úlast_successÚoutcomer*   s	            r2   rŠ   z$SoftFileLease._refresh_until_stopped  s«   € ô —~‘~Ó'ˆØ—)‘)˜D×4Ñ4Ô5Ø!×0Ñ0°¸¸HÀeÓL‰NˆG�UØ˜&Ò ØØ˜$ŠÜ#Ÿ~™~Ó/‘Ü—‘Ó! LÑ0°D×4HÑ4HÈ4×KcÑKcÑ4cÒcØ×'Ñ'¨Ð/?ÀÈÔNØð —)‘)˜D×4Ñ4×5r1   c                ó†  — 	 t        j                  | j                  «      }|j                  |j                  f|k7  r| j	                  |dd |«       y	 t        | j                  |¬«       y# t        $ r}| j	                  |d||«       Y d }~yd }~wt
        $ r}d|fcY d }~S d }~ww xY w# t
        $ r}d|fcY d }~S d }~ww xY w)Nr   )r   Nr    r   )rn   )r   N)	r‹   Úlstatr%   ÚFileNotFoundErrorr•   rz   Úst_devÚst_inor   )rC   rA   rn   ro   r&   Ústr*   s          r2   r”   zSoftFileLease._refresh_claim  s¹   € ð	&Ü—‘˜$Ÿ.™.Ó)ˆBð �I‰I�r—y‘yÐ! XÒ-Ø×#Ñ# E¨?¸DÀ%ÔHØð	&Ü�$—.‘. RÕ(ð øô !ò 	 Ø×#Ñ# EÐ+;¸UÀEÔJÜûÜò 	&Ø Ð%Õ%ûð	&ûô ò 	&Ø Ð%Õ%ûð	&úsG   ‚A* ÁB) Á*	B&Á3BÂB&ÂB!ÂB&Â!B&Â)	C Â2B;Â5C Â;C c                ó�   — t        | j                  |||¬«      |_        | j                  �| j                  |j                  «       y y )N)r%   r&   r(   r*   )r#   r%   r;   rY   )rC   rA   r(   r*   r&   s        r2   r•   z SoftFileLease._report_compromise6  sB   € ô +°T·^±^È5ÐY_ÐglÔmˆÔØ×ÑÐ*Ø×Ñ × 0Ñ 0Õ1ð +r1   )r%   zstr | os.PathLike[str]rQ   ÚfloatrR   zfloat | NonerS   z(Callable[[LeaseCompromise], None] | Noner\   zUnpack[LockOptions]rF   rG   )rF   r8   )rF   rŸ   )rF   r9   )rF   r:   rE   )rF   r   )rF   z%tuple[OwnerRecord, float, int] | None)
rA   r8   rn   Úintro   útuple[int, int]r&   r$   rF   rG   )rA   r8   rn   r    ro   r¡   r&   r$   r6   r   rF   rG   )
rA   r8   rn   r    ro   r¡   r&   r$   rF   z&tuple[_RefreshOutcome, OSError | None])
rA   r8   r(   r'   r*   r)   r&   r$   rF   rG   )r+   r,   r-   r.   rM   r/   rO   rP   rD   Úpropertyr`   rQ   r&   r;   ri   rq   rt   rx   rw   rm   rf   rŠ   r”   r•   Ú__classcell__)r^   s   @r2   rK   rK   J   s–  ø… ñð< %€K�Ó$ð !&Ð˜Ó%Ø(RÐ  #ÓRð !%Ø+/ØBFñ'à)ð'ð ð	'ð
 )ð'ð @ð'ð &ð'ð 
õ'ðR ò"ó ð"ð ò$ó ð$ð ò!ó ð!ð ò&ó ð&õ>õõ
rõ<ó<óóDðàðð ðð "ð	ð
 ðð ðð 
óð0àðð ðð "ð	ð
 ðð 
0óð02àð2ð !ð2ð ð	2ð
 ð2ð 
÷2r1   rK   )r'   r#   rK   )0Ú
__future__r   r‹   rg   r~   Ú
contextlibr   Údataclassesr   Ú	threadingr   r   r   r	   Útypingr
   r   Ú_errorr   Ú	_identityr   Ú_markerr   r   r   r   Ú_softr   Ú_utilr   r   ÚsysÚcollections.abcr   Ú_apir   Úversion_infor   Útyping_extensionsr'   Ú_RefreshOutcomer#   r4   r8   r>   rI   rK   Ú__all__r0   r1   r2   ú<module>rµ      sð   ðÝ "ã 	Û Û Ý Ý !ß :Ó :ß )å )Ý %ß MÓ MÝ "ß )áÛÝ(å!à
×Ñ˜7Ò"Þ!å,àÐNÑOÐ àÐ3Ñ4€ñ �$Ô÷!ð !ó ð!ñ �$Ô÷ð ó ðð ÷(ð (ó ð(÷#ñ #ôEÐ#4°eô Eôx2Ð&ô x2òv�r1   