Ë
    B²j "  ã                  ó¬   — 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
 erddlZddlmZmZ dd	lmZ dd
lmZ  G d„ d«      Z G d„ d«      ZddgZy)zIAsync wrapper around :class:`SoftReadWriteLock` for use with ``asyncio``.é    )ÚannotationsN)Úasynccontextmanager)ÚTYPE_CHECKINGé   )ÚSoftReadWriteLock)ÚAsyncGeneratorÚCallable)Úfutures)ÚTracebackTypec                  ó8   — e Zd ZdZdd„Zdd„Z	 	 	 	 	 	 	 	 dd„Zy)	Ú$AsyncAcquireSoftReadWriteReturnProxyzTAsync context-aware object that releases an :class:`AsyncSoftReadWriteLock` on exit.c                ó   — || _         y ©N©Úlock)Úselfr   s     úW/var/www/html/ia-enhanced/venv/lib/python3.12/site-packages/filelock/_soft_rw/_async.pyÚ__init__z-AsyncAcquireSoftReadWriteReturnProxy.__init__   s	   € Øˆ�	ó    c              ƒ  ó"   K  — | j                   S ­wr   r   ©r   s    r   Ú
__aenter__z/AsyncAcquireSoftReadWriteReturnProxy.__aenter__   s   è ø€ Ø�y‰yÐùs   ‚c              ƒ  óT   K  — | j                   j                  «       ƒ d {  –—†  y 7 Œ­wr   )r   Úrelease)r   Úexc_typeÚ	exc_valueÚ	tracebacks       r   Ú	__aexit__z.AsyncAcquireSoftReadWriteReturnProxy.__aexit__   s   è ø€ ð �i‰i×ÑÓ!×!Ò!ús   ‚( &¡(N)r   ÚAsyncSoftReadWriteLockÚreturnÚNone)r    r   )r   ztype[BaseException] | Noner   zBaseException | Noner   zTracebackType | Noner    r!   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   © r   r   r   r      s:   „ Ù^óóð"à,ð"ð (ð"ð (ð	"ð
 
ô"r   r   c            	      ó8  — e Zd ZdZ	 d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„«       Z	edd„«       Z
	 dddœ	 	 	 	 	 dd„Z	 dddœ	 	 	 	 	 dd„Zddœd d„Zedddœd!d„«       Zedddœd!d„«       Zd"d„Zd#d„Zy)$r   aÛ  
    Async wrapper around :class:`SoftReadWriteLock` for ``asyncio`` applications.

    The sync class's blocking filesystem operations run on a thread pool via ``loop.run_in_executor()``.
    Reentrancy, upgrade/downgrade rules, fork handling, heartbeat and TTL stale detection, and singleton
    behavior are delegated to the underlying :class:`SoftReadWriteLock`.

    :param lock_file: path to the lock file; sidecar state/write/readers live next to it
    :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 :class:`SoftReadWriteLock` instances per resolved path
    :param heartbeat_interval: seconds between heartbeat refreshes; default 30 s
    :param stale_threshold: seconds of mtime inactivity before a marker is stale; defaults to ``3 * heartbeat_interval``
    :param poll_interval: seconds between acquire retries under contention; default 0.25 s
    :param loop: event loop for ``run_in_executor``; ``None`` uses the running loop
    :param executor: executor for ``run_in_executor``; ``None`` uses the default executor

    .. versionadded:: 3.27.0

    Tg      >@Ng      Ð?)ÚblockingÚis_singletonÚheartbeat_intervalÚstale_thresholdÚpoll_intervalÚloopÚexecutorc          	     óN   — t        |||||||¬«      | _        || _        |	| _        y )N)r(   r)   r*   r+   r,   )r   Ú_lockÚ_loopÚ	_executor)
r   Ú	lock_fileÚtimeoutr(   r)   r*   r+   r,   r-   r.   s
             r   r   zAsyncSoftReadWriteLock.__init__;   s5   € ô 'ØØØØ%Ø1Ø+Ø'ô
ˆŒ
ð ˆŒ
Ø!ˆ�r   c                ó.   — | j                   j                  S )z>:returns: the path to the lock file passed to the constructor.)r0   r3   r   s    r   r3   z AsyncSoftReadWriteLock.lock_fileT   s   € ð �z‰z×#Ñ#Ð#r   c                ó.   — | j                   j                  S )zf:returns: the default timeout applied when ``acquire_read`` / ``acquire_write`` is called without one.)r0   r4   r   s    r   r4   zAsyncSoftReadWriteLock.timeoutY   s   € ð �z‰z×!Ñ!Ð!r   c                ó.   — | j                   j                  S )zc:returns: whether ``acquire_*`` defaults to blocking; ``False`` makes contention raise immediately.)r0   r(   r   s    r   r(   zAsyncSoftReadWriteLock.blocking^   s   € ð �z‰z×"Ñ"Ð"r   c                ó   — | j                   S )zX:returns: the event loop used for ``run_in_executor``, or ``None`` for the running loop.)r1   r   s    r   r-   zAsyncSoftReadWriteLock.loopc   s   € ð �z‰zÐr   c                ó   — | j                   S )zZ:returns: the executor used for ``run_in_executor``, or ``None`` for the default executor.)r2   r   s    r   r.   zAsyncSoftReadWriteLock.executorh   s   € ð �~‰~Ðr   ©r(   c             ƒ  ó†   K  — | j                  | j                  j                  ||¬«      ƒ d{  –—†  t        | ¬«      S 7 Œ­w)aC  
        Acquire a shared read lock.

        See :meth:`SoftReadWriteLock.acquire_read` for the full reentrancy / upgrade / fork semantics. The blocking
        work runs inside ``run_in_executor`` so other coroutines on the same loop continue to progress while this
        call waits.

        :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

        :returns: a proxy usable as an async context manager to release the lock

        :raises RuntimeError: if a write lock is already held, 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

        r:   Nr   )Ú_runr0   Úacquire_readr   ©r   r4   r(   s      r   r=   z#AsyncSoftReadWriteLock.acquire_readm   s;   è ø€ ð( �i‰i˜Ÿ
™
×/Ñ/°À8ˆiÓL×LÐLÜ3¸Ô>Ð>ð 	Múó   ‚,A®?¯Ac             ƒ  ó†   K  — | j                  | j                  j                  ||¬«      ƒ d{  –—†  t        | ¬«      S 7 Œ­w)a  
        Acquire an exclusive write lock.

        See :meth:`SoftReadWriteLock.acquire_write` for the two-phase writer-preferring semantics. The blocking
        work runs inside ``run_in_executor``.

        :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

        :returns: a proxy usable as an async 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

        r:   Nr   )r<   r0   Úacquire_writer   r>   s      r   rA   z$AsyncSoftReadWriteLock.acquire_write„   s;   è ø€ ð& �i‰i˜Ÿ
™
×0Ñ0°'ÀHˆiÓM×MÐMÜ3¸Ô>Ð>ð 	Núr?   F©Úforcec             ƒ  ón   K  — | j                  | j                  j                  |¬«      ƒ d{  –—†  y7 Œ­w)zó
        Release one level of the current lock.

        :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``

        rB   N)r<   r0   r   )r   rC   s     r   r   zAsyncSoftReadWriteLock.releaseš   s(   è ø€ ð �i‰i˜Ÿ
™
×*Ñ*°%ˆiÓ8×8Ò8ús   ‚+5­3®5c              óÂ   K  — | j                  ||¬«      ƒ d{  –—†  	 d­–— | j                  «       ƒ d{  –—†  y7 Œ#7 Œ# | j                  «       ƒ d{  –—†7   w xY w­w)aÏ  
        Async context manager that acquires and releases a shared read lock.

        :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

        r:   N)r=   r   r>   s      r   Ú	read_lockz AsyncSoftReadWriteLock.read_lock¥   sR   è ø€ ð ×Ñ °(ÐÓ;×;Ð;ð	!Üà—,‘,“.× Ñ ð	 	<øð !ù�$—,‘,“.× Ò üó>   ‚A™=šAŸA ¤A·?¸A¿AÁAÁAÁAÁAc              óÂ   K  — | j                  ||¬«      ƒ d{  –—†  	 d­–— | j                  «       ƒ d{  –—†  y7 Œ#7 Œ# | j                  «       ƒ d{  –—†7   w xY w­w)añ  
        Async context manager that acquires and releases an exclusive write lock.

        :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

        r:   N)rA   r   r>   s      r   Ú
write_lockz!AsyncSoftReadWriteLock.write_lock·   sR   è ø€ ð × Ñ  °8Ð Ó<×<Ð<ð	!Üà—,‘,“.× Ñ ð	 	=øð !ù�$—,‘,“.× Ò ürG   c              ƒ  ój   K  — | j                  | j                  j                  «      ƒ d{  –—†  y7 Œ­w)zRRelease any held lock and release the underlying filesystem resources. Idempotent.N)r<   r0   Úcloser   s    r   rK   zAsyncSoftReadWriteLock.closeÉ   s"   è ø€ à�i‰i˜Ÿ
™
×(Ñ(Ó)×)Ò)ús   ‚)3«1¬3c              �  óÈ   K  — | j                   xs t        j                  «       }|j                  | j                  t        j                  |g|¢­i |¤Ž«      ƒ d {  –—† S 7 Œ­wr   )r1   ÚasyncioÚget_running_loopÚrun_in_executorr2   Ú	functoolsÚpartial)r   ÚfuncÚargsÚkwargsr-   s        r   r<   zAsyncSoftReadWriteLock._runÍ   sQ   è ø€ Ø�z‰zÒ7œW×5Ñ5Ó7ˆØ×)Ñ)¨$¯.©.¼)×:KÑ:KÈDÐ:bÐSWÒ:bÐ[aÑ:bÓc×cÐcÐcús   ‚AA"ÁA ÁA")éÿÿÿÿ)r3   zstr | os.PathLike[str]r4   Úfloatr(   Úboolr)   rW   r*   rV   r+   úfloat | Noner,   rV   r-   ú asyncio.AbstractEventLoop | Noner.   úfutures.Executor | Noner    r!   )r    Ústr)r    rV   )r    rW   )r    rY   )r    rZ   r   )r4   rX   r(   úbool | Noner    r   )rC   rW   r    r!   )r4   rX   r(   r\   r    zAsyncGenerator[None])r    r!   )rR   zCallable[..., object]rS   ÚobjectrT   r]   r    r]   )r"   r#   r$   r%   r   Úpropertyr3   r4   r(   r-   r.   r=   rA   r   r   rF   rI   rK   r<   r&   r   r   r   r   %   s”  „ ñð0 ð"ð
 Ø!Ø$(Ø(,Ø#Ø15Ø,0ñ"à)ð"ð ð"ð
 ð"ð ð"ð "ð"ð &ð"ð ð"ð /ð"ð *ð"ð 
ó"ð2 ò$ó ð$ð ò"ó ð"ð ò#ó ð#ð òó ðð òó ðð
 '+ð?ØGKñ?Ø#ð?Ø9Dð?à	-ó?ð0 '+ð?ØGKñ?Ø#ð?Ø9Dð?à	-ó?ð, .3õ 	9ð ð!ÐW[ô !ó ð!ð" ð!ÐX\ô !ó ð!ó"*ôdr   r   )r%   Ú
__future__r   rM   rP   Ú
contextlibr   Útypingr   Ú_syncr   ÚosÚcollections.abcr   r	   Ú
concurrentr
   Útypesr   r   r   Ú__all__r&   r   r   ú<module>rh      sQ   ðÙ Oå "ã Û Ý *Ý  å $áÛß8Ý"Ý#÷"ñ "÷$jdñ jdð\ +Øð�r   