§
    dŠtj0;  ã                  ó,  — 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j$        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/dS )"é    )Ú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	<   dS )
Ú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*   © ó    úM/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/filelock/_lease.pyr#   r#   !   sG   € € € € € € à@Ð@à€N€N�NØ€J€J�JØÐÐÑØ €EÐ Ð Ð Ñ Ð Ð r1   r#   c                  ó(   — e Zd ZU dZded<   ded<   dS )Ú
_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ÐZà€N€N�NØ€K€K�K€K€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<   dS )	Ú_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   sK   € € € € € € àXÐXà€EÐÐÐÑØ)-€JÐ-Ð-Ð-Ñ-Ø#'€IÐ'Ð'Ð'Ñ'Ð'Ð'r1   r8   c                  ó   — e Zd ZdZdd„ZdS )Ú_LeaseClaimHolderz,Holds the claim its owning context acquired.ÚreturnÚNonec                ó,   — t          ¦   «         | _        d S ©N)r8   Úclaim©Úselfs    r2   Ú__init__z_LeaseClaimHolder.__init__B   s   € Ý ‘]”]ˆŒ
ˆ
ˆ
r1   N©r?   r@   )r+   r,   r-   r.   rF   r0   r1   r2   r>   r>   <   s.   € € € € € Ø6Ð6ð
#ð #ð #ð #ð #ð #r1   r>   c                  ó   — e Zd ZdZdS )Ú_ThreadLocalLeaseClaimHolderz:A thread local version of the ``_LeaseClaimHolder`` class.N)r+   r,   r-   r.   r0   r1   r2   rI   rI   F   s   € € € € € ØDÐDÐDÐDr1   rI   c                  ó  ‡ — 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dAˆ fd%„Zd@ˆ fd&„ZdBd(„ZdCd/„Zd@d0„ZdDd3„ZdEd5„ZdFd:„Zˆ xZS )GÚ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_compromiser%   ústr | os.PathLike[str]rQ   ÚfloatrR   úfloat | NonerS   ú(Callable[[LeaseCompromise], None] | NoneÚkwargsúUnpack[LockOptions]r?   r@   c               óL  •— |dk    rd|›�}t          |¦  «        ‚|€|dz  }d|cxk     r|k     sn d|›�}t          |¦  «        ‚ t          ¦   «         j        |fi |¤Ž || _        || _        || _         |                      ¦   «         rt          nt          ¦   «         | _	        dS )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ÚsuperrF   Ú_lease_durationÚ_heartbeat_intervalÚ_on_compromiseÚis_thread_localrI   r>   Ú_claims)rE   r%   rQ   rR   rS   rX   ÚmsgÚ	__class__s          €r2   rF   zSoftFileLease.__init__o   sÝ   ø€ ð. ˜QÒÐØL¸.ÐLÐLˆCÝ˜S‘/”/Ð!ØÐ%Ø!/°!Ñ!3ÐØÐ%Ð6Ð6Ò6Ð6¨Ò6Ð6Ð6Ð6ØmÐWiÐmÐmˆCÝ˜S‘/”/Ð!Ø�‰ŒÔ˜Ð-Ð- fÐ-Ð-Ð-Ø-ˆÔØ#5ˆÔ Ø+ˆÔð Z¨D×,@Ò,@Ñ,BÔ,BÐYÕ(Ð(ÕHYñ+ô +ˆŒˆˆr1   r8   c                ó   — | j         j        S rB   )ra   rC   rD   s    r2   Ú_claimzSoftFileLease._claim˜   s   € àŒ|Ô!Ð!r1   c                ó   — | j         S )zEThe staleness in seconds after which a contender may take this claim.)r]   rD   s    r2   rQ   zSoftFileLease.lease_durationœ   s   € ð Ô#Ð#r1   r9   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.

        )re   r&   rD   s    r2   r&   zSoftFileLease.token¡   s   € ð Œ{Ô Ð r1   r:   c                ó   — | j         j        S )z•
        The loss of claim the heartbeat observed.

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

        )re   r;   rD   s    r2   r;   zSoftFileLease.compromise«   s   € ð Œ{Ô%Ð%r1   c                ó4  •— | j         }|                      ¦   «          t          j        d¦  «        x|_        }d |_        t          ¦   «                              ¦   «          | j        j	        x}�)| j        j
        x}	 �|                      ||||¦  «         d S d S d S )Né   )re   Ú_stop_heartbeatÚsecretsÚ	token_hexr&   r;   r\   Ú_acquireÚ_contextÚlock_file_fdÚlock_file_fd_identityÚ_start_heartbeat)rE   rC   r&   ÚfdÚidentityrc   s        €r2   rn   zSoftFileLease._acquireµ   s¬   ø€ Ø”ˆØ×ÒÑÔÐÝ%Ô/°Ñ3Ô3Ð3ˆŒ�eØˆÔÝ‰Œ×ÒÑÔÐð ”-Ô,Ð,ˆBÐ9ØœÔ;Ð;ˆHØð?ð ×!Ò! %¨¨X°uÑ=Ô=Ð=Ð=Ð=ð :Ð9ð ?ð ?r1   c                óˆ   •— |                       ¦   «          d | j        _        t          ¦   «                              ¦   «          d S rB   )rk   re   r&   r\   Ú_release©rE   rc   s    €r2   rv   zSoftFileLease._releaseÂ   s;   ø€ Ø×ÒÑÔÐØ ˆŒÔÝ‰Œ×ÒÑÔÐÐÐr1   r   c                óŒ   •— t          ¦   «                              ¦   «                              | j        j        | j        ¬¦  «        S )N)r&   rQ   )r\   Ú_published_recordÚ_replacere   r&   r]   rw   s    €r2   ry   zSoftFileLease._published_recordÇ   s5   ø€ Ý‰wŒw×(Ò(Ñ*Ô*×3Ò3¸$¼+Ô:KÐ\`Ô\pÐ3ÑqÔqÐqr1   c                ó\  •— |                       ¦   «         x}€"t          ¦   «                              ¦   «          d S |\  }}}|j        dk    rd S |j        | j        k    r)| j        › d|j        ›d| j        ›d�}t          |¦  «        ‚t          t          ¦  «        5  t          |j        |j        |j        ¦  «        r$t          | j        ||¦  «         	 d d d ¦  «         d S t          j        ¦   «         |z
  | j        k    rt          | j        ||¦  «         d d d ¦  «         d S # 1 swxY w Y   d S )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_peerr\   Ú_try_break_stale_lockÚmoderQ   r]   r%   r   r   ÚOSErrorr   ÚpidÚhostnameÚstartr   Útime)rE   ÚpeerÚownerÚmtimeÚinorb   rc   s         €r2   r}   z#SoftFileLease._try_break_stale_lockÊ   s³  ø€ Ø—O’OÑ%Ô%Ð%ˆDÐ.õ
 ‰GŒG×)Ò)Ñ+Ô+Ð+ØˆFØ Ñˆˆu�cð Œ:˜Ò Ð ØˆFØÔ 4Ô#7Ò7Ð7à”>ð fð f°UÔ5Ið fð fØÔ'ðfð fð fð õ (¨Ñ,Ô,Ð,õ •gÑÔð 	<ð 	<õ ˜eœi¨¬¸¼ÑEÔEð Ý ¤°°sÑ;Ô;Ð;Øð	<ð 	<ð 	<ñ 	<ô 	<ð 	<ð 	<ð 	<õ Œy‰{Œ{˜UÑ" dÔ&:Ò:Ð:Ý ¤°°sÑ;Ô;Ð;ð	<ð 	<ð 	<ñ 	<ô 	<ð 	<ð 	<ð 	<ð 	<ð 	<ð 	<ð 	<øøøð 	<ð 	<ð 	<ð 	<ð 	<ð 	<s   Â8D!Ã5D!Ä!D%Ä(D%ú%tuple[OwnerRecord, float, int] | Nonec                óà   — t          t          t          ¦  «        5  t          | j        ¦  «        \  }}}t          |¦  «        x}�|||fcd d d ¦  «         S 	 d d d ¦  «         n# 1 swxY w Y   d S rB   )r   r   r[   r   r%   r   )rE   Úcontentr†   r‡   r…   s        r2   r|   zSoftFileLease._read_peerè   sÌ   € Ý•g�zÑ*Ô*ð 	)ð 	)Ý"1°$´.Ñ"AÔ"AÑˆG�U˜CÝ% gÑ.Ô.Ð.�Ð;Ø˜e SÐ(ð	)ð 	)ð 	)ð 	)ñ 	)ô 	)ð 	)ð 	)à;ð	)ð 	)ð 	)ñ 	)ô 	)ð 	)ð 	)ð 	)ð 	)ð 	)ð 	)øøøð 	)ð 	)ð 	)ð 	)ð ˆts   ›.A#Á#A'Á*A'rC   rs   Úintrt   útuple[int, int]r&   c                óÖ   — t          ¦   «         }t          | j        |||||fdt          j        ¦   «         › �d¬¦  «        }t          ||¦  «        |_        |                     ¦   «          d S )Nzfilelock-lease-T)ÚtargetÚargsÚnameÚdaemon)r   r   Ú_refresh_until_stoppedÚosÚgetpidr4   r<   r‚   )rE   rC   rs   rt   r&   r6   r5   s          r2   rr   zSoftFileLease._start_heartbeatï   sm   € õ ‰wŒwˆÝØÔ.Ø˜˜X u¨dÐ3Ø0¥2¤9¡;¤;Ð0Ð0Øð	
ñ 
ô 
ˆõ % V¨TÑ2Ô2ˆŒØ�Š‰Œˆˆˆr1   c                óô   — | j         }|j        x}€d S |j                             ¦   «          d |_        |j        j        �7|j        t          ¦   «         ur$|j                             | j        ¬¦  «         d S d S d S )N)Útimeout)	re   r<   r6   Úsetr5   Úidentr   Újoinr^   )rE   rC   r<   s      r2   rk   zSoftFileLease._stop_heartbeatÿ   sˆ   € Ø”ˆØœÐ(ˆIÐ1ØˆFØŒ×ÒÑÔÐØˆŒð ÔÔ!Ð-°)Ô2BÍ.ÑJZÔJZÐ2ZÐ2ZØÔ×!Ò!¨$Ô*BÐ!ÑCÔCÐCÐCÐCð .Ð-Ð2ZÐ2Zr1   r6   r   c                ó”  — t          j        ¦   «         }|                     | j        ¦  «        sš|                      ||||¦  «        \  }}|dk    rd S |dk    rt          j        ¦   «         }nAt          j        ¦   «         |z
  | j        | j        z
  k    r|                      |d||¦  «         d S |                     | j        ¦  «        ¯˜d S d S )Nr   r   r   )rƒ   Ú	monotonicÚwaitr^   Ú_refresh_claimr]   Ú_report_compromise)	rE   rC   rs   rt   r&   r6   Úlast_successÚoutcomer*   s	            r2   r’   z$SoftFileLease._refresh_until_stopped  sÝ   € õ ”~Ñ'Ô'ˆØ—)’)˜DÔ4Ñ5Ô5ð 	Ø!×0Ò0°¸¸HÀeÑLÔL‰NˆG�UØ˜&Ò Ð Ø�Ø˜$ŠˆÝ#œ~Ñ/Ô/��Ý”Ñ!Ô! LÑ0°DÔ4HÈ4ÔKcÑ4cÒcÐcØ×'Ò'¨Ð/?ÀÈÑNÔNÐNØ�ð —)’)˜DÔ4Ñ5Ô5ð 	ð 	ð 	ð 	ð 	r1   ú&tuple[_RefreshOutcome, OSError | None]c                ó†  — 	 t          j        | j        ¦  «        }nF# t          $ r#}|                      |d||¦  «         Y d }~dS d }~wt
          $ r}d|fcY d }~S d }~ww xY w|j        |j        f|k    r|                      |dd |¦  «         dS 	 t          | j        |¬¦  «         n# t
          $ r}d|fcY d }~S d }~ww xY wdS )Nr   )r   Nr    r   )rs   )r   N)	r“   Úlstatr%   ÚFileNotFoundErrorrž   r   Úst_devÚst_inor   )rE   rC   rs   rt   r&   Ústr*   s          r2   r�   zSoftFileLease._refresh_claim#  s!  € ð	&Ý”˜$œ.Ñ)Ô)ˆBˆBøÝ ð 	 ð 	 ð 	 Ø×#Ò# EÐ+;¸UÀEÑJÔJÐJØ�<�<�<�<�<øøøøÝð 	&ð 	&ð 	&Ø Ð%Ð%Ð%Ð%Ð%Ð%Ð%øøøøð	&øøøð ŒI�r”yÐ! XÒ-Ð-Ø×#Ò# E¨?¸DÀ%ÑHÔHÐHØ�<ð	&Ý�$”. RÐ(Ñ(Ô(Ð(Ð(øÝð 	&ð 	&ð 	&Ø Ð%Ð%Ð%Ð%Ð%Ð%Ð%øøøøð	&øøøàˆzsD   ‚ œ
A¦AÁAÁAÁAÁAÂB& Â&
B>Â0B9Â3B>Â9B>r(   r'   r*   r)   c                ó†   — t          | j        |||¬¦  «        |_        | j        �|                      |j        ¦  «         d S d S )N)r%   r&   r(   r*   )r#   r%   r;   r_   )rE   rC   r(   r*   r&   s        r2   rž   z SoftFileLease._report_compromise;  sO   € õ +°T´^È5ÐY_ÐglÐmÑmÔmˆÔØÔÐ*Ø×Ò Ô 0Ñ1Ô1Ð1Ð1Ð1ð +Ð*r1   )r%   rT   rQ   rU   rR   rV   rS   rW   rX   rY   r?   r@   )r?   r8   )r?   rU   )r?   r9   )r?   r:   rG   )r?   r   )r?   rˆ   )
rC   r8   rs   r‹   rt   rŒ   r&   r$   r?   r@   )rC   r8   rs   r‹   rt   rŒ   r&   r$   r6   r   r?   r@   )
rC   r8   rs   r‹   rt   rŒ   r&   r$   r?   r¡   )
rC   r8   r(   r'   r*   r)   r&   r$   r?   r@   )r+   r,   r-   r.   rM   r/   rO   rP   rF   Úpropertyre   rQ   r&   r;   rn   rv   ry   r}   r|   rr   rk   r’   r�   rž   Ú__classcell__)rc   s   @r2   rK   rK   J   s  ø€ € € € € € ðð ð< %€KÐ$Ð$Ð$Ñ$ð !&ÐÐ%Ð%Ð%Ñ%Ø(RÐ ÐRÐRÐRÑRð !%Ø+/ØBFð'ð 'ð 'ð 'ð 'ð 'ð 'ð 'ðR ð"ð "ð "ñ „Xð"ð ð$ð $ð $ñ „Xð$ð ð!ð !ð !ñ „Xð!ð ð&ð &ð &ñ „Xð&ð>ð >ð >ð >ð >ð >ðð ð ð ð ð ð
rð rð rð rð rð rð<ð <ð <ð <ð <ð <ð<ð ð ð ðð ð ð ð 
Dð 
Dð 
Dð 
Dðð ð ð ð0ð ð ð ð02ð 2ð 2ð 2ð 2ð 2ð 2ð 2r1   rK   )r'   r#   rK   )0Ú
__future__r   r“   rl   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Ð MÐ MÐ MÐ MÐ MÐ MÐ MÐ MÐ MÐ MØ "Ð "Ð "Ð "Ð "Ð "Ø )Ð )Ð )Ð )Ð )Ð )Ð )Ð )àð 	-Ø€J€J€JØ(Ð(Ð(Ð(Ð(Ð(à!Ð!Ð!Ð!Ð!Ð!à
Ô˜7Ò"Ð"Ø!Ð!Ð!Ð!Ð!Ð!Ð!à,Ð,Ð,Ð,Ð,Ð,àÐNÔOÐ àÐ3Ô4€ð €�$ÐÑÔð!ð !ð !ð !ð !ñ !ô !ñ Ôð!ð €�$ÐÑÔðð ð ð ð ñ ô ñ Ôðð ð(ð (ð (ð (ð (ñ (ô (ñ „ð(ð#ð #ð #ð #ð #ñ #ô #ð #ðEð Eð Eð Eð EÐ#4°eñ Eô Eð Eð}2ð }2ð }2ð }2ð }2Ð&ñ }2ô }2ð }2ð@ð ð €€€r1   