
    *pj4                    6   S r SSKJr  SSKrSSKrSSKrSSKrSSKJr  SSK	J
r
  SSKJrJrJr  SSKJrJrJrJr  SS	KJrJrJrJrJrJr  SS
KJr  \(       a  SSKJrJr  SSK J!r!  SSK"J#r#  SSKJ$r$  \" S5      r%\" S5      r& " S S5      r' " S S5      r(SS/r)g)zEAsync wrapper around :class:`ReadWriteLock` for use with ``asyncio``.    )annotationsN)ThreadPoolExecutor)asynccontextmanager)TYPE_CHECKING	ParamSpecTypeVar   )_append_exception_context_ensure_current_process_fork_transition_register_fork_object)_BackendOutcome_capture_call_drain_future_future_result_raise_cancelled_error_wait_until_done)ReadWriteLock)AsyncGeneratorCallable)futures)TracebackType)AcquireReturnProxy_P_Rc                     \ 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S.S'S jjj5       r\S&SS.S'S jj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 jrS,S jrS-S jr        S.S jrS+S jr\S#S j5       rS+S jrS+S jrS+S jrSrg)/AsyncReadWriteLock(   a  
Async wrapper around :class:`ReadWriteLock` for use in ``asyncio`` applications.

This wrapper dispatches every blocking SQLite operation to a thread pool via ``loop.run_in_executor()`` because
Python's :mod:`sqlite3` module has no async API. It delegates reentrancy, upgrade/downgrade rules, and singleton
behavior 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`` this lock creates and owns a dedicated
    single-thread executor so every operation runs on the same thread (SQLite affinity requires this) and shuts it
    down in :meth:`close`. This lock uses a caller-supplied executor as-is and never shuts it down, so after passing
    no executor call :meth:`close` to release the owned one.

.. versionadded:: 3.21.0

TN)blockingis_singletonloopexecutorc               l   [         R                  " 5       nXpl        SU l        SU l        [        U 5        [        5          [        XX4S9U l        XPl	        US L U l
        U=(       d	    [        SS9U l        [         R                  " 5       U:w  a  Sn[        U5      e S S S 5        g ! , (       d  f       g = f)NF)r   r    r	   )max_workersz:AsyncReadWriteLock construction cannot continue after fork)osgetpid_creator_pid_fork_invalidated_closedr   r   r   _lock_loop_owns_executorr   	_executorRuntimeError)	self	lock_filetimeoutr   r    r!   r"   creator_pidmsgs	            V/var/www/html/pdf-tiff/venv/lib/python3.13/site-packages/filelock/_async_read_write.py__init__AsyncReadWriteLock.__init__>   s     iik'!&d#&yHhDJJ"*d"2D%J);)JDNyy{k)R"3'' *  s   AB%%
B3c                .    U R                   R                  $ )zThe path to the lock file.)r*   r0   r/   s    r4   r0   AsyncReadWriteLock.lock_fileV   s     zz###    c                .    U R                   R                  $ )zThe default timeout.)r*   r1   r8   s    r4   r1   AsyncReadWriteLock.timeout[   s     zz!!!r:   c                .    U R                   R                  $ )z'Whether blocking is enabled by default.)r*   r   r8   s    r4   r   AsyncReadWriteLock.blocking`   s     zz"""r:   c                    U R                   $ )z2The event loop (or ``None`` for the running loop).)r+   r8   s    r4   r!   AsyncReadWriteLock.loope   s     zzr:   c                    U R                   $ )z_The executor used for ``run_in_executor`` (a dedicated single-thread one if none was supplied).)r-   r8   s    r4   r"   AsyncReadWriteLock.executorj   s     ~~r:   r   c              R  #    Uc  U R                   R                  nUc  U R                   R                  nU R                  XS9I Sh  vN   Sn S7v    U R                  U5      I Sh  vN   g N'! [         a  nUne SnAff = f N! U R                  U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

NrC   )r*   r1   r   acquire_readBaseException_release_in_contextr/   r1   r   
body_errorerrors        r4   	read_lockAsyncReadWriteLock.read_locko   s      ?jj((Gzz**H;;;+/
	7
 **:666 	<  	J	 7$**:666`   AB'A/B'A1 B')B*B'1
B;A>>BB B'B$B B$$B'c              R  #    Uc  U R                   R                  nUc  U R                   R                  nU R                  XS9I Sh  vN   Sn S7v    U R                  U5      I Sh  vN   g N'! [         a  nUne SnAff = f N! U R                  U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

NrC   )r*   r1   r   acquire_writerF   rG   rH   s        r4   
write_lockAsyncReadWriteLock.write_lock   s      ?jj((Gzz**H   <<<+/
	7
 **:666 	=  	J	 7$**:666rM   c                   #     U R                  5       I S h  vN   g  N! [         a  nUb  [        X!5        e S nAff = f7fN)releaserF   r
   )r/   rI   release_errors      r4   rG   &AsyncReadWriteLock._release_in_context   s9     	,,.   	%)-D	s+   A   A  
=8=A c                  #    U R                  5         U R                  [        R                  " U R                  R
                  XS95      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

rC   Nlock)_raise_if_unusable_run_acquire	functoolspartialr*   rE    AsyncAcquireReadWriteReturnProxyr/   r1   r   s      r4   rE   AsyncReadWriteLock.acquire_read   sO      	!	 1 1$**2I2I7 fggg/T:: 	h   AAAAc                  #    U R                  5         U R                  [        R                  " U R                  R
                  XS95      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

rC   NrX   )rZ   r[   r\   r]   r*   rO   r^   r_   s      r4   rO    AsyncReadWriteLock.acquire_write   sO      	!	 1 1$**2J2JG ghhh/T:: 	ira   Fforcec                  #    [        5         U R                  (       a  g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``

Nrd   )r   
_inherited_runr*   rT   )r/   re   s     r4   rT   AsyncReadWriteLock.release   s7      	 !??ii

**%i888s   AAAAc                  #    [        5         U R                  (       a  gU R                  (       a  gU R                  U R                  R
                  5      n [        U5      I Sh  vN   [        U5        SU l        U R                  (       aF  [        R                  " [         R"                  " U R$                  R&                  SS95      I Sh  vN   gg Nn! [        R                   aU  n [        U5      I Sh  vN    O"! [         a  n[        X#5         SnAOSnAff = fSU l        U R                  5         e SnAff = f Nt7f)z
Release the lock (if held) and close the underlying SQLite connection.

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

NTwait)r   rg   r)   _submitr*   closer   asyncioCancelledErrorr   rF   r   _shutdown_owned_executorr   r,   	to_threadr\   r]   r-   shutdown)r/   close_futurecancellationrJ   s       r4   rn   AsyncReadWriteLock.close   s      	 !??<<||DJJ$4$45		"<000 	|$ ##I$5$5dnn6M6MTX$YZZZ  1%% 	<#L111  <&|;;<DL))+	 [sy   AEC %C&C *A#EEEC D?+D 9C<:D ?D: 
D
DD:DD::D??Ec                  #    U R                  U5      n [        U5      I S h  vN   [        U5        g  N! [        R                   a  n [	        U5      I S h  vN    O"! [
         a  n[        X45         S nAOS nAff = f [	        U R                  U R                  R                  5      5      I S h  vN    e ! [
         a  n[        X45         S nAe S nAff = fS nAff = f7frS   )
rm   r   ro   rp   r   rF   r   r*   rT   r   )r/   acquireacquire_futureru   rJ   s        r4   r[   AsyncReadWriteLock._run_acquire   s     g.	">222 	~& 3%% 		<#N333  <&|;;<<#DLL1C1C$DEEE  ! <&|;;<		s   C%6 46 C%6 C"A AA C 
A?*A:5C:A??C1B;4B75B;:C;
CCCCCC""C%c                   #    U R                   " U/UQ70 UD6n [        U5      I S h  vN   [        U5      $  N! [        R                   a=  n [	        U5      I S h  vN    e ! [
         a  n[        XV5         S nAe S nAff = fS nAff = f7frS   )rm   r   ro   rp   r   rF   r   r   )r/   funcargskwargsfutureru   rJ   s          r4   rh   AsyncReadWriteLock._run  s     d4T4V4	"6*** f%% +%% 	<#F+++  ! <&|;;<	sa   B: 8: B: BA$A A$#B$
B.A>9B>BBBBc           	         U R                   =(       d    [        R                  " 5       R                  U R                  [
        [        R                  " U/UQ70 UD65      $ rS   )r+   ro   get_running_looprun_in_executorr-   r   r\   r]   )r/   r|   r}   r~   s       r4   rm   AsyncReadWriteLock._submit  sK     

8g668IINNd4T4V4
 	
r:   c                Z    U R                   (       a  U R                  R                  SS9  g g )NFrk   )r,   r-   rs   r8   s    r4   rq   +AsyncReadWriteLock._shutdown_owned_executor"  s%    NN###/ r:   c                l    U R                   =(       d"    [        R                  " 5       U R                  :g  $ rS   )r(   r%   r&   r'   r8   s    r4   rg   AsyncReadWriteLock._inherited&  s$    %%I8I8I)IIr:   c                    [        5         U R                  (       a  SU R                   S3n[        U5      eU R                  (       a  Sn[
        R                  " U5      eg )NzAsyncReadWriteLock on z4 was invalidated by fork(); construct a new instancez$Cannot operate on a closed database.)r   rg   r0   r.   r)   sqlite3ProgrammingError)r/   r3   s     r4   rZ   %AsyncReadWriteLock._raise_if_unusable*  sP    !??*4>>*::noCs##<<8C**3// r:   c                    SU l         g )NT)r(   r8   s    r4   _reset_after_fork_in_child-AsyncReadWriteLock._reset_after_fork_in_child3  s
    !%r:   c                    [         R                  " 5       [        U SS 5      :X  a-  [        U SS5      (       a  U R                  R	                  SS9  g g g )Nr'   r,   Frk   )r%   r&   getattrr-   rs   r8   s    r4   __del__AsyncReadWriteLock.__del__6  sJ     99;'$=='$P`bgBhBhNN###/ Ci=r:   )r)   r'   r-   r(   r*   r+   r,   ))r0   zstr | os.PathLike[str]r1   floatr   boolr    r   r!    asyncio.AbstractEventLoop | Noner"   zfutures.Executor | NonereturnNone)r   str)r   r   )r   r   )r   r   )r   zfutures.ExecutorrS   )r1   zfloat | Noner   zbool | Noner   zAsyncGenerator[None])rI   BaseException | Noner   r   )r1   r   r   r   r   r^   )re   r   r   r   )r   r   )rx   z Callable[[], AcquireReturnProxy]r   r   )r|   Callable[_P, _R]r}   _P.argsr~   	_P.kwargsr   r   )r|   r   r}   r   r~   r   r   z#asyncio.Future[_BackendOutcome[_R]])__name__
__module____qualname____firstlineno____doc__r5   propertyr0   r1   r   r!   r"   r   rK   rP   rG   rE   rO   rT   rn   r[   rh   rm   rq   rg   rZ   r   r   __static_attributes__ r:   r4   r   r   (   s   0 (
 !15,0()( (
 ( ( /( *( 
(0 $ $ " " # #     7W[ 7 70 7X\ 7 70;$ ; ;&;4 ; ;& .3 9 [<' 
&
$
-4
@I
	,
0 J J0&0r:   r   c                  F    \ rS rSrSrSS jrS	S jr        S
S jrSrg)r^   i=  zEContext-aware object that releases the async read/write lock on exit.c                    Xl         g rS   rX   )r/   rY   s     r4   r5   )AsyncAcquireReadWriteReturnProxy.__init__@  s    	r:   c                "   #    U R                   $ 7frS   rX   r8   s    r4   
__aenter__+AsyncAcquireReadWriteReturnProxy.__aenter__C  s     yys   c                T   #    U R                   R                  5       I S h  vN   g  N7frS   )rY   rT   )r/   exc_type	exc_value	tracebacks       r4   	__aexit__*AsyncAcquireReadWriteReturnProxy.__aexit__F  s      ii!!!s   (&(rX   N)rY   r   r   r   )r   r   )r   ztype[BaseException] | Noner   r   r   zTracebackType | Noner   r   )	r   r   r   r   r   r5   r   r   r   r   r:   r4   r^   r^   =  s:    O"," (" (	"
 
"r:   r^   )*r   
__future__r   ro   r\   r%   r   concurrent.futuresr   
contextlibr   typingr   r   r   _apir
   r   r   r   _asyncr   r   r   r   r   r   _read_writer   collections.abcr   r   
concurrentr   typesr   r   r   r   r   r^   __all__r   r:   r4   <module>r      s    K "   	  1 * 4 4   '8"#(t_T]R0 R0j" "& 'r:   