§
    dŠtjä,  ã                  ó  — d Z ddlmZ ddlZddlZddlZddlmZ ddlm	Z	m
Z
mZ ddlmZmZmZmZmZmZ ddlmZ e	rdd	lmZmZ dd
lmZ ddlmZ ddlmZ  e
d¦  «        Z ed¦  «        Z G d„ d¦  «        Z  G d„ d¦  «        Z!ddgZ"dS )zIAsync wrapper around :class:`SoftReadWriteLock` for use with ``asyncio``.é    )ÚannotationsN)Úasynccontextmanager)ÚTYPE_CHECKINGÚ	ParamSpecÚTypeVar)Ú_BackendOutcomeÚ_capture_callÚ_drain_futureÚ_future_resultÚ_raise_cancelled_errorÚ_wait_until_doneé   )ÚSoftReadWriteLock)ÚAsyncGeneratorÚCallable)Úfutures)ÚTracebackType)ÚAcquireReturnProxyÚ_PÚ_Rc            	      óB  — e Zd ZdZ	 d;ddddddddœd<d„Zed=d„¦   «         Zed>d„¦   «         Zed?d„¦   «         Zed@d„¦   «         Z	edAd„¦   «         Z
edBdd œdCd#„¦   «         ZedBdd œdCd$„¦   «         Z	 dBdd œdDd&„Z	 dBdd œdDd'„Zd(d)œdEd+„ZdFd,„ZdFd-„ZdGd0„ZdHd8„ZdId:„ZdS )JÚAsyncSoftReadWriteLockaÒ  
    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()``. The
    underlying :class:`SoftReadWriteLock` handles reentrancy, upgrade/downgrade rules, fork handling, heartbeat and
    TTL stale detection, and singleton behavior.

    :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 | NoneÚreturnÚNonec          	     óˆ   — t          j        ¦   «         | _        t          |||||||¬¦  «        | _        || _        |	| _        d S )N)r   r   r   r   r   )ÚosÚgetpidÚ_creator_pidr   Ú_lockÚ_loopÚ	_executor)
Úselfr!   r#   r   r   r   r   r   r   r    s
             úV/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/filelock/_soft_rw/_async.pyÚ__init__zAsyncSoftReadWriteLock.__init__7   sQ   € õ œI™KœKˆÔÝ&ØØØØ%Ø1Ø+Ø'ð
ñ 
ô 
ˆŒ
ð ˆŒ
Ø!ˆŒˆˆó    Ústrc                ó   — | j         j        S )z4The path to the lock file passed to the constructor.)r/   r!   ©r2   s    r3   r!   z AsyncSoftReadWriteLock.lock_fileQ   s   € ð ŒzÔ#Ð#r5   c                ó   — | j         j        S )z\The default timeout applied when ``acquire_read`` / ``acquire_write`` is called without one.)r/   r#   r8   s    r3   r#   zAsyncSoftReadWriteLock.timeoutV   s   € ð ŒzÔ!Ð!r5   c                ó   — | j         j        S )zYWhether ``acquire_*`` defaults to blocking; ``False`` makes contention raise immediately.)r/   r   r8   s    r3   r   zAsyncSoftReadWriteLock.blocking[   s   € ð ŒzÔ"Ð"r5   c                ó   — | j         S )zNThe event loop used for ``run_in_executor``, or ``None`` for the running loop.)r0   r8   s    r3   r   zAsyncSoftReadWriteLock.loop`   s   € ð ŒzÐr5   c                ó   — | j         S )zPThe executor used for ``run_in_executor``, or ``None`` for the default executor.)r1   r8   s    r3   r    zAsyncSoftReadWriteLock.executore   s   € ð Œ~Ðr5   ©r   úbool | NoneúAsyncGenerator[None]c              óÂ   K  — |                       ||¬¦  «        ƒ 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.

        :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)Úacquire_readÚrelease©r2   r#   r   s      r3   Ú	read_lockz AsyncSoftReadWriteLock.read_lockj   s�   è è € ð ×Ò °(ÐÑ;Ô;Ð;Ð;Ð;Ð;Ð;Ð;Ð;ð	!ØˆEˆEˆEˆEà—,’,‘.”.Ð Ð Ð Ð Ð Ð Ð Ð Ð ø�$—,’,‘.”.Ð Ð Ð Ð Ð Ð Ð Ð øøøó   ¡A ÁAc              óÂ   K  — |                       ||¬¦  «        ƒ 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.

        :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)Úacquire_writerB   rC   s      r3   Ú
write_lockz!AsyncSoftReadWriteLock.write_lock|   s�   è è € ð × Ò  °8Ð Ñ<Ô<Ð<Ð<Ð<Ð<Ð<Ð<Ð<ð	!ØˆEˆEˆEˆEà—,’,‘.”.Ð Ð Ð Ð Ð Ð Ð Ð Ð ø�$—,’,‘.”.Ð Ð Ð Ð Ð Ð Ð Ð øøørE   Ú$AsyncAcquireSoftReadWriteReturnProxyc             ƒ  óÂ   K  — |                       ¦   «          |                      t          j        | j        j        ||¬¦  «        ¦  «        ƒ d{V —† t          | ¬¦  «        S )a.  
        Acquire a shared read lock.

        See :meth:`SoftReadWriteLock.acquire_read` for reentrancy / upgrade / fork semantics. The blocking work runs
        inside ``run_in_executor`` so other coroutines on the same loop keep progressing 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=   N©Úlock)Ú_raise_if_inheritedÚ_run_acquireÚ	functoolsÚpartialr/   rA   rI   rC   s      r3   rA   z#AsyncSoftReadWriteLock.acquire_readŽ   si   è è € ð& 	× Ò Ñ"Ô"Ð"Ø×Ò¥	Ô 1°$´*Ô2IÈ7Ð]eÐ fÑ fÔ fÑgÔgÐgÐgÐgÐgÐgÐgÐgÝ3¸Ð>Ñ>Ô>Ð>r5   c             ƒ  óÂ   K  — |                       ¦   «          |                      t          j        | j        j        ||¬¦  «        ¦  «        ƒ d{V —† t          | ¬¦  «        S )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=   NrK   )rM   rN   rO   rP   r/   rG   rI   rC   s      r3   rG   z$AsyncSoftReadWriteLock.acquire_write¥   si   è è € ð& 	× Ò Ñ"Ô"Ð"Ø×Ò¥	Ô 1°$´*Ô2JÈGÐ^fÐ gÑ gÔ gÑhÔhÐhÐhÐhÐhÐhÐhÐhÝ3¸Ð>Ñ>Ô>Ð>r5   F©ÚforcerS   c             ƒ  ó”   K  — | j         t          j        ¦   «         k    r)|                      | j        j        |¬¦  «        ƒ d{V —† dS 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``

        rR   N)r.   r,   r-   Ú_runr/   rB   )r2   rS   s     r3   rB   zAsyncSoftReadWriteLock.release¼   sW   è è € ð Ô¥¤	¡¤Ò+Ð+Ø—)’)˜DœJÔ.°e�)Ñ<Ô<Ð<Ð<Ð<Ð<Ð<Ð<Ð<Ð<Ð<ð ,Ð+r5   c              ƒ  ó�   K  — | j         t          j        ¦   «         k    r'|                      | j        j        ¦  «        ƒ d{V —† dS dS )zRRelease any held lock and release the underlying filesystem resources. Idempotent.N)r.   r,   r-   rU   r/   Úcloser8   s    r3   rW   zAsyncSoftReadWriteLock.closeÈ   sQ   è è € àÔ¥¤	¡¤Ò+Ð+Ø—)’)˜DœJÔ,Ñ-Ô-Ð-Ð-Ð-Ð-Ð-Ð-Ð-Ð-Ð-ð ,Ð+r5   c                ór   — | j         t          j        ¦   «         k    rd| j        › d�}t	          |¦  «        ‚d S )NzAsyncSoftReadWriteLock on z4 was inherited across fork; construct a new instance)r.   r,   r-   r!   ÚRuntimeError)r2   Úmsgs     r3   rM   z*AsyncSoftReadWriteLock._raise_if_inheritedÍ   s>   € ØÔ¥¤	¡¤Ò+Ð+Øs¨t¬~ÐsÐsÐsˆCÝ˜sÑ#Ô#Ð#ð ,Ð+r5   Úacquireú Callable[[], AcquireReturnProxy]c              ƒ  óâ  K  — |                       |¦  «        }	 t          |¦  «        ƒ d {V —† n±# t          j        $ rŸ}	 t	          |¦  «        ƒ d {V —† n'# t
          $ r}t          ||¦  «         Y d }~nd }~ww xY w	 t	          |                       | j        j        ¦  «        ¦  «        ƒ d {V —† n'# t
          $ r}t          ||¦  «         Y d }~nd }~ww xY w‚ d }~ww xY wt          |¦  «         d S ©N)
Ú_submitr   ÚasyncioÚCancelledErrorr
   ÚBaseExceptionr   r/   rB   r   )r2   r[   Úacquire_futureÚcancellationÚerrors        r3   rN   z#AsyncSoftReadWriteLock._run_acquireÒ   sY  è è € ð
 Ÿš gÑ.Ô.ˆð	Ý" >Ñ2Ô2Ð2Ð2Ð2Ð2Ð2Ð2Ð2Ð2øÝÔ%ð 		ð 		ð 		ð<Ý# NÑ3Ô3Ð3Ð3Ð3Ð3Ð3Ð3Ð3Ð3øÝ ð <ð <ð <Ý& |°UÑ;Ô;Ð;Ð;Ð;Ð;Ð;Ð;øøøøð<øøøð<Ý# D§L¢L°´Ô1CÑ$DÔ$DÑEÔEÐEÐEÐEÐEÐEÐEÐEÐEøÝ ð <ð <ð <Ý& |°UÑ;Ô;Ð;Ð;Ð;Ð;Ð;Ð;øøøøð<øøøàøøøøð		øøøõ 	�~Ñ&Ô&Ð&Ð&Ð&sb   ™/ ¯C¿AÁCÁ
A9ÁA4Á/CÁ4A9Á9CÁ=2B0Â/CÂ0
CÂ:CÃ
CÃCÃCÃCÚfuncúCallable[_P, _R]Úargsú_P.argsÚkwargsú	_P.kwargsr   c              �  ó   K  —  | j         |g|¢R i |¤Ž}	 t          |¦  «        ƒ d {V —† nV# t          j        $ rD}	 t	          |¦  «        ƒ d {V —† n'# t
          $ r}t          ||¦  «         Y d }~nd }~ww xY w‚ d }~ww xY wt          |¦  «        S r^   )r_   r   r`   ra   r
   rb   r   r   )r2   rf   rh   rj   Úfuturerd   re   s          r3   rU   zAsyncSoftReadWriteLock._runæ   sì   è è € ð �”˜dÐ4 TÐ4Ð4Ð4¨VÐ4Ð4ˆð	Ý" 6Ñ*Ô*Ð*Ð*Ð*Ð*Ð*Ð*Ð*Ð*øÝÔ%ð 	ð 	ð 	ð<Ý# FÑ+Ô+Ð+Ð+Ð+Ð+Ð+Ð+Ð+Ð+øÝ ð <ð <ð <Ý& |°UÑ;Ô;Ð;Ð;Ð;Ð;Ð;Ð;øøøøð<øøøàøøøøð	øøøõ ˜fÑ%Ô%Ð%s8   •+ «A>»AÁA9Á
A5ÁA0Á+A9Á0A5Á5A9Á9A>ú#asyncio.Future[_BackendOutcome[_R]]c           	     óž   — | j         pt          j        ¦   «         }|                     | j        t
          t          j        |g|¢R i |¤Ž¦  «        S r^   )r0   r`   Úget_running_loopÚrun_in_executorr1   r	   rO   rP   )r2   rf   rh   rj   r   s        r3   r_   zAsyncSoftReadWriteLock._submitô   sQ   € ð ŒzÐ7�WÔ5Ñ7Ô7ˆØ×#Ò# D¤NµMÅ9ÔCTÐUYÐCkÐ\`ÐCkÐCkÐCkÐdjÐCkÐCkÑlÔlÐlr5   )r   )r!   r"   r#   r$   r   r%   r   r%   r   r$   r   r&   r   r$   r   r'   r    r(   r)   r*   )r)   r6   )r)   r$   )r)   r%   )r)   r'   )r)   r(   r^   )r#   r&   r   r>   r)   r?   )r#   r&   r   r>   r)   rI   )rS   r%   r)   r*   )r)   r*   )r[   r\   r)   r*   )rf   rg   rh   ri   rj   rk   r)   r   )rf   rg   rh   ri   rj   rk   r)   rn   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r4   Úpropertyr!   r#   r   r   r    r   rD   rH   rA   rG   rB   rW   rM   rN   rU   r_   © r5   r3   r   r   !   sF  € € € € € ðð ð0 ð"ð
 Ø!Ø$(Ø(,Ø#Ø15Ø,0ð"ð "ð "ð "ð "ð "ð4 ð$ð $ð $ñ „Xð$ð ð"ð "ð "ñ „Xð"ð ð#ð #ð #ñ „Xð#ð ðð ð ñ „Xðð ðð ð ñ „Xðð ð!ÐW[ð !ð !ð !ð !ð !ñ Ôð!ð" ð!ÐX\ð !ð !ð !ð !ð !ñ Ôð!ð$ '+ð?ØGKð?ð ?ð ?ð ?ð ?ð ?ð0 '+ð?ØGKð?ð ?ð ?ð ?ð ?ð ?ð. .3ð 
=ð 
=ð 
=ð 
=ð 
=ð 
=ð.ð .ð .ð .ð
$ð $ð $ð $ð
'ð 'ð 'ð 'ð(&ð &ð &ð &ðmð mð mð mð mð mr5   r   c                  ó*   — e Zd ZdZdd„Zdd„Zdd„ZdS )rI   zTAsync context-aware object that releases an :class:`AsyncSoftReadWriteLock` on exit.rL   r   r)   r*   c                ó   — || _         d S r^   rK   )r2   rL   s     r3   r4   z-AsyncAcquireSoftReadWriteReturnProxy.__init__þ   s   € ØˆŒ	ˆ	ˆ	r5   c              ƒ  ó   K  — | j         S r^   rK   r8   s    r3   Ú
__aenter__z/AsyncAcquireSoftReadWriteReturnProxy.__aenter__  s   è è € ØŒyÐr5   Úexc_typeútype[BaseException] | NoneÚ	exc_valueúBaseException | NoneÚ	tracebackúTracebackType | Nonec              ƒ  óH   K  — | j                              ¦   «         ƒ d {V —† d S r^   )rL   rB   )r2   r|   r~   r€   s       r3   Ú	__aexit__z.AsyncAcquireSoftReadWriteReturnProxy.__aexit__  s4   è è € ð Œi×ÒÑ!Ô!Ð!Ð!Ð!Ð!Ð!Ð!Ð!Ð!Ð!r5   N)rL   r   r)   r*   )r)   r   )r|   r}   r~   r   r€   r�   r)   r*   )rr   rs   rt   ru   r4   r{   rƒ   rw   r5   r3   rI   rI   û   sV   € € € € € Ø^Ð^ðð ð ð ðð ð ð ð"ð "ð "ð "ð "ð "r5   rI   )#ru   Ú
__future__r   r`   rO   r,   Ú
contextlibr   Útypingr   r   r   Úfilelock._asyncr   r	   r
   r   r   r   Ú_syncr   Úcollections.abcr   r   Ú
concurrentr   Útypesr   Úfilelock._apir   r   r   r   rI   Ú__all__rw   r5   r3   ú<module>rŽ      s³  ðØ OÐ Oà "Ð "Ð "Ð "Ð "Ð "à €€€Ø Ð Ð Ð Ø 	€	€	€	Ø *Ð *Ð *Ð *Ð *Ð *Ø 4Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4ðð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð %Ð $Ð $Ð $Ð $Ð $àð 1Ø8Ð8Ð8Ð8Ð8Ð8Ð8Ð8Ø"Ð"Ð"Ð"Ð"Ð"Ø#Ð#Ð#Ð#Ð#Ð#à0Ð0Ð0Ð0Ð0Ð0à€Yˆt�_„_€Ø€WˆT�]„]€ðWmð Wmð Wmð Wmð Wmñ Wmô Wmð Wmðt"ð "ð "ð "ð "ñ "ô "ð "ð& +Øð€€€r5   