
     iy                        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dS )zEAsync wrapper around :class:`ReadWriteLock` for use with ``asyncio``.    )annotationsN)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     d/srv/www/vhosts/g4struct/public_html/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 | Noner/   futures.Executor | Noner   r   c               R    t          ||||          | _        || _        || _        d S )N)r,   r-   )r   _lock_loop	_executor)r   r0   r2   r,   r-   r.   r/   s          r   r   zAsyncReadWriteLock.__init__8   s/     #9gWcddd

!r   strc                    | j         j        S )z$:returns: the path to the lock file.)r8   r0   r   s    r   r0   zAsyncReadWriteLock.lock_fileF   s     z##r   c                    | j         j        S )z:returns: the default timeout.)r8   r2   r   s    r   r2   zAsyncReadWriteLock.timeoutK   s     z!!r   c                    | j         j        S )z1:returns: whether blocking is enabled by default.)r8   r,   r   s    r   r,   zAsyncReadWriteLock.blockingP   s     z""r   c                    | j         S )z<:returns: the event loop (or ``None`` for the running loop).)r9   r   s    r   r.   zAsyncReadWriteLock.loopU   s     zr   c                    | j         S )z5:returns: the executor (or ``None`` for the default).)r:   r   s    r   r/   zAsyncReadWriteLock.executorZ   s     ~r   funcCallable[..., object]argsobjectkwargsc                   K   | j         pt          j                    }|                    | j        t          j        |g|R i |           d {V S r   )r9   asyncioget_running_looprun_in_executorr:   	functoolspartial)r   rA   rC   rE   r.   s        r   _runzAsyncReadWriteLock._run_   sb      z7W577))$.):KD:bSW: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

        rM   Nr   )rL   r8   acquire_readr   r   r2   r,   s      r   rO   zAsyncReadWriteLock.acquire_readc   sH       ii
/8i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

        rM   Nr   )rL   r8   acquire_writer   rP   s      r   rR   z AsyncReadWriteLock.acquire_writeu   sH       ii
0'HiMMMMMMMMM/T::::r   FforcerT   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``

        rS   N)rL   r8   r#   )r   rT   s     r   r#   zAsyncReadWriteLock.release   s;       ii
*%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

        NrM   )r8   r2   r,   rO   r#   rP   s      r   	read_lockzAsyncReadWriteLock.read_lock   s       ?j(Gz*H(;;;;;;;;;	!EEEE,,..         $,,..           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

        NrM   )r8   r2   r,   rR   r#   rP   s      r   
write_lockzAsyncReadWriteLock.write_lock   s       ?j(Gz*H  8 <<<<<<<<<	!EEEE,,..         $,,..        r[   c                T   K   |                      | j        j                   d{V  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.

        N)rL   r8   closer   s    r   r_   zAsyncReadWriteLock.close   s7       ii
()))))))))))r   )r+   )r0   r1   r2   r3   r,   r4   r-   r4   r.   r5   r/   r6   r   r   )r   r;   )r   r3   )r   r4   )r   r5   )r   r6   )rA   rB   rC   rD   rE   rD   r   rD   )r2   r3   r,   r4   r   r   )rT   r4   r   r   r   )r2   rV   r,   rW   r   rX   )r   r   )r%   r&   r'   r(   r   propertyr0   r2   r,   r.   r/   rL   rO   rR   r#   r   rZ   r]   r_   r)   r   r   r   r   %   s        * "
 !15,0" " " " " " $ $ $ X$ " " " X" # # # X#    X    Xd d d d;$ ; ; ; ; ; ;$;4 ; ; ; ; ; ;$ .3 9 9 9 9 9 9 !W[ ! ! ! ! ! !( !X\ ! ! ! ! ! !(* * * * * *r   r   )r(   
__future__r   rG   rJ   
contextlibr   typingr   _read_writer   oscollections.abcr   r	   
concurrentr
   typesr   r   r   __all__r)   r   r   <module>rj      s!   K K " " " " " "      * * * * * *             & & & & & & $III88888888""""""######" " " " " " " "$`* `* `* `* `* `* `* `*H 'r   