§
    ôÝþiO  ã                  óÆ   — 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 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dS )zEAsync wrapper around :class:`ReadWriteLock` for use with ``asyncio``.é    )ÚannotationsN)ÚThreadPoolExecutor)Úasynccontextmanager)ÚTYPE_CHECKINGé   )ÚReadWriteLock)ÚAsyncGeneratorÚCallable)Úfutures)ÚTracebackTypec                  ó*   — e Zd ZdZdd„Zdd„Zdd„ZdS )Ú AsyncAcquireReadWriteReturnProxyzEContext-aware object that releases the async read/write lock on exit.ÚlockÚAsyncReadWriteLockÚreturnÚNonec                ó   — || _         d S ©N©r   )Úselfr   s     ú[/usr/local/lib/hermes-agent/venv/lib/python3.11/site-packages/filelock/_async_read_write.pyÚ__init__z)AsyncAcquireReadWriteReturnProxy.__init__   s   € ØˆŒ	ˆ	ˆ	ó    c              ƒ  ó   K  — | j         S r   r   ©r   s    r   Ú
__aenter__z+AsyncAcquireReadWriteReturnProxy.__aenter__   s   è è € ØŒyÐr   Úexc_typeútype[BaseException] | NoneÚ	exc_valueúBaseException | NoneÚ	tracebackúTracebackType | Nonec              ƒ  óH   K  — | j                              ¦   «         ƒ d {V —† d S r   )r   Úrelease)r   r   r   r!   s       r   Ú	__aexit__z*AsyncAcquireReadWriteReturnProxy.__aexit__   s4   è è € ð Œi×ÒÑ!Ô!Ð!Ð!Ð!Ð!Ð!Ð!Ð!Ð!Ð!r   N)r   r   r   r   )r   r   )r   r   r   r    r!   r"   r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r%   © r   r   r   r      sV   € € € € € ØOÐOðð ð ð ðð ð ð ð"ð "ð "ð "ð "ð "r   r   c                  ó   — e Zd ZdZ	 d.dddddœd/d„Zed0d„¦   «         Zed1d„¦   «         Zed2d„¦   «         Zed3d„¦   «         Z	ed4d„¦   «         Z
d5d„Zd.dd œd6d"„Zd.dd œd6d#„Zd$d%œd7d'„Zed8dd œd9d+„¦   «         Zed8dd œd9d,„¦   «         Zd:d-„ZdS );r   a¹  
    Async wrapper around :class:`ReadWriteLock` for use in ``asyncio`` applications.

    Because Python's :mod:`sqlite3` module has no async API, all blocking SQLite operations are dispatched to a thread
    pool via ``loop.run_in_executor()``. Reentrancy, upgrade/downgrade rules, and singleton behavior are delegated
    to the underlying :class:`ReadWriteLock`.

    :param lock_file: path to the SQLite database file used as the lock
    :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
    :param is_singleton: if ``True``, reuse existing :class:`ReadWriteLock` instances for the same resolved path
    :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.21.0

    éÿÿÿÿTN)ÚblockingÚis_singletonÚloopÚexecutorÚ	lock_fileústr | os.PathLike[str]ÚtimeoutÚfloatr-   Úboolr.   r/   ú asyncio.AbstractEventLoop | Noner0   úfutures.Executor | Noner   r   c               ó„   — t          ||||¬¦  «        | _        || _        |d u | _        |pt	          d¬¦  «        | _        d S )N)r-   r.   r   )Úmax_workers)r   Ú_lockÚ_loopÚ_owns_executorr   Ú	_executor)r   r1   r3   r-   r.   r/   r0   s          r   r   zAsyncReadWriteLock.__init__9   sM   € õ # 9¨gÀÐWcÐdÑdÔdˆŒ
ØˆŒ
Ø&¨$Ð.ˆÔØ!ÐFÕ%7ÀAÐ%FÑ%FÔ%FˆŒˆˆr   Ústrc                ó   — | j         j        S )z$:returns: the path to the lock file.)r:   r1   r   s    r   r1   zAsyncReadWriteLock.lock_fileH   s   € ð ŒzÔ#Ð#r   c                ó   — | j         j        S )z:returns: the default timeout.)r:   r3   r   s    r   r3   zAsyncReadWriteLock.timeoutM   s   € ð ŒzÔ!Ð!r   c                ó   — | j         j        S )z1:returns: whether blocking is enabled by default.)r:   r-   r   s    r   r-   zAsyncReadWriteLock.blockingR   s   € ð ŒzÔ"Ð"r   c                ó   — | j         S )z<:returns: the event loop (or ``None`` for the running loop).)r;   r   s    r   r/   zAsyncReadWriteLock.loopW   s   € ð ŒzÐr   c                ó   — | j         S )z5:returns: the executor (or ``None`` for the default).)r=   r   s    r   r0   zAsyncReadWriteLock.executor\   s   € ð Œ~Ðr   ÚfuncúCallable[..., object]ÚargsÚobjectÚkwargsc                ó¢   K  — | j         pt          j        ¦   «         }|                     | j        t          j        |g|¢R i |¤Ž¦  «        ƒ d {V —†S r   )r;   ÚasyncioÚget_running_loopÚrun_in_executorr=   Ú	functoolsÚpartial)r   rD   rF   rH   r/   s        r   Ú_runzAsyncReadWriteLock._runa   sb   è è € ØŒzÐ7WÔ5Ñ7Ô7ˆØ×)Ò)¨$¬.½)Ô:KÈDÐ:bÐSWÐ:bÐ:bÐ:bÐ[aÐ:bÐ:bÑcÔcÐcÐcÐcÐcÐcÐcÐcr   ©r-   r   c             ƒ  óv   K  — |                       | j        j        ||¬¦  «        ƒ d{V —† t          | ¬¦  «        S )a7  
        Acquire a shared read lock.

        See :meth:`ReadWriteLock.acquire_read` for full semantics.

        :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: a proxy that can be used as an async context manager to release the lock

        :raises RuntimeError: if a write lock is already held on this instance
        :raises Timeout: if the lock cannot be acquired within *timeout* seconds

        rP   Nr   )rO   r:   Úacquire_readr   ©r   r3   r-   s      r   rR   zAsyncReadWriteLock.acquire_reade   sH   è è € ð iŠi˜œ
Ô/°À8ˆiÑLÔLÐLÐLÐLÐLÐLÐLÐLÝ/°TÐ:Ñ:Ô:Ð:r   c             ƒ  óv   K  — |                       | j        j        ||¬¦  «        ƒ d{V —† t          | ¬¦  «        S )aZ  
        Acquire an exclusive write lock.

        See :meth:`ReadWriteLock.acquire_write` for full semantics.

        :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: a proxy that can be used as an async context manager to release the lock

        :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

        rP   Nr   )rO   r:   Úacquire_writer   rS   s      r   rU   z AsyncReadWriteLock.acquire_writew   sH   è è € ð iŠi˜œ
Ô0°'ÀHˆiÑMÔMÐMÐMÐMÐMÐMÐMÐMÝ/°TÐ:Ñ:Ô:Ð:r   F©ÚforcerW   c             ƒ  óX   K  — |                       | j        j        |¬¦  «        ƒ d{V —† dS )a2  
        Release one level of the current lock.

        See :meth:`ReadWriteLock.release` for full semantics.

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

        rV   N)rO   r:   r$   )r   rW   s     r   r$   zAsyncReadWriteLock.release‰   s;   è è € ð iŠi˜œ
Ô*°%ˆiÑ8Ô8Ð8Ð8Ð8Ð8Ð8Ð8Ð8Ð8Ð8r   úfloat | Noneúbool | NoneúAsyncGenerator[None]c              óú   K  — |€| j         j        }|€| j         j        }|                      ||¬¦  «        ƒ d{V —† 	 dW V — |                      ¦   «         ƒ d{V —† dS # |                      ¦   «         ƒ d{V —† w xY w)aƒ  
        Async 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

        NrP   )r:   r3   r-   rR   r$   rS   s      r   Ú	read_lockzAsyncReadWriteLock.read_lock–   s®   è è € ð ˆ?Ø”jÔ(ˆGØÐØ”zÔ*ˆHØ×Ò °(ÐÑ;Ô;Ð;Ð;Ð;Ð;Ð;Ð;Ð;ð	!ØˆEˆEˆEˆEà—,’,‘.”.Ð Ð Ð Ð Ð Ð Ð Ð Ð ø$—,’,‘.”.Ð Ð Ð Ð Ð Ð Ð Ð øøøó   ½A ÁA:c              óú   K  — |€| j         j        }|€| j         j        }|                      ||¬¦  «        ƒ d{V —† 	 dW V — |                      ¦   «         ƒ d{V —† dS # |                      ¦   «         ƒ d{V —† w xY w)aˆ  
        Async 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

        NrP   )r:   r3   r-   rU   r$   rS   s      r   Ú
write_lockzAsyncReadWriteLock.write_lock«   s®   è è € ð ˆ?Ø”jÔ(ˆGØÐØ”zÔ*ˆHØ× Ò  °8Ð Ñ<Ô<Ð<Ð<Ð<Ð<Ð<Ð<Ð<ð	!ØˆEˆEˆEˆEà—,’,‘.”.Ð Ð Ð Ð Ð Ð Ð Ð Ð ø$—,’,‘.”.Ð Ð Ð Ð Ð Ð Ð Ð øøør^   c              ƒ  óœ   K  — |                       | j        j        ¦  «        ƒ d{V —† | j        r| j                             d¬¦  «         dS dS )z¤
        Release the lock (if held) and close the underlying SQLite connection.

        After calling this method, the lock instance is no longer usable.

        NF)Úwait)rO   r:   Úcloser<   r=   Úshutdownr   s    r   rc   zAsyncReadWriteLock.closeÀ   se   è è € ð iŠi˜œ
Ô(Ñ)Ô)Ð)Ð)Ð)Ð)Ð)Ð)Ð)ØÔð 	0ØŒN×#Ò#¨Ð#Ñ/Ô/Ð/Ð/Ð/ð	0ð 	0r   )r,   )r1   r2   r3   r4   r-   r5   r.   r5   r/   r6   r0   r7   r   r   )r   r>   )r   r4   )r   r5   )r   r6   )r   r7   )rD   rE   rF   rG   rH   rG   r   rG   )r3   r4   r-   r5   r   r   )rW   r5   r   r   r   )r3   rY   r-   rZ   r   r[   )r   r   )r&   r'   r(   r)   r   Úpropertyr1   r3   r-   r/   r0   rO   rR   rU   r$   r   r]   r`   rc   r*   r   r   r   r   &   sú  € € € € € ðð ð* ðGð
 Ø!Ø15Ø,0ðGð Gð Gð Gð Gð Gð ð$ð $ð $ñ „Xð$ð ð"ð "ð "ñ „Xð"ð ð#ð #ð #ñ „Xð#ð ðð ð ñ „Xðð ðð ð ñ „Xððdð dð dð dð;È$ð ;ð ;ð ;ð ;ð ;ð ;ð$;È4ð ;ð ;ð ;ð ;ð ;ð ;ð$ .3ð 9ð 9ð 9ð 9ð 9ð 9ð ð!ÐW[ð !ð !ð !ð !ð !ñ Ôð!ð( ð!ÐX\ð !ð !ð !ð !ð !ñ Ôð!ð(	0ð 	0ð 	0ð 	0ð 	0ð 	0r   r   )r)   Ú
__future__r   rJ   rM   Úconcurrent.futuresr   Ú
contextlibr   Útypingr   Ú_read_writer   ÚosÚcollections.abcr	   r
   Ú
concurrentr   Útypesr   r   r   Ú__all__r*   r   r   ú<module>rp      s3  ðØ KÐ Kà "Ð "Ð "Ð "Ð "Ð "à €€€Ø Ð Ð Ð Ø 1Ð 1Ð 1Ð 1Ð 1Ð 1Ø *Ð *Ð *Ð *Ð *Ð *Ø  Ð  Ð  Ð  Ð  Ð  à &Ð &Ð &Ð &Ð &Ð &àð $Ø€I€I€IØ8Ð8Ð8Ð8Ð8Ð8Ð8Ð8Ø"Ð"Ð"Ð"Ð"Ð"Ø#Ð#Ð#Ð#Ð#Ð#ð"ð "ð "ð "ð "ñ "ô "ð "ð$c0ð c0ð c0ð c0ð c0ñ c0ô c0ð c0ðN 'Øð€€€r   