o
    #j "                     @  s   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 dZG dd dZddgZdS )zIAsync wrapper around :class:`SoftReadWriteLock` for use with ``asyncio``.    )annotationsN)asynccontextmanager)TYPE_CHECKING   )SoftReadWriteLock)AsyncGeneratorCallable)futures)TracebackTypec                   @  s.   e Zd ZdZdddZddd	ZdddZdS )$AsyncAcquireSoftReadWriteReturnProxyzTAsync context-aware object that releases an :class:`AsyncSoftReadWriteLock` on exit.lockAsyncSoftReadWriteLockreturnNonec                 C  s
   || _ d S Nr   )selfr    r   Y/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/filelock/_soft_rw/_async.py__init__   s   
z-AsyncAcquireSoftReadWriteReturnProxy.__init__c                   s   | j S r   r   r   r   r   r   
__aenter__   s   z/AsyncAcquireSoftReadWriteReturnProxy.__aenter__exc_typetype[BaseException] | None	exc_valueBaseException | None	tracebackTracebackType | Nonec                   s   | j  I d H  d S r   )r   release)r   r   r   r   r   r   r   	__aexit__   s   z.AsyncAcquireSoftReadWriteReturnProxy.__aexit__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   r      s
    

r   c                	   @  s   e Zd ZdZ	d@dddddddddAddZedBddZedCddZedDd d!ZedEd"d#Z	edFd$d%Z
	dGdd&dHd)d*Z	dGdd&dHd+d,Zd-d.dId0d1ZedGdd&dJd3d4ZedGdd&dJd5d6ZdKd7d8ZdLd>d?ZdS )Mr   a  
    Async wrapper around :class:`SoftReadWriteLock` for ``asyncio`` applications.

    The sync class's blocking filesystem operations run on a thread pool via ``loop.run_in_executor()``.
    Reentrancy, upgrade/downgrade rules, fork handling, heartbeat and TTL stale detection, and singleton
    behavior are delegated to the underlying :class:`SoftReadWriteLock`.

    :param lock_file: path to the lock file; sidecar state/write/readers live next to it
    :param timeout: maximum wait time in seconds; ``-1`` means block indefinitely
    :param blocking: if ``False``, raise :class:`~filelock.Timeout` immediately on contention
    :param is_singleton: if ``True``, reuse existing :class:`SoftReadWriteLock` instances per resolved path
    :param heartbeat_interval: seconds between heartbeat refreshes; default 30 s
    :param stale_threshold: seconds of mtime inactivity before a marker is stale; defaults to ``3 * heartbeat_interval``
    :param poll_interval: seconds between acquire retries under contention; default 0.25 s
    :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.27.0

    Tg      >@Ng      ?)blockingis_singletonheartbeat_intervalstale_thresholdpoll_intervalloopexecutor	lock_filestr | os.PathLike[str]timeoutfloatr%   boolr&   r'   r(   float | Noner)   r*    asyncio.AbstractEventLoop | Noner+   futures.Executor | Noner   r   c          
   	   C  s(   t |||||||d| _|| _|	| _d S )N)r%   r&   r'   r(   r)   )r   _lock_loop	_executor)
r   r,   r.   r%   r&   r'   r(   r)   r*   r+   r   r   r   r   ;   s   	
zAsyncSoftReadWriteLock.__init__strc                 C     | j jS )z>:returns: the path to the lock file passed to the constructor.)r4   r,   r   r   r   r   r,   T      z AsyncSoftReadWriteLock.lock_filec                 C  r8   )zf:returns: the default timeout applied when ``acquire_read`` / ``acquire_write`` is called without one.)r4   r.   r   r   r   r   r.   Y   r9   zAsyncSoftReadWriteLock.timeoutc                 C  r8   )zc:returns: whether ``acquire_*`` defaults to blocking; ``False`` makes contention raise immediately.)r4   r%   r   r   r   r   r%   ^   r9   zAsyncSoftReadWriteLock.blockingc                 C     | j S )zX:returns: the event loop used for ``run_in_executor``, or ``None`` for the running loop.)r5   r   r   r   r   r*   c      zAsyncSoftReadWriteLock.loopc                 C  r:   )zZ:returns: the executor used for ``run_in_executor``, or ``None`` for the default executor.)r6   r   r   r   r   r+   h   r;   zAsyncSoftReadWriteLock.executorr%   bool | Noner   c                  &   | j | jj||dI dH  t| dS )aC  
        Acquire a shared read lock.

        See :meth:`SoftReadWriteLock.acquire_read` for the full reentrancy / upgrade / fork semantics. The blocking
        work runs inside ``run_in_executor`` so other coroutines on the same loop continue to progress while this
        call waits.

        :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

        :returns: a proxy usable as an async context manager to release the lock

        :raises RuntimeError: if a write lock is already held, if this instance was invalidated by
            :func:`os.fork`, or if :meth:`close` was called
        :raises Timeout: if the lock cannot be acquired within *timeout* seconds

        r<   Nr   )_runr4   acquire_readr   r   r.   r%   r   r   r   r@   m   s   
z#AsyncSoftReadWriteLock.acquire_readc                  r>   )a  
        Acquire an exclusive write lock.

        See :meth:`SoftReadWriteLock.acquire_write` for the two-phase writer-preferring semantics. The blocking
        work runs inside ``run_in_executor``.

        :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

        :returns: a proxy usable as an async context manager to release the lock

        :raises RuntimeError: if a read lock is already held, if a write lock is held by a different thread, if
            this instance was invalidated by :func:`os.fork`, or if :meth:`close` was called
        :raises Timeout: if the lock cannot be acquired within *timeout* seconds

        r<   Nr   )r?   r4   acquire_writer   rA   r   r   r   rB      s   
z$AsyncSoftReadWriteLock.acquire_writeFforcerD   c                  s   | j | jj|dI dH  dS )z
        Release one level of the current lock.

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

        rC   N)r?   r4   r   )r   rD   r   r   r   r      s   	zAsyncSoftReadWriteLock.releaseAsyncGenerator[None]c                C B   | j ||dI dH  zdV  W |  I dH  dS |  I dH  w )a  
        Async context manager that acquires and releases a shared read lock.

        :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

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

        r<   N)r@   r   rA   r   r   r   	read_lock   
   "z AsyncSoftReadWriteLock.read_lockc                C rF   )a  
        Async context manager that acquires and releases an exclusive write lock.

        :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

        :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

        r<   N)rB   r   rA   r   r   r   
write_lock   rH   z!AsyncSoftReadWriteLock.write_lockc                   s   |  | jjI dH  dS )zRRelease any held lock and release the underlying filesystem resources. Idempotent.N)r?   r4   closer   r   r   r   rJ      s   zAsyncSoftReadWriteLock.closefuncCallable[..., object]argsobjectkwargsc                   s8   | j pt }|| jtj|g|R i |I d H S r   )r5   asyncioZget_running_loopZrun_in_executorr6   	functoolspartial)r   rK   rM   rO   r*   r   r   r   r?      s   (zAsyncSoftReadWriteLock._run)r$   )r,   r-   r.   r/   r%   r0   r&   r0   r'   r/   r(   r1   r)   r/   r*   r2   r+   r3   r   r   )r   r7   )r   r/   )r   r0   )r   r2   )r   r3   r   )r.   r1   r%   r=   r   r   )rD   r0   r   r   )r.   r1   r%   r=   r   rE   )r   r   )rK   rL   rM   rN   rO   rN   r   rN   )r    r!   r"   r#   r   propertyr,   r.   r%   r*   r+   r@   rB   r   r   rG   rI   rJ   r?   r   r   r   r   r   %   sJ    
r   )r#   
__future__r   rP   rQ   
contextlibr   typingr   Z_syncr   oscollections.abcr   r   Z
concurrentr	   typesr
   r   r   __all__r   r   r   r   <module>   s$     /