§
    ‰+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
 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     ú^/home/wildlama/visual-decline/.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	 d0dddddœd1d„Zed2d„¦   «         Zed3d„¦   «         Zed4d„¦   «         Zed5d„¦   «         Z	ed6d„¦   «         Z
d7d „Zd0dd!œd8d#„Zd0dd!œd8d$„Zd%d&œd9d(„Zed:dd!œd;d,„¦   «         Zed:dd!œd;d-„¦   «         Zd<d.„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``. When ``None`` a dedicated single-thread executor is created
        and owned by this lock, ensuring every operation runs on the same thread (required for SQLite affinity); it
        is shut down by :meth:`close`. A caller-supplied executor is used as-is and never shut down here, so when no
        executor is passed remember to call :meth:`close` to release the owned one.

    .. 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__<   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_fileK   s   € ð ŒzÔ#Ð#r   c                ó   — | j         j        S )z:returns: the default timeout.)r:   r3   r   s    r   r3   zAsyncReadWriteLock.timeoutP   s   € ð ŒzÔ!Ð!r   c                ó   — | j         j        S )z1:returns: whether blocking is enabled by default.)r:   r-   r   s    r   r-   zAsyncReadWriteLock.blockingU   s   € ð ŒzÔ"Ð"r   c                ó   — | j         S )z<:returns: the event loop (or ``None`` for the running loop).)r;   r   s    r   r/   zAsyncReadWriteLock.loopZ   s   € ð ŒzÐr   úfutures.Executorc                ó   — | j         S )zi:returns: the executor used for ``run_in_executor`` (a dedicated single-thread one if none was supplied).)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   rE   rG   rI   r/   s        r   Ú_runzAsyncReadWriteLock._rund   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

        rQ   Nr   )rP   r:   Úacquire_readr   ©r   r3   r-   s      r   rS   zAsyncReadWriteLock.acquire_readh   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

        rQ   Nr   )rP   r:   Úacquire_writer   rT   s      r   rV   z AsyncReadWriteLock.acquire_writez   sH   è è € ð iŠi˜œ
Ô0°'ÀHˆiÑMÔMÐMÐMÐMÐMÐMÐMÐMÝ/°TÐ:Ñ:Ô:Ð:r   F©ÚforcerX   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``

        rW   N)rP   r:   r$   )r   rX   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

        NrQ   )r:   r3   r-   rS   r$   rT   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

        NrQ   )r:   r3   r-   rV   r$   rT   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)rP   r:   Úcloser<   r=   Úshutdownr   s    r   re   zAsyncReadWriteLock.closeÃ   se   è è € ð iŠi˜œ
Ô(Ñ)Ô)Ð)Ð)Ð)Ð)Ð)Ð)Ð)ØÔð 	0ØŒN×#Ò#¨Ð#Ñ/Ô/Ð/Ð/Ð/ð	0ð 	0r   c                ób   — t          | dd¦  «        r| j                             d¬¦  «         d S d S )Nr<   Frc   )Úgetattrr=   rf   r   s    r   Ú__del__zAsyncReadWriteLock.__del__Î   sB   € õ 4Ð)¨5Ñ1Ô1ð 	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   rC   )rE   rF   rG   rH   rI   rH   r   rH   )r3   r4   r-   r5   r   r   )rX   r5   r   r   r   )r3   rZ   r-   r[   r   r\   )r   r   )r&   r'   r(   r)   r   Úpropertyr1   r3   r-   r/   r0   rP   rS   rV   r$   r   r^   ra   re   ri   r*   r   r   r   r   &   s  € € € € € ðð ð0 ð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ð 0ð 0ð 0ð 0ð 0r   r   )r)   Ú
__future__r   rK   rN   Úconcurrent.futuresr   Ú
contextlibr   Útypingr   Ú_read_writer   ÚosÚcollections.abcr	   r
   Ú
concurrentr   Útypesr   r   r   Ú__all__r*   r   r   ú<module>ru      s3  ðØ KÐ Kà "Ð "Ð "Ð "Ð "Ð "à €€€Ø Ð Ð Ð Ø 1Ð 1Ð 1Ð 1Ð 1Ð 1Ø *Ð *Ð *Ð *Ð *Ð *Ø  Ð  Ð  Ð  Ð  Ð  à &Ð &Ð &Ð &Ð &Ð &àð $Ø€I€I€IØ8Ð8Ð8Ð8Ð8Ð8Ð8Ð8Ø"Ð"Ð"Ð"Ð"Ð"Ø#Ð#Ð#Ð#Ð#Ð#ð"ð "ð "ð "ð "ñ "ô "ð "ð$l0ð l0ð l0ð l0ð l0ñ l0ô l0ð l0ð` 'Øð€€€r   