
    Цiy                        S r SSKJr  SSKrSSKrSSKJr  SSKJr  SSK	J
r
  \(       a  SSKrSSKJrJr  SS	KJr  SS
KJr   " S S5      r " S S5      rSS/rg)zEAsync wrapper around :class:`ReadWriteLock` for use with ``asyncio``.    )annotationsN)asynccontextmanager)TYPE_CHECKING   )ReadWriteLock)AsyncGeneratorCallable)futures)TracebackTypec                  F    \ rS rSrSrSS jrS	S jr        S
S jrSrg) AsyncAcquireReadWriteReturnProxy   zEContext-aware object that releases the async read/write lock on exit.c                    Xl         g Nlock)selfr   s     Y/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/filelock/_async_read_write.py__init__)AsyncAcquireReadWriteReturnProxy.__init__   s    	    c                "   #    U R                   $ 7fr   r   r   s    r   
__aenter__+AsyncAcquireReadWriteReturnProxy.__aenter__   s     yys   c                T   #    U R                   R                  5       I S h  vN   g  N7fr   )r   release)r   exc_type	exc_value	tracebacks       r   	__aexit__*AsyncAcquireReadWriteReturnProxy.__aexit__   s      ii!!!s   (&(r   N)r   AsyncReadWriteLockreturnNone)r$   r#   )r   ztype[BaseException] | Noner   zBaseException | Noner    zTracebackType | Noner$   r%   )	__name__
__module____qualname____firstlineno____doc__r   r   r!   __static_attributes__ r   r   r   r      s:    O"," (" (	"
 
"r   r   c                  F   \ rS rSrSr SSSSSS.             SS jjjr\SS j5       r\SS j5       r\SS	 j5       r	\SS
 j5       r
\SS j5       rSS jrSSS.SS jjjrSSS.SS jjjrSS.S S jjr\S!SS.S"S jjj5       r\S!SS.S"S jjj5       rS#S jrSrg)$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executorc               :    [        XX4S9U l        XPl        X`l        g )N)r/   r0   )r   _lock_loop	_executor)r   	lock_filetimeoutr/   r0   r1   r2   s          r   r   AsyncReadWriteLock.__init__8   s     #9d

!r   c                .    U R                   R                  $ )z$:returns: the path to the lock file.)r4   r7   r   s    r   r7   AsyncReadWriteLock.lock_fileF   s     zz###r   c                .    U R                   R                  $ )z:returns: the default timeout.)r4   r8   r   s    r   r8   AsyncReadWriteLock.timeoutK   s     zz!!!r   c                .    U R                   R                  $ )z1:returns: whether blocking is enabled by default.)r4   r/   r   s    r   r/   AsyncReadWriteLock.blockingP   s     zz"""r   c                    U R                   $ )z<:returns: the event loop (or ``None`` for the running loop).)r5   r   s    r   r1   AsyncReadWriteLock.loopU   s     zzr   c                    U R                   $ )z5:returns: the executor (or ``None`` for the default).)r6   r   s    r   r2   AsyncReadWriteLock.executorZ   s     ~~r   c                   #    U R                   =(       d    [        R                  " 5       nUR                  U R                  [
        R                  " U/UQ70 UD65      I S h  vN $  N7fr   )r5   asyncioget_running_looprun_in_executorr6   	functoolspartial)r   funcargskwargsr1   s        r   _runAsyncReadWriteLock._run_   sP     zz7W557))$..):K:KD:bSW:b[a:bccccs   A A)"A'#A)r/   c               x   #    U R                  U R                  R                  XS9I Sh  vN   [        U S9$  N7f)a  
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

rO   Nr   )rM   r4   acquire_readr   r   r8   r/   s      r   rQ   AsyncReadWriteLock.acquire_readc   s8      ii

//iLLL/T:: 	M   (:8:c               x   #    U R                  U R                  R                  XS9I Sh  vN   [        U S9$  N7f)a  
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

rO   Nr   )rM   r4   acquire_writer   rR   s      r   rV    AsyncReadWriteLock.acquire_writeu   s8      ii

00'iMMM/T:: 	NrT   Fforcec               h   #    U R                  U R                  R                  US9I Sh  vN   g N7f)a
  
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``

rX   N)rM   r4   r   )r   rY   s     r   r   AsyncReadWriteLock.release   s'      ii

**%i888s   (202c                #    Uc  U R                   R                  nUc  U R                   R                  nU R                  XS9I Sh  vN    S7v   U R	                  5       I Sh  vN   g N# N! U R	                  5       I Sh  vN    f = f7f)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

NrO   )r4   r8   r/   rQ   r   rR   s      r   	read_lockAsyncReadWriteLock.read_lock   sw      ?jj((Gzz**H;;;	!,,.  	 	< !$,,.  H   ABA+BA/ B%A-&B-B/B
BB

Bc                #    Uc  U R                   R                  nUc  U R                   R                  nU R                  XS9I Sh  vN    S7v   U R	                  5       I Sh  vN   g N# N! U R	                  5       I Sh  vN    f = f7f)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

NrO   )r4   r8   r/   rV   r   rR   s      r   
write_lockAsyncReadWriteLock.write_lock   sw      ?jj((Gzz**H   <<<	!,,.  	 	= !$,,.  r_   c                j   #    U R                  U R                  R                  5      I Sh  vN   g N7f)z
Release the lock (if held) and close the underlying SQLite connection.

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

N)rM   r4   closer   s    r   rd   AsyncReadWriteLock.close   s#      ii

(()))s   )313)r6   r4   r5   ))r7   zstr | os.PathLike[str]r8   floatr/   boolr0   rh   r1    asyncio.AbstractEventLoop | Noner2   futures.Executor | Noner$   r%   )r$   str)r$   rg   )r$   rh   )r$   ri   )r$   rj   )rJ   zCallable[..., object]rK   objectrL   rl   r$   rl   )r8   rg   r/   rh   r$   r   )rY   rh   r$   r%   r   )r8   zfloat | Noner/   zbool | Noner$   zAsyncGenerator[None])r$   r%   )r&   r'   r(   r)   r*   r   propertyr7   r8   r/   r1   r2   rM   rQ   rV   r   r   r]   ra   rd   r+   r,   r   r   r#   r#   %   s;   * "
 !15,0")" "
 " " /" *" 
" $ $ " " # #    d;$ ; ;$;4 ; ;$ .3 9 !W[ ! !( !X\ ! !(*r   r#   )r*   
__future__r   rE   rH   
contextlibr   typingr   _read_writer   oscollections.abcr   r	   
concurrentr
   typesr   r   r#   __all__r,   r   r   <module>rw      sO    K "   *   &8"#" "$`* `*H 'r   