Ë
    °ëjC”  ã                  óR  — U d Z ddlmZ g d¢ZddlZddlZddlZddl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 dd	lmZ dd
lmZmZmZmZmZmZmZmZmZ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+ erddl,m-Z-m.Z. ddl#m/Z/  e«       Z0de1d<    ejd                  «       a3de1d<    G d„ de4«      Z5 G d„ de5¬«      Z6 G d„ dejn                  «      Z8d$d„Z9	 	 	 	 	 	 	 	 d%d„Z:e G d„ d«      «       Z;e G d „ d!«      «       Z<d&d"„Z= ej|                  e=«        ee6«       dd#gZ?y)'z]Cross-process and cross-host reader/writer lock over a generation log of immutable snapshots.é    )Úannotations)zfilelock._errorzfilelock._leasezfilelock._soft_rw._protocolzfilelock._soft_rw._storageÚmathN)ÚcontextmanagerÚsuppress)Ú	dataclass)Úisfinite)ÚTYPE_CHECKINGÚClassVarÚFinal)ÚWeakValueDictionary)ÚAcquireReturnProxyÚ_acquire_thread_lockÚ
_canonicalÚ_check_blockingÚ_check_timeout_maxÚ_ensure_current_processÚ_register_fork_classÚ_register_fork_objectÚ_resolve_read_write_timeoutÚ_secondsÚ_timeout_behavior)ÚTimeout)ÚLeaseCompromise)ÚGenerationLogÚLedgerÚModeÚParticipant)ÚOsFiles)ÚCallableÚ	Generator)ÚCompromiseReasonz2Final[WeakValueDictionary[int, SoftReadWriteLock]]Ú_ALL_INSTANCESúthreading.LockÚ_ALL_INSTANCES_LOCKc                  óv   ‡ — e Zd ZU ded<   ded<   ded<   	 ddddd	d
d	dœ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dˆ fd„Zˆ xZS )Ú_SoftRWMetaz+WeakValueDictionary[str, SoftReadWriteLock]Ú
_instanceszthreading.RLockÚ_instances_lockzset[str]Ú_instances_under_constructionTç      >@Nç      Ð?©ÚblockingÚis_singletonÚheartbeat_intervalÚstale_thresholdÚpoll_intervalÚon_compromisec          
     óÂ  •— t        «        t        |«       t        d|«      }|€i nd|i}	|st        ‰| �  ||f|||||dœ|	¤ŽS t        |«      }
| j                  5  | j                  j                  |
«      }|€¬|
| j                  v rd|›�}t        |«      ‚t        j                  «       }| j                  }|j                  |
«       	 t        ‰| �  ||f|||||dœ|	¤Ž}|j                  |
«       t        j                  «       |k7  rd}t        |«      ‚|| j                  |
<   n�t        |j                   d¬«      t        |d¬«      k7  s|j"                  |k7  r-d|j                   › d	|j"                  › d
|› d	|› �}t%        |«      ‚|�|j&                  |k7  rd|›�}t%        |«      ‚t)        |||«       |cd d d «       S # |j                  |
«       w xY w# 1 sw Y   y xY w)NÚtimeoutr2   )r-   r.   r/   r0   r1   z2Singleton lock construction is already active for zOLock construction cannot continue after fork; construct a new lock in the childF)Úany_negativez$Singleton lock created with timeout=z, blocking=z, cannot be changed to timeout=zCSingleton lock created with a different on_compromise callback for )r   r   r   ÚsuperÚ__call__r   r(   r'   Úgetr)   ÚRuntimeErrorÚosÚgetpidÚaddÚdiscardr   r4   r-   Ú
ValueErrorÚ_on_compromiseÚ_validate_intervals)ÚclsÚ	lock_filer4   r-   r.   r/   r0   r1   r2   ÚextraÚ
normalizedÚinstanceÚmsgÚconstruction_pidÚconstruction_registryÚ	__class__s                  €úd/home/oem/CyberBrain26-unified/dev-env/.venv/lib/python3.12/site-packages/filelock/_soft_rw/_sync.pyr7   z_SoftRWMeta.__call__7   s;  ø€ ô 	 Ô!ä˜Ô!Ü˜9 gÓ.ˆà#Ð+‘°/À=Ð1QˆÙÜ‘7Ñ#ØØð	ð "Ø)Ø#5Ø /Ø+ñ	ð ñ	ð 	ô   	Ó*ˆ
Ø× Ñ ñ +	Ø—~‘~×)Ñ)¨*Ó5ˆHØÐØ ×!BÑ!BÑBØNÈyÈmÐ\�CÜ& sÓ+Ð+Ü#%§9¡9£;Ð Ø(+×(IÑ(IÐ%Ø%×)Ñ)¨*Ô5ð>Ü$™wÑ/Ø!Øð	 ð "*Ø%1Ø+=Ø(7Ø&3ñ	 ð  ñ	 �Hð *×1Ñ1°*Ô=Ü—9‘9“;Ð"2Ò2Øk�CÜ& sÓ+Ð+Ø-5�—‘˜zÒ*ä! (×"2Ñ"2ÀÔGÜ$ W¸5ÔAòBà×$Ñ$¨Ò0ð ;¸8×;KÑ;KÐ:LÈKÐX`×XiÑXiÐWjð k5Ø5<°I¸[ÈÈ
ðTð ô ! “oÐ%ØÐ*¨x×/FÑ/FÈ-Ò/Wð \Ð\eÐ[hÐi�Ü  “oÐ%ä#Ð$6¸ÈÔWØ÷W+	ñ +	øð* *×1Ñ1°*Õ=ú÷++	ð +	ús&   ÁA-GÃ	F?Ã CGÆ?GÇGÇG©éÿÿÿÿ)rB   ústr | os.PathLike[str]r4   Úfloatr-   Úboolr.   rO   r/   rN   r0   úfloat | Noner1   rN   r2   ú(Callable[[LeaseCompromise], None] | NoneÚreturnÚSoftReadWriteLock)Ú__name__Ú
__module__Ú__qualname__Ú__annotations__r7   Ú__classcell__©rI   s   @rJ   r&   r&   2   s¢   ø… Ø;Ó;Ø$Ó$Ø#+Ó+ð
 ðKð
 Ø!Ø$(Ø(,Ø#ØBFñKà)ðKð ðKð
 ðKð ðKð "ðKð &ðKð ðKð @ðKð 
÷Kñ Kó    r&   c                  óJ  ‡ — e Zd ZU dZ e«       Zded<    ej                  «       Z	 e
«       Zded<   d(ˆ fd„Z	 d)dddd	d
d	dœ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d*d„Zed+d„«       Zed,d„«       Zed-d„«       Zed.d	dœd/d„«       Zed.d	dœd/d„«       Zd.d	dœd0d„Zd.d	dœd0d„Ze	 d)ddœ	 	 	 	 	 	 	 d1d„«       Zd+d„Zddœd2d„Z	 	 	 	 	 	 	 	 	 	 	 	 d3d„Zd4d„Zd5d„Zd6d„Zd7d„Zd	d	dœ	 	 	 	 	 	 	 	 	 	 	 d8d „Z d9d!„Z!	 	 	 	 	 	 	 	 	 	 	 	 d:d"„Z"d;d#„Z#	 	 	 	 	 	 	 	 	 	 d<d$„Z$d=d%„Z%d>d&„Z&d+d'„Z'ˆ xZ(S )?rS   a¹  
    Cross-process and cross-host reader/writer lock for shared filesystems.

    Use this class instead of :class:`~filelock.ReadWriteLock` when the lock file lives on a network filesystem (NFS,
    Lustre, HPC cluster shared storage). ``ReadWriteLock`` is backed by SQLite and cannot run on NFS because SQLite's
    ``fcntl`` locking is unreliable there.

    The lock's state is a log of immutable snapshots under ``foo.lock.rw/gen/<N>``, each naming the writer and the
    readers holding the lock at generation ``N``. Every acquire, release, and eviction publishes the next snapshot with
    one atomic no-replace hard link, so no transition can be left half done by a crash on any host. Each participant
    also keeps ``foo.lock.rw/holders/<token>``, a record whose nonce a daemon heartbeat thread rewrites every
    ``heartbeat_interval`` seconds. A contender evicts a member whose record has not changed for ``stale_threshold``
    seconds of the contender's own monotonic clock; no clock is ever compared across hosts, so skew between hosts or
    against the file server cannot make a live holder look dead.

    Writer acquire is writer-preferring: a writer enters the snapshot as soon as no live writer is named, which blocks
    any new reader, then waits for the named readers to leave. Writer starvation is impossible.

    An expired holder is not fenced by the lock: a process paused past ``stale_threshold`` resumes believing it holds
    the lock until its next heartbeat reports the loss through ``on_compromise``. :attr:`generation` is a monotonic
    fencing token for the protected resource: a store that rejects writes carrying a lower generation than the highest
    it has accepted refuses such a holder.

    Reentrancy, upgrade/downgrade rules, thread pinning, and singleton caching by canonical path match
    :class:`~filelock.ReadWriteLock`.

    Forking invalidates the inherited instance in the child so the child cannot double-own the lock with its parent;
    ``release()`` on that instance is a no-op, and the child must construct a new instance if it needs a lock.

    Trust boundary: protects against same-UID non-cooperating processes (one host or cross-host) and same-host
    different-UID users via ``0o600`` / ``0o700`` permissions. Does not protect against root compromise or multi-tenant
    mounts where hostile co-tenants share the UID.

    :param lock_file: path to the lock file; the protocol directory lives next to it as ``<lock_file>.rw``
    :param timeout: maximum wait time in seconds; ``-1`` means block indefinitely
    :param blocking: if ``False``, raise :class:`~filelock.Timeout` immediately on contention
    :param is_singleton: if ``True``, reuse existing instances for the same canonical path
    :param heartbeat_interval: seconds between heartbeat refreshes; default 30 s
    :param stale_threshold: seconds a holder record may stay unchanged before a contender evicts it; defaults to
        ``3 * heartbeat_interval``, matching etcd's ``LeaseKeepAlive`` convention
    :param poll_interval: seconds between acquire retries under contention; default 0.25 s
    :param on_compromise: called from the heartbeat thread with a :class:`~filelock.LeaseCompromise` when the hold is
        lost: a peer evicted it, or refreshes failed for long enough that a peer could have

    .. versionadded:: 3.27.0

    .. versionchanged:: 3.33.0

        The on-disk protocol is a generation log; earlier releases cannot share a lock path with this one.

    z5ClassVar[WeakValueDictionary[str, SoftReadWriteLock]]r'   zClassVar[set[str]]r)   c                ó¨   •— t        ‰| �  di |¤Ž t        «       | _        t	        j
                  «       | _        t        «       | _        t        | «       y)z<Give each lock subclass its own singleton registry and lock.N© )
r6   Ú__init_subclass__r   r'   Ú	threadingÚRLockr(   Úsetr)   r   )rA   ÚkwargsrI   s     €rJ   r^   z#SoftReadWriteLock.__init_subclass__¾   s>   ø€ ä‰Ñ!Ñ+ FÒ+Ü,Ó.ˆŒÜ'Ÿo™oÓ/ˆÔÜ,/«EˆÔ)Ü˜SÕ!rZ   Tr*   Nr+   r,   c               óð  — t        j                  «       | _        t        |||«      \  }}}t        j                  |«      | _        || _        || _        || _        || _	        || _
        t        | j
                  «      › d�| _        t        | j
                  «      | _        t        t         j"                  «      | _        t'        | j                  | j
                  | j                  «      | _        || _        t-        t/        j0                  «       t/        j0                  «       ¬«      | _        d | _        d | _        d| _        t:        5  | t<        t?        | «      <   d d d «       tA        | «       y # 1 sw Y   ŒxY w)Nz.rw©ÚinternalÚtransactionF)!r:   r;   Ú_creator_pidr@   ÚfspathrB   r4   r-   r/   r0   r1   r   Ú_rootr   Ú_filesr   ÚtimeÚ	monotonicÚ_ledgerr   Ú_logr?   Ú_Locksr_   ÚLockÚ_locksÚ_holdÚ_compromiseÚ_closedr$   r"   Úidr   )	ÚselfrB   r4   r-   r.   r/   r0   r1   r2   s	            rJ   Ú__init__zSoftReadWriteLock.__init__Æ   s!  € ô ŸI™I›KˆÔÜ=PØ °ó>
Ñ:Ð˜O¨]ô !Ÿi™i¨	Ó2ˆŒØ%ˆŒØ&ˆŒØ);ˆÔØ&5ˆÔØ$1ˆÔô # 4§>¡>Ó2Ð3°3Ð7ˆŒ
Ü˜dŸn™nÓ-ˆŒÜœdŸn™nÓ-ˆŒÜ! $§+¡+¨t¯~©~¸t¿z¹zÓJˆŒ	Ø+ˆÔÜ¤i§n¡nÓ&6ÄIÇNÁNÓDTÔUˆŒØ#'ˆŒ
Ø37ˆÔØ"ˆŒä ñ 	,Ø'+ŒNœ2˜d›8Ñ$÷	,ä˜dÕ#÷	,ð 	,ús   ÅE,Å,E5c                óš   — t        j                  «       at        «       | _        t        j
                  «       | _        t        «       | _        y ©N)	r_   rp   r$   r   r'   r`   r(   ra   r)   )rA   s    rJ   Ú_reset_class_after_forkz)SoftReadWriteLock._reset_class_after_forkî   s4   € ô (Ÿn™nÓ.ÐÜ,Ó.ˆŒÜ'Ÿo™oÓ/ˆÔÜ,/«EˆÕ)rZ   c                ó¶   — | j                   j                  5  | j                  €dn| j                  j                  j                  cddd«       S # 1 sw Y   yxY w)aF  
        The generation at which the current hold was granted, or ``None`` when no lock is held.

        Generations are monotonic across all participants and hosts, so this is a fencing token: pass it to the
        protected resource and have the resource reject any operation carrying a lower generation than the highest it
        has accepted. That refuses a holder that paused past ``stale_threshold``, was evicted, and resumed. Removing the
        ``<lock_file>.rw`` directory starts a new log whose generations begin again at 1.

        .. versionadded:: 3.33.0

        N)rq   re   rr   ÚparticipantÚ
generation©rv   s    rJ   r}   zSoftReadWriteLock.generationö   sH   € ð �[‰[×!Ñ!ñ 	UØŸ:™:Ð-‘4°4·:±:×3IÑ3I×3TÑ3T÷	U÷ 	Uò 	Uús   —.AÁAc                ór   — | j                   j                  5  | j                  cddd«       S # 1 sw Y   yxY w)a¾  
        How the current hold was lost, or ``None`` while it stands.

        Set by the heartbeat thread once a peer has evicted this holder or refreshes have failed for long enough that a
        peer could have. The holder should stop using the protected resource when it is set. Until the lost hold is
        released, acquiring on this instance raises :class:`RuntimeError` instead of joining it.

        .. versionadded:: 3.33.0

        N)rq   re   rs   r~   s    rJ   Ú
compromisezSoftReadWriteLock.compromise  s/   € ð �[‰[×!Ñ!ñ 	$Ø×#Ñ#÷	$÷ 	$ò 	$ús   —-­6©r-   c             #  ó†   K  — | j                  ||¬«       	 d–— | j                  «        y# | j                  «        w xY w­w)a   
        Context manager that acquires and releases a shared read lock.

        Falls back to instance defaults for *timeout* and *blocking* when ``None``.

        :param timeout: maximum wait time in seconds, or ``None`` to use the instance default
        :param blocking: if ``False``, raise :class:`~filelock.Timeout` immediately; ``None`` uses the instance default

        :raises RuntimeError: if a write lock is already held on this instance
        :raises Timeout: if the lock cannot be acquired within *timeout* seconds
        :raises TypeError: if *timeout* is a :class:`bool` or not a real number, or *blocking* is not a :class:`bool`
        :raises ValueError: if a blocking call gets a ``nan`` *timeout* or a negative one other than ``-1``

        r�   N)Úacquire_readÚrelease©rv   r4   r-   s      rJ   Ú	read_lockzSoftReadWriteLock.read_lock  s5   è ø€ ð  	×Ñ˜'¨HÐÔ5ð	Ûà�L‰L�NøˆD�L‰L�Nüó   ‚A—, ›A¬>¾Ac             #  ó†   K  — | j                  ||¬«       	 d–— | j                  «        y# | j                  «        w xY w­w)a"  
        Context manager that acquires and releases an exclusive write lock.

        Falls back to instance defaults for *timeout* and *blocking* when ``None``.

        :param timeout: maximum wait time in seconds, or ``None`` to use the instance default
        :param blocking: if ``False``, raise :class:`~filelock.Timeout` immediately; ``None`` uses the instance default

        :raises RuntimeError: if a read lock is already held, or a write lock is held by a different thread
        :raises Timeout: if the lock cannot be acquired within *timeout* seconds
        :raises TypeError: if *timeout* is a :class:`bool` or not a real number, or *blocking* is not a :class:`bool`
        :raises ValueError: if a blocking call gets a ``nan`` *timeout* or a negative one other than ``-1``

        r�   N)Úacquire_writer„   r…   s      rJ   Ú
write_lockzSoftReadWriteLock.write_lock+  s5   è ø€ ð  	×Ñ˜7¨XÐÔ6ð	Ûà�L‰L�NøˆD�L‰L�Nür‡   c               ó*   — | j                  d||¬«      S )uM  
        Acquire a shared read lock.

        If this instance already holds a read lock, the lock level is incremented (reentrant). Attempting to acquire a
        read lock while holding a write lock raises :class:`RuntimeError` (downgrade not allowed). On the 0â†’1
        transition the reader publishes its holder record, enters the next snapshot once no live writer is named, and
        starts a daemon heartbeat thread that rewrites the record's nonce every ``heartbeat_interval`` seconds so peers
        on other hosts do not evict it.

        :param timeout: maximum wait time in seconds, or ``None`` to use the instance default; ``-1`` means block
            indefinitely
        :param blocking: if ``False``, raise :class:`~filelock.Timeout` immediately when the lock is unavailable;
            ``None`` uses the instance default

        :returns: a proxy that can be used as a context manager to release the lock

        :raises RuntimeError: if a write lock is already held on this instance, if this instance was invalidated by
            :func:`os.fork`, or if :meth:`close` was called
        :raises Timeout: if the lock cannot be acquired within *timeout* seconds
        :raises TypeError: if *timeout* is a :class:`bool` or not a real number, or *blocking* is not a :class:`bool`
        :raises ValueError: if a blocking call gets a ``nan`` *timeout* or a negative one other than ``-1``
        :raises SoftFileLockProtocolError: if a snapshot cannot be read without risking overlap, or the filesystem
            refuses the no-replace hard links the protocol commits with

        Úreadr�   ©Ú_acquirer…   s      rJ   rƒ   zSoftReadWriteLock.acquire_readA  s   € ð4 �}‰}˜V W°xˆ}Ó@Ð@rZ   c               ó*   — | j                  d||¬«      S )a  
        Acquire an exclusive write lock.

        If this instance already holds a write lock from the same thread, the lock level is incremented (reentrant).
        Attempting to acquire a write lock while holding a read lock raises :class:`RuntimeError` (upgrade not
        allowed). Write locks are pinned to the acquiring thread: a different thread trying to re-enter also raises
        :class:`RuntimeError`.

        A writer enters the next snapshot as its writer as soon as no live writer is named, which blocks every new
        reader on every host, then waits for the readers that snapshot names to leave. Writer starvation is impossible:
        new readers see the named writer and wait behind it.

        :param timeout: maximum wait time in seconds, or ``None`` to use the instance default; ``-1`` means block
            indefinitely
        :param blocking: if ``False``, raise :class:`~filelock.Timeout` immediately when the lock is unavailable;
            ``None`` uses the instance default

        :returns: a proxy that can be used as a context manager to release the lock

        :raises RuntimeError: if a read lock is already held, if a write lock is held by a different thread, if this
            instance was invalidated by :func:`os.fork`, or if :meth:`close` was called
        :raises Timeout: if the lock cannot be acquired within *timeout* seconds
        :raises TypeError: if *timeout* is a :class:`bool` or not a real number, or *blocking* is not a :class:`bool`
        :raises ValueError: if a blocking call gets a ``nan`` *timeout* or a negative one other than ``-1``
        :raises SoftFileLockProtocolError: if a snapshot cannot be read without risking overlap, or the filesystem
            refuses the no-replace hard links the protocol commits with

        Úwriter�   r�   r…   s      rJ   r‰   zSoftReadWriteLock.acquire_write]  s   € ð: �}‰}˜W g¸ˆ}ÓAÐArZ   c               ó   —  | |||¬«      S )a0  
        Return the singleton :class:`SoftReadWriteLock` for *lock_file*.

        :param lock_file: path to the lock file; the protocol directory lives next to it as ``<lock_file>.rw``
        :param timeout: maximum wait time in seconds; ``-1`` means block indefinitely
        :param blocking: if ``False``, raise :class:`~filelock.Timeout` immediately when the lock is unavailable

        :returns: the singleton lock instance

        :raises ValueError: if an instance already exists for this path with different *timeout* or *blocking* values

        r�   r]   )rA   rB   r4   r-   s       rJ   Úget_lockzSoftReadWriteLock.get_lock|  s   € ñ( �9˜g°Ô9Ð9rZ   c                óÐ   — | j                   t        j                  «       k7  ry| j                  j                  5  d| _        ddd«       | j                  d¬«       y# 1 sw Y   ŒxY w)u‰  
        Release any held lock and mark the instance closed.

        Idempotent. After calling this method the instance can no longer acquire locks â€” subsequent acquires raise
        :class:`RuntimeError`, and so does an acquire another thread is still waiting in, which gives up its claim
        instead of taking the lock. A fork-invalidated instance is closed without raising.
        NT©Úforce)rg   r:   r;   rq   re   rt   r„   r~   s    rJ   ÚclosezSoftReadWriteLock.close’  sT   € ð ×Ñ¤§	¡	£Ò+Øð �[‰[×!Ñ!ñ 	 ØˆDŒL÷	 à�‰˜4ˆÕ ÷	 ð 	 ús   ¹AÁA%Fr”   c               ó’   — | j                   t        j                  «       k7  ry| j                  t	        j
                  «       |¬«       y)aÖ  
        Release one level of the current lock.

        When the lock level reaches zero the heartbeat thread is stopped, the participant is committed out of the next
        snapshot, and its holder record is removed. On a fork-invalidated instance (that is, the child of a
        :func:`os.fork` call made while the parent held a lock) this method is a no-op so inherited ``with`` blocks can
        unwind cleanly in the child.

        :param force: if ``True``, release the lock completely regardless of the current lock level

        :raises RuntimeError: if no lock is currently held and *force* is ``False``, or if the calling thread holds no
            level of the current lock and *force* is ``False``

        Nr”   )rg   r:   r;   Ú_releaser_   Ú	get_ident)rv   r•   s     rJ   r„   zSoftReadWriteLock.release¢  s4   € ð ×Ñ¤§	¡	£Ò+ØØ�‰”i×)Ñ)Ó+°5ˆÕ9rZ   c               ó.   — | j                  |||||¬«      S )N)r-   ÚholderÚcancel_checkr�   )rv   r›   Úmoder4   r-   rœ   s         rJ   Ú_acquire_level_ofz#SoftReadWriteLock._acquire_level_ofµ  s   € ð
 �}‰}˜T 7°XÀfÐ[gˆ}ÓhÐhrZ   c                ó*   — | j                  |d¬«       y )NFr”   )r˜   )rv   r›   s     rJ   Ú_release_level_ofz#SoftReadWriteLock._release_level_of¼  s   € Ø�‰�f EˆÕ*rZ   c                ód   — | j                   x}d uxr ||j                  k(  xs ||j                  v S ry   )rr   Úwrite_thread_idÚread_depths)rv   r›   Úholds      rJ   Ú_holds_level_ofz!SoftReadWriteLock._holds_level_of¿  s:   € ð Ÿ
™
Ð"�¨4Ð/Òr°V¸t×?SÑ?SÑ5SÒ5qÐW]Ðae×aqÑaqÐWqÐrrZ   c               óà  — | j                   j                  5  | j                  }|€3|r
	 d d d «       y d| j                  › dt	        | «      › d�}t        |«      ‚|rd|_        n#| j                  ||«       |j                  |«       |j                  dkD  r
	 d d d «       y d | _        d d d «       j                  j                  «        	 |j                  t        j                  «       urA|j                  j                  t        | j                   dz   t        j"                  «      ¬«       |j$                  j'                  «        y # 1 sw Y   Œ xY w# |j$                  j'                  «        w xY w)NzCannot release a lock on ú (lock id: z) that is not heldr   g      ð?)r4   )rq   re   rr   rB   ru   r9   ÚlevelÚ_raise_if_not_holderÚleave_one_levelÚheartbeat_stopra   Úheartbeat_threadr_   Úcurrent_threadÚjoinÚminr/   ÚTIMEOUT_MAXr|   Úleave)rv   Ú	thread_idr•   r¤   rF   s        rJ   r˜   zSoftReadWriteLock._releaseÄ  sA  € Ø�[‰[×!Ñ!ñ 	Ø—:‘:ˆDØˆ|ÙØ÷		ð 	ð
 2°$·.±.Ð1AÀÌRÐPTËXÈJÐVhÐi�Ü" 3Ó'Ð'ÙØ�•
à×)Ñ)¨$°	Ô:Ø×$Ñ$ YÔ/Ø�z‰z˜AŠ~Ø÷	ð 	ð ˆDŒJ÷	ð& 	×Ñ×ÑÔ!ð	%Ø×$Ñ$¬I×,DÑ,DÓ,FÑFØ×%Ñ%×*Ñ*´3°t×7NÑ7NÐQTÑ7TÔV_×VkÑVkÓ3lÐ*Ômð ×Ñ×"Ñ"Õ$÷3	ð 	ûð2 ×Ñ×"Ñ"Õ$ús$   —E²A$EÂEÃ	A!E ÅEÅE-c                óp  — ||j                   j                  k(  ry |j                  dk(  rE||j                  k7  r6d| j                  › dt        | «      › d|› d|j                  › �}t        |«      ‚|j                  dk(  r9||j                  vr*d| j                  › dt        | «      › d|› d�}t        |«      ‚y y )	Nr�   zCannot release write lock on r§   ú) from thread ú while it is held by thread rŒ   zCannot release read lock on z, which does not hold it)r¬   Úidentr�   r¢   rB   ru   r9   r£   )rv   r¤   r²   rF   s       rJ   r©   z&SoftReadWriteLock._raise_if_not_holderà  s×   € à˜×-Ñ-×3Ñ3Ò3Øà�9‰9˜Ò I°×1EÑ1EÒ$Eà/°·±Ð/?¸{Ì2ÈdË8È*ð UØ(˜kÐ)EÀd×FZÑFZÐE[ð]ð ô ˜sÓ#Ð#à�9‰9˜Ò 9°D×4DÑ4DÑ#Dà.¨t¯~©~Ð.>¸kÌ"ÈTË(Èð TØ(˜kÐ)AðCð ô ˜sÓ#Ð#ð $EÐrZ   )r›   rœ   c               ón  — | j                   t        j                  «       k7  rd| j                  › d�}t	        |«      ‚|€| j
                  n|}|€| j                  n|}|€t        j                  «       n|}| j                  j                  5  | j                  r| j                  «       ‚t        ||¬«      }| j                  �| j                  ||«      cd d d «       S 	 d d d «       |dk(  rd nt!        j"                  «       |z   }t%        | j                  j&                  ||| j(                  |¬«      st+        | j                  «      d ‚	 | j-                  |||||¬«      | j                  j&                  j/                  «        S # 1 sw Y   Œ¦xY w# | j                  j&                  j/                  «        w xY w)NúSoftReadWriteLock on z4 was invalidated by fork(); construct a new instancer�   rL   )r-   r4   r1   rœ   )r-   rœ   )rg   r:   r;   rB   r9   r4   r-   r_   r™   rq   re   rt   Ú_closed_errorr   rr   Ú_validate_reentrantrk   Úperf_counterr   rf   r1   r   Ú_do_acquire_innerr„   )rv   r�   r4   r-   r›   rœ   rF   Údeadlines           rJ   rŽ   zSoftReadWriteLock._acquireó  s|  € ð ×Ñ¤§	¡	£Ò+Ø)¨$¯.©.Ð)9Ð9mÐnˆCÜ˜sÓ#Ð#Ø") /�$—,’,°wˆØ$,Ð$4�4—=’=¸(ˆØ*0¨.”×$Ñ$Ô&¸fˆà�[‰[×!Ñ!ñ 	>Ø�|Š|Ø×(Ñ(Ó*Ð*Ü1°'ÀHÔMˆGØ�z‰zÐ%Ø×/Ñ/°°fÓ=÷	>ñ 	>ð &÷		>ð # bš=‘4¬d×.?Ñ.?Ó.AÀGÑ.KˆÜ#Ø�K‰K×#Ñ#ØØØ×,Ñ,Ø%õ
ô ˜$Ÿ.™.Ó)¨tÐ3ð	.Ø×)Ñ)¨$°¸&È8ÐbnÐ)Óoà�K‰K×#Ñ#×+Ñ+Õ-÷'	>ð 	>ûð& �K‰K×#Ñ#×+Ñ+Õ-ús   ÂAFÅF ÆFÆ&F4c                ó4   — t        d| j                  › d�«      S )Nr¸   z has been closed)r9   rB   r~   s    rJ   r¹   zSoftReadWriteLock._closed_error  s   € ÜÐ3°D·N±NÐ3CÐCSÐTÓUÐUrZ   c               ó€  ‡ ‡	‡
— ‰ j                   j                  5  ‰ j                  �‰ j                  ||«      cd d d «       S 	 d d d «       t	        ‰ j
                  ‰ j                  |‰ j                  t        j                  ‰ j                  ‰ j                  ¬«      Š
‰
j                  «        	 ‰ j                  ‰
j                  |||¬«       t'        j(                  «       }t+        d||dk(  r|nd |dk(  r|dini ‰
t-        ˆ	ˆ
ˆ fd„‰ j.                  |dt1        ‰ «      d›�¬	«      |t        j                  «       ¬
«      Š	d }‰ j                   j                  5  ‰ j2                  r‰ j5                  «       }n)‰	‰ _        d ‰ _        	 ‰	j8                  j;                  «        d d d «       |�‰
j%                  «        |‚t=        ‰ ¬«      S # 1 sw Y   �Œ…xY w# t        $ r6 t!        t"        «      5  ‰
j%                  «        d d d «       ‚ # 1 sw Y   ‚ xY ww xY w# t        $ r}d ‰ _        |}Y d }~ŒŽd }~ww xY w# 1 sw Y   Œ—xY w)N)r0   ÚclockÚledgerÚlog)r½   r-   rœ   é   r�   rŒ   c                 ó(   •— ‰j                  ‰‰ «      S ry   )Ú_refresh)r¤   r|   rv   s   €€€rJ   ú<lambda>z5SoftReadWriteLock._do_acquire_inner.<locals>.<lambda>B  s   ø€  §¡¨k¸4Ó @€ rZ   zfilelock-heartbeat-Úx)ÚrefreshÚintervalÚ
stop_eventÚname)r¨   r�   r¢   r£   r|   r¬   r«   Úlast_refresh©Úlock)rq   re   rr   rº   r   rj   ri   r0   rk   rl   rm   rn   ÚpublishÚ	_wait_forÚadvanceÚBaseExceptionr   ÚOSErrorr±   r_   ÚEventÚ_HoldÚ_HeartbeatThreadr/   ru   rt   r¹   rs   r¬   Ústartr   )rv   r�   r½   r›   r-   rœ   rÊ   Ústart_errorÚerrorr¤   r|   s   `        @@rJ   r¼   z#SoftReadWriteLock._do_acquire_inner  s  ú€ ð �[‰[×!Ñ!ñ 	>Ø�z‰zÐ%Ø×/Ñ/°°fÓ=÷	>ñ 	>Ø%÷	>ô "Ø�K‰KØ�J‰JØØ ×0Ñ0Ü—.‘.Ø—<‘<Ø—	‘	ô
ˆð 	×ÑÔð	Ø�N‰N˜;×.Ñ.¸ÈHÐcoˆNÔpô —_‘_Ó&ˆ
ÜØØØ&*¨g¢o™F¸4Ø'+¨v¢~˜ ™¸2Ø#Ü-Ý@Ø×0Ñ0Ø%Ø*¬2¨d«8°A¨,Ð7ô	ð &ÜŸ™Ó)ô
ˆð( -1ˆØ�[‰[×!Ñ!ñ 
	(Ø�|Š|Ø"×0Ñ0Ó2‘à!�”
Ø#'�Ô ð(Ø×)Ñ)×/Ñ/Ô1÷
	(ð Ð"Ø×ÑÔØÐÜ! tÔ,Ð,÷u	>ñ 	>ûô ò 	ô œ'Ó"ñ $Ø×!Ñ!Ô#÷$à÷$àúð	ûôJ %ò (Ø!%�D”JØ"'•Kûð(ú÷
	(ð 
	(ús_   šGÂ.G Å,H4ÆHÇGÇHÇ+HÇ<	HÈH	È
HÈ	H1È	H,È'H4È,H1È1H4È4H=c                óF  — | j                   }|€J ‚|j                  |k7  rB|dk(  rdnd}|dk(  rdnd}d|› d| j                  › dt        | «      › d|› d	|› d
�}t	        |«      ‚|dk(  rE||j
                  k7  r6d| j                  › dt        | «      › d|› d|j
                  › �}t	        |«      ‚| j                  x}�t        | j                  ||«      ‚|dk(  r,|j                  j                  |d«      dz   |j                  |<   |xj                  dz  c_
        t        | ¬«      S )NrŒ   r�   Ú	downgradeÚupgradeúCannot acquire ú	 lock on r§   z): already holding a z lock (z not allowed)zCannot acquire write lock on r´   rµ   r   rÃ   rÍ   )rr   r�   rB   ru   r9   r¢   rs   Ú_lost_hold_errorr£   r8   r¨   r   )rv   r�   r›   r¤   ÚoppositeÚ	directionrF   r€   s           rJ   rº   z%SoftReadWriteLock._validate_reentrant`  sL  € Ø�z‰zˆØÐÐÐØ�9‰9˜ÒØ"&¨&¢.‘w°fˆHØ'+¨v¢~™¸9ˆIà! $  y°·±Ð0@ÀÌBÈtËHÈ:ð V%Ø%- J¨g°i°[ÀðOð ô ˜sÓ#Ð#Ø�7Š?˜v¨×)=Ñ)=Ò=à/°·±Ð/?¸{Ì2ÈdË8È*ð UØ%˜hÐ&BÀ4×CWÑCWÐBXðZð ô ˜sÓ#Ð#ð ×*Ñ*Ð*ˆJÐ7Ü" 4§>¡>°4¸ÓDÐDØ�6Š>Ø'+×'7Ñ'7×';Ñ';¸FÀAÓ'FÈÑ'JˆD×Ñ˜VÑ$Ø�
Š
�a‰�
Ü! tÔ,Ð,rZ   c               ót  —  |«       s±| j                   r| j                  «       ‚t        j                  «       }|r|�||k\  rt	        | j
                  «      ‚|� |«       rt	        | j
                  «      ‚| j                  }|�t        |t        ||z
  d«      «      }t        j                  |«        |«       sŒ°y y )Ng        )
rt   r¹   rk   r»   r   rB   r1   r¯   ÚmaxÚsleep)rv   Ú	predicater½   r-   rœ   ÚnowÚ	sleep_fors          rJ   rÐ   zSoftReadWriteLock._wait_forz  sž   € ñ ”+à�|Š|Ø×(Ñ(Ó*Ð*Ü×#Ñ#Ó%ˆCÙ Ð 4¸ÀºÜ˜dŸn™nÓ-Ð-àÐ'©L¬NÜ˜dŸn™nÓ-Ð-Ø×*Ñ*ˆIØÐ#Ü 	¬3¨x¸#©~¸sÓ+CÓD�	Ü�J‰J�yÔ!ñ —+rZ   c                óŒ  — 	 |j                  «       \  }}|dk(  rt        j                  «       |_        y|dk(  r| j                  |dd «       yt        j                  «       |j
                  z
  | j                  | j                  z
  k\  r| j                  |d|«       yy# t        $ r}| j                  |d|«       Y d }~yd }~ww xY w)Nzrefresh-failedFÚokTÚlostÚevicted)Ú	heartbeatÚ	ExceptionÚ_report_compromiserk   rl   rÌ   r0   r/   )rv   r|   r¤   ÚoutcomerÙ   Úfailures         rJ   rÅ   zSoftReadWriteLock._refresh‘  s½   € ð
	Ø(×2Ñ2Ó4‰NˆG�Uð �dŠ?Ü $§¡Ó 0ˆDÔØØ�fÒØ×#Ñ# D¨)°TÔ:ØÜ�>‰>Ó˜d×/Ñ/Ñ/°4×3GÑ3GÈ$×JaÑJaÑ3aÒaØ×#Ñ# DÐ*:¸EÔBØØøô ò 	Ø×#Ñ# DÐ*:¸GÔDÜûð	ús   ‚B Â	CÂ&B>Â>Cc                ó.  — | j                   j                  5  | j                  |ur
	 d d d «       y t        | j                  |j
                  j                  ||¬«      }|| _        d d d «       | j                  �| j                  «       y y # 1 sw Y   Œ(xY w)N)rB   ÚtokenÚreasonrÙ   )	rq   re   rr   r   rB   r|   rò   rs   r?   )rv   r¤   ró   rÙ   r€   s        rJ   rî   z$SoftReadWriteLock._report_compromise¦  sŽ   € à�[‰[×!Ñ!ñ 	*Ø�z‰z Ñ%Ø÷	*ð 	*ô )ØŸ.™.°×0@Ñ0@×0FÑ0FÈvÐ]bôˆJð  *ˆDÔ÷	*ð ×ÑÐ*Ø×Ñ 
Õ+ð +÷	*ð 	*ús   —B°4BÂBc                ó~   — t        t        j                  «       t        j                  «       ¬«      | _        d | _        y )Nrd   )ro   r_   rp   rq   rr   r~   s    rJ   Ú_reset_after_fork_in_childz,SoftReadWriteLock._reset_after_fork_in_child²  s%   € Ü¤i§n¡nÓ&6ÄIÇNÁNÓDTÔUˆŒØˆ�
rZ   )rb   ÚobjectrR   ÚNonerK   )rB   rM   r4   rN   r-   rO   r.   rO   r/   rN   r0   rP   r1   rN   r2   rQ   rR   r÷   ©rR   r÷   )rR   ú
int | None)rR   zLeaseCompromise | Nonery   )r4   rP   r-   úbool | NonerR   zGenerator[None])r4   rP   r-   rú   rR   r   )rB   rM   r4   rN   r-   rO   rR   rS   )r•   rO   rR   r÷   )r›   Úintr�   r   r4   rN   r-   rO   rœ   úCallable[[], bool]rR   r   )r›   rû   rR   r÷   )r›   rû   rR   rO   )r²   rû   r•   rO   rR   r÷   )r¤   rÕ   r²   rû   rR   r÷   )r�   r   r4   rP   r-   rú   r›   rù   rœ   úCallable[[], bool] | NonerR   r   )rR   r9   )r�   r   r½   rP   r›   rû   r-   rO   rœ   rý   rR   r   )r�   r   r›   rû   rR   r   )
rå   rü   r½   rP   r-   rO   rœ   rý   rR   r÷   )r|   r   r¤   rÕ   rR   rO   )r¤   rÕ   ró   r!   rÙ   zException | NonerR   r÷   ))rT   rU   rV   Ú__doc__r   r'   rW   r_   r`   r(   ra   r)   r^   rw   Úclassmethodrz   Úpropertyr}   r€   r   r†   rŠ   rƒ   r‰   r’   r–   r„   rž   r    r¥   r˜   r©   rŽ   r¹   r¼   rº   rÐ   rÅ   rî   rõ   rX   rY   s   @rJ   rS   rS   …   sÔ  ø… ñ2ñh I\ÓH]€JÐEÓ]Ø%�i—o‘oÓ'€OÙ8;»Ð!Ð#5Ó=õ"ð ð&$ð
 Ø!Ø$(Ø(,Ø#ØBFñ&$à)ð&$ð ð&$ð
 ð&$ð ð&$ð "ð&$ð &ð&$ð ð&$ð @ð&$ð 
ó&$ðP ò2ó ð2ð òUó ðUð ò$ó ð$ð ðÐQUô ó ðð* ðÐRVô ó ðð*AÐTXõ Að8BÐUYõ Bð> ð ð:ð
 ñ:à)ð:ð ð:ð
 ð:ð 
ò:ó ð:ó*!ð  (-õ :ð&iØðiØ!%ðiØ05ðiØDHðiØXjðià	óió+ósó
%ó8$ð2 "Ø26ñ#.àð#.ð ð#.ð
 ð#.ð ð#.ð 0ð#.ð 
ó#.óJVðC-àðC-ð ðC-ð ð	C-ð ðC-ð 0ðC-ð 
óC-óJ-ð4"à%ð"ð ð	"ð
 ð"ð 0ð"ð 
ó"ó.ó*
,÷rZ   rS   )Ú	metaclassc                  ó<   ‡ — e Zd Z	 	 	 	 	 	 	 	 	 	 dˆ fd„Zdd„Zˆ xZS )rÖ   c                óR   •— t         ‰| �  |d¬«       || _        || _        || _        y )NT)rË   Údaemon)r6   rw   rÅ   Ú	_intervalÚ_stop_event)rv   rÈ   rÉ   rÊ   rË   rI   s        €rJ   rw   z_HeartbeatThread.__init__¸  s-   ø€ ô 	‰Ñ˜d¨4ÐÔ0ØˆŒØ!ˆŒØ%ˆÕrZ   c                óf  — 	 | j                   j                  | j                  «      sR| j                  «       s	 | j                   j	                  «        y | j                   j                  | j                  «      sŒR| j                   j	                  «        y # | j                   j	                  «        w xY wry   )r  Úwaitr  rÅ   ra   r~   s    rJ   Úrunz_HeartbeatThread.runÄ  s~   € ð	#Ø×&Ñ&×+Ñ+¨D¯N©NÔ;Ø—}‘}”Øà×Ñ× Ñ Õ"ð	 ×&Ñ&×+Ñ+¨D¯N©NÕ;ð ×Ñ× Ñ Õ"øˆD×Ñ× Ñ Õ"ús   ‚5B Á%B ÂB0)
rÈ   rü   rÉ   rN   rÊ   úthreading.EventrË   ÚstrrR   r÷   rø   )rT   rU   rV   rw   r	  rX   rY   s   @rJ   rÖ   rÖ   ·  s=   ø„ ð
&à#ð
&ð ð
&ð $ð	
&ð
 ð
&ð 
õ
&÷#rZ   rÖ   c           	     ó@   — t        d|› d| › d|j                  › d�«      S )NrÝ   rÞ   z: the current hold was lost (z$), release it before acquiring again)r9   ró   )rB   r�   r€   s      rJ   rß   rß   Î  s6   € ÜØ
˜$˜˜y¨¨Ð3PÐQ[×QbÑQbÐPcð d,ð 	,óð rZ   c                óˆ  — t        d| «      } t        | «      r| dk  rd| › �}t        |«      ‚t        d| «       |€| dz  nt        d|«      }t        |«      r|| k  rd| › d|› �}t        |«      ‚t        t        d|«      x}«      r|dk  rd	|› �}t        |«      ‚t        d|«       ||k\  rd
|› d|› �}t        |«      ‚| ||fS )Nr/   r   z4heartbeat_interval must be positive and finite, got é   r0   z0stale_threshold must exceed heartbeat_interval (z) and be finite, got r1   z/poll_interval must be positive and finite, got z-poll_interval must be below stale_threshold (z), got )r   r   r>   r   )r/   r0   r1   rF   s       rJ   r@   r@   Õ  s  € ô "Ð"6Ð8JÓKÐÜÐ&Ô'Ð+=ÀÒ+BØDÐEWÐDXÐYˆÜ˜‹oÐäÐ+Ð-?Ô@à"1Ð"9Ð˜QÒ¼xÐHYÐ[jÓ?kð ô �OÔ$¨Ð;MÒ(Mà>Ð?QÐ>Rð S"Ø"1Ð!2ð4ð 	ô ˜‹oÐÜ¤X¨o¸}Ó%MÐM�MÔNÐR_ÐcdÒRdØ?À¸ÐOˆÜ˜‹oÐÜ�¨Ô6à˜Ò'Ø=¸oÐ=NÈgÐVcÐUdÐeˆÜ˜‹oÐØ˜°Ð=Ð=rZ   c                  ó"   — e Zd ZU ded<   ded<   y)ro   r#   re   rf   N)rT   rU   rV   rW   r]   rZ   rJ   ro   ro   ò  s   … àÓØÔrZ   ro   c                  ój   — e Zd ZU dZded<   ded<   ded<   ded	<   d
ed<   ded<   ded<   ded<   dd„Zy)rÕ   zYEverything that exists only while a lock is held; ``None`` when the instance has no lock.rû   r¨   r   r�   rù   r¢   zdict[int, int]r£   r   r|   rÖ   r¬   r
  r«   rN   rÌ   c                ó
  — | xj                   dz  c_         | j                  dk(  r_|| j                  v r|nt        t	        | j                  «      «      }| j                  j                  |«      dz
  x}r|| j                  |<   y y y )NrÃ   rŒ   )r¨   r�   r£   ÚnextÚiterÚpop)rv   r²   ÚownerÚdepths       rJ   rª   z_Hold.leave_one_level  sz   € Ø�
Š
�a‰�
Ø�9‰9˜Òà!*¨d×.>Ñ.>Ñ!>‘IÄDÌÈd×N^ÑN^ÓI_ÓD`ˆEØ×(Ñ(×,Ñ,¨UÓ3°aÑ7Ð7ˆuÐ7Ø*/�× Ñ  Ò'ð 8ð rZ   N)r²   rû   rR   r÷   )rT   rU   rV   rþ   rW   rª   r]   rZ   rJ   rÕ   rÕ   ø  s8   … ácàƒJØ
ƒJØÓàÓØÓØ&Ó&Ø#Ó#ØÓô0rZ   rÕ   c                 ó´   — t        t        j                  «       «      D ],  } t        t        «      5  | j                  d¬«       d d d «       Œ. y # 1 sw Y   Œ9xY w)NTr”   )Úlistr"   Úvaluesr   rí   r„   )rE   s    rJ   Ú_cleanup_all_instancesr    sR   € Üœ×.Ñ.Ó0Ó1ò )ˆÜ”iÓ ñ 	)Ø×Ñ 4ÐÔ(÷	)ð 	)ñ)÷	)ð 	)ús   °AÁA	rß   )rB   r  r�   r   r€   r   rR   r9   )r/   rN   r0   rP   r1   rN   rR   ztuple[float, float, float]rø   )@rþ   Ú
__future__r   Ú__lazy_modules__Úatexitr:   r_   rk   Ú
contextlibr   r   Údataclassesr   r   r   Útypingr	   r
   r   Úweakrefr   Úfilelock._apir   r   r   r   r   r   r   r   r   r   r   Úfilelock._errorr   Úfilelock._leaser   Úfilelock._soft_rw._protocolr   r   r   r   Úfilelock._soft_rw._storager   Úcollections.abcr   r    r!   r"   rW   rp   r$   Útyper&   rS   ÚThreadrÖ   rß   r@   ro   rÕ   r  ÚregisterÚ__all__r]   rZ   rJ   ú<module>r,     s=  ðÚ cå "òÐ ó Û 	Û Û ß /Ý !Ý ß 1Ñ 1Ý '÷÷ ÷ ñ õ $Ý +ß PÓ PÝ .áß3å0áEXÓEZ€ÐBÓ ZØ&4 i§n¡nÓ&6Ð �^Ó 6ôP�$ô Pôfo +õ oôd#�y×'Ñ'ô #ó.ð>Øð>Ø0<ð>ØMRð>àó>ð: ÷ ð  ó ð ð
 ÷0ð 0ó ð0ó,)ð €‡�Ð&Ô 'Ù Ð&Ô 'ð Øð�rZ   