§
    Ò¬¸jß3  ã                  ó.  — 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mZ ddlmZ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 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ÚLiteralÚ	ParamSpecÚTypeVar)Ú_BackendOutcomeÚ_capture_callÚ_drain_futureÚ_future_resultÚ_raise_cancelled_errorÚ_task_owners_forÚ_wait_until_doneé   )ÚSoftReadWriteLock)ÚAsyncGeneratorÚCallable)Úfutures)ÚTracebackType)ÚAcquireReturnProxy)ÚLeaseCompromiseÚ_PÚ_Rc            
      ó|  — e Zd ZdZ	 dDdddddddddœdEd„ZedFd„¦   «         ZedGd„¦   «         ZedHd„¦   «         ZedId!„¦   «         Z	edJd#„¦   «         Z
edKd$„¦   «         ZedLd%„¦   «         ZedMdd&œdNd)„¦   «         ZedMdd&œdNd*„¦   «         Z	 dMdd&œdOd,„Z	 dMdd&œdOd-„ZdPd0„Zd1d2œdQd4„ZdRd5„ZdRd6„ZdSd9„ZdTdA„ZdUdC„ZdS )VÚ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()``. Each
    ``asyncio`` task owns its own hold. Tasks share a read lock, and a task asking for the write lock waits until the
    other holders release, with waiting writers ahead of new readers. Upgrading or downgrading a held lock raises
    :class:`RuntimeError`. The underlying :class:`SoftReadWriteLock` handles forks, the heartbeat, and stale eviction.
    Singleton wrappers share one sync lock and its task holds.

    :param lock_file: path to the lock file; the protocol directory lives next to it as ``<lock_file>.rw``
    :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 a holder record may stay unchanged before a contender evicts it; defaults to
        ``3 * heartbeat_interval``
    :param poll_interval: seconds between acquire retries under contention; default 0.25 s
    :param on_compromise: called from the heartbeat thread with a :class:`~filelock.LeaseCompromise` when the hold is
        lost
    :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Úon_compromiseÚloopÚexecutorÚ	lock_fileústr | os.PathLike[str]ÚtimeoutÚfloatr   Úboolr   r   r    úfloat | Noner!   r"   ú(Callable[[LeaseCompromise], None] | Noner#   ú asyncio.AbstractEventLoop | Noner$   úfutures.Executor | NoneÚreturnÚNonec          
     ó¼   — t          j        ¦   «         | _        t          ||||||||¬¦  «        | _        t          | j        ¦  «        | _        |	| _        |
| _        d S )N)r   r   r   r    r!   r"   )	ÚosÚgetpidÚ_creator_pidr   Ú_lockr   Ú_ownersÚ_loopÚ	_executor)Úselfr%   r'   r   r   r   r    r!   r"   r#   r$   s              úh/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/filelock/_soft_rw/_async.pyÚ__init__zAsyncSoftReadWriteLock.__init__>   se   € õ œI™KœKˆÔÝ&ØØØØ%Ø1Ø+Ø'Ø'ð	
ñ 	
ô 	
ˆŒ
õ (¨¬
Ñ3Ô3ˆŒØˆŒ
Ø!ˆŒˆˆó    Ústrc                ó   — | j         j        S )z4The path to the lock file passed to the constructor.)r4   r%   ©r8   s    r9   r%   z AsyncSoftReadWriteLock.lock_file[   s   € ð ŒzÔ#Ð#r;   c                ó   — | j         j        S )z\The default timeout applied when ``acquire_read`` / ``acquire_write`` is called without one.)r4   r'   r>   s    r9   r'   zAsyncSoftReadWriteLock.timeout`   s   € ð ŒzÔ!Ð!r;   c                ó   — | j         j        S )zYWhether ``acquire_*`` defaults to blocking; ``False`` makes contention raise immediately.)r4   r   r>   s    r9   r   zAsyncSoftReadWriteLock.blockinge   s   € ð ŒzÔ"Ð"r;   ú
int | Nonec                ó   — | j         j        S )z_The generation the current hold was granted at, a fencing token; ``None`` when no lock is held.)r4   Ú
generationr>   s    r9   rC   z!AsyncSoftReadWriteLock.generationj   ó   € ð ŒzÔ$Ð$r;   úLeaseCompromise | Nonec                ó   — | j         j        S )z;How the current hold was lost, or ``None`` while it stands.)r4   Ú
compromiser>   s    r9   rG   z!AsyncSoftReadWriteLock.compromiseo   rD   r;   c                ó   — | j         S )zNThe event loop used for ``run_in_executor``, or ``None`` for the running loop.)r6   r>   s    r9   r#   zAsyncSoftReadWriteLock.loopt   s   € ð ŒzÐr;   c                ó   — | j         S )zPThe executor used for ``run_in_executor``, or ``None`` for the default executor.)r7   r>   s    r9   r$   zAsyncSoftReadWriteLock.executory   s   € ð Œ~Ðr;   ©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 the calling task already holds the write lock
        :raises Timeout: if the lock cannot be acquired within *timeout* seconds

        rJ   N)Úacquire_readÚrelease©r8   r'   r   s      r9   Ú	read_lockz AsyncSoftReadWriteLock.read_lock~   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 the calling task already holds the read lock
        :raises Timeout: if the lock cannot be acquired within *timeout* seconds

        rJ   N)Úacquire_writerO   rP   s      r9   Ú
write_lockz!AsyncSoftReadWriteLock.write_lock�   s�   è è € ð × Ò  °8Ð Ñ<Ô<Ð<Ð<Ð<Ð<Ð<Ð<Ð<ð	!ØˆEˆEˆEˆEà—,’,‘.”.Ð Ð Ð Ð Ð Ð Ð Ð Ð ø�$—,’,‘.”.Ð Ð Ð Ð Ð Ð Ð Ð øøørR   Ú$AsyncAcquireSoftReadWriteReturnProxyc             ƒ  óŠ   K  — |                       ¦   «          |                      d||¬¦  «        ƒ 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 the calling task already holds the write lock, 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

        ÚreadrJ   N©Úlock©Ú_raise_if_inheritedÚ_acquirerV   rP   s      r9   rN   z#AsyncSoftReadWriteLock.acquire_read¢   sU   è è € ð& 	× Ò Ñ"Ô"Ð"Ø�mŠm˜F G°hˆmÑ?Ô?Ð?Ð?Ð?Ð?Ð?Ð?Ð?Ý3¸Ð>Ñ>Ô>Ð>r;   c             ƒ  óŠ   K  — |                       ¦   «          |                      d||¬¦  «        ƒ d{V —† t          | ¬¦  «        S )aò  
        Acquire an exclusive write lock.

        See :meth:`SoftReadWriteLock.acquire_write` for the 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 the calling task already holds the read lock, 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

        ÚwriterJ   NrY   r[   rP   s      r9   rT   z$AsyncSoftReadWriteLock.acquire_write¹   sU   è è € ð& 	× Ò Ñ"Ô"Ð"Ø�mŠm˜G W°xˆmÑ@Ô@Ð@Ð@Ð@Ð@Ð@Ð@Ð@Ý3¸Ð>Ñ>Ô>Ð>r;   ÚmodeúLiteral['read', 'write']c             ƒ  óì   ‡ ‡‡K  — ‰€‰ j         j        n‰Š|dk    r‰ j         j        n‰ j         j        Šdˆˆ ˆfd„}‰ j                             ||€‰ j         j        n|‰‰ j        |¬¦  «        ƒ d {V —† d S )	NrX   Ú	remainingr(   r.   r/   c              “  ól   •K  — ‰                      t          j        ‰| ‰¬¦  «        ¦  «        ƒ d {V —† d S )NrJ   )Ú_run_acquireÚ	functoolsÚpartial)rc   r   r8   Úsync_acquires    €€€r9   Úenterz.AsyncSoftReadWriteLock._acquire.<locals>.enterÔ   sF   øè è € Ø×#Ò#¥IÔ$5°lÀIÐX`Ð$aÑ$aÔ$aÑbÔbÐbÐbÐbÐbÐbÐbÐbÐbÐbr;   )r'   r   r%   ri   )rc   r(   r.   r/   )r4   r   rN   rT   r5   Úacquirer'   r%   )r8   r`   r'   r   ri   rh   s   `  ` @r9   r]   zAsyncSoftReadWriteLock._acquireÐ   sÑ   øøøè è € Ø*2Ð*:�4”:Ô&Ð&ÀˆØ26¸&².°.�t”zÔ.Ð.ÀdÄjÔF^ˆð	cð 	cð 	cð 	cð 	cð 	cð 	cð 	cð Œl×"Ò"ØØ*1¨/�D”JÔ&Ð&¸wØØ”nØð #ñ 
ô 
ð 	
ð 	
ð 	
ð 	
ð 	
ð 	
ð 	
ð 	
ð 	
r;   F)Úforcerk   c             ƒ  óÚ   K  — | j         t          j        ¦   «         k    rL| j                             || j        t          j        | j        | j	        j        ¦  «        ¬¦  «        ƒ d{V —† dS dS )a4  
        Release one level of the calling task's hold.

        The wrapper releases the lock once no task holds it.

        :param force: if ``True``, drop the calling task's whole hold at any nesting level

        :raises RuntimeError: if the calling task holds no lock and *force* is ``False``

        )rk   r%   ÚleaveN)
r3   r1   r2   r5   rO   r%   rf   rg   Ú_runr4   )r8   rk   s     r9   rO   zAsyncSoftReadWriteLock.releaseß   sŠ   è è € ð Ô¥¤	¡¤Ò+Ð+Ø”,×&Ò&Ø t¤~½YÔ=NÈtÌyÐZ^ÔZdÔZlÑ=mÔ=mð 'ñ ô ð ð ð ð ð ð ð ð ð ð ,Ð+r;   c              ƒ  óÂ   K  — | j         t          j        ¦   «         k    r@|                      | j        j        ¦  «        ƒ d{V —† | j                             ¦   «          dS dS )zRRelease any held lock and release the underlying filesystem resources. Idempotent.N)r3   r1   r2   rn   r4   Úcloser5   Úresetr>   s    r9   rp   zAsyncSoftReadWriteLock.closeï   se   è è € àÔ¥¤	¡¤Ò+Ð+Ø—)’)˜DœJÔ,Ñ-Ô-Ð-Ð-Ð-Ð-Ð-Ð-Ð-ØŒL×ÒÑ Ô Ð Ð Ð ð ,Ð+r;   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)r3   r1   r2   r%   ÚRuntimeError)r8   Úmsgs     r9   r\   z*AsyncSoftReadWriteLock._raise_if_inheritedõ   s>   € ØÔ¥¤	¡¤Ò+Ð+Øs¨t¬~ÐsÐsÐsˆCÝ˜sÑ#Ô#Ð#ð ,Ð+r;   rj   ú 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   r4   rO   r   )r8   rj   Úacquire_futureÚcancellationÚerrors        r9   re   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 rw   )rx   r   ry   rz   r   r{   r   r   )r8   r   r�   rƒ   Úfuturer}   r~   s          r9   rn   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 rw   )r6   ry   Úget_running_loopÚrun_in_executorr7   r
   rf   rg   )r8   r   r�   rƒ   r#   s        r9   rx   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Ðlr;   )r   )r%   r&   r'   r(   r   r)   r   r)   r   r(   r    r*   r!   r(   r"   r+   r#   r,   r$   r-   r.   r/   )r.   r<   )r.   r(   )r.   r)   )r.   rA   )r.   rE   )r.   r,   )r.   r-   rw   )r'   r*   r   rK   r.   rL   )r'   r*   r   rK   r.   rV   )r`   ra   r'   r*   r   rK   r.   r/   )rk   r)   r.   r/   )r.   r/   )rj   ru   r.   r/   )r   r€   r�   r‚   rƒ   r„   r.   r   )r   r€   r�   r‚   rƒ   r„   r.   r‡   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r:   Úpropertyr%   r'   r   rC   rG   r#   r$   r   rQ   rU   rN   rT   r]   rO   rp   r\   re   rn   rx   © r;   r9   r   r   #   s�  € € € € € ðð ð: ð"ð
 Ø!Ø$(Ø(,Ø#ØBFØ15Ø,0ð"ð "ð "ð "ð "ð "ð: ð$ð $ð $ñ „Xð$ð ð"ð "ð "ñ „Xð"ð ð#ð #ð #ñ „Xð#ð ð%ð %ð %ñ „Xð%ð ð%ð %ð %ñ „Xð%ð ðð ð ñ „Xðð ðð ð ñ „Xðð ð!ÐW[ð !ð !ð !ð !ð !ñ Ôð!ð" ð!ÐX\ð !ð !ð !ð !ð !ñ Ôð!ð$ '+ð?ØGKð?ð ?ð ?ð ?ð ?ð ?ð0 '+ð?ØGKð?ð ?ð ?ð ?ð ?ð ?ð.
ð 
ð 
ð 
ð .3ð ð ð ð ð ð ð !ð !ð !ð !ð$ð $ð $ð $ð
'ð 'ð 'ð 'ð(&ð &ð &ð &ðmð mð mð mð mð mr;   r   c                  ó*   — e Zd ZdZdd„Zdd„Zdd„ZdS )rV   zTAsync context-aware object that releases an :class:`AsyncSoftReadWriteLock` on exit.rZ   r   r.   r/   c                ó   — || _         d S rw   rY   )r8   rZ   s     r9   r:   z-AsyncAcquireSoftReadWriteReturnProxy.__init__&  s   € ØˆŒ	ˆ	ˆ	r;   c              ƒ  ó   K  — | j         S rw   rY   r>   s    r9   Ú
__aenter__z/AsyncAcquireSoftReadWriteReturnProxy.__aenter__)  s   è è € ØŒyÐr;   Úexc_typeútype[BaseException] | NoneÚ	exc_valueúBaseException | NoneÚ	tracebackúTracebackType | Nonec              ƒ  óH   K  — | j                              ¦   «         ƒ d {V —† d S rw   )rZ   rO   )r8   r•   r—   r™   s       r9   Ú	__aexit__z.AsyncAcquireSoftReadWriteReturnProxy.__aexit__,  s4   è è € ð Œi×ÒÑ!Ô!Ð!Ð!Ð!Ð!Ð!Ð!Ð!Ð!Ð!r;   N)rZ   r   r.   r/   )r.   r   )r•   r–   r—   r˜   r™   rš   r.   r/   )r‹   rŒ   r�   rŽ   r:   r”   rœ   r�   r;   r9   rV   rV   #  sV   € € € € € Ø^Ð^ðð ð ð ðð ð ð ð"ð "ð "ð "ð "ð "r;   rV   )'rŽ   Ú
__future__r   ry   rf   r1   Ú
contextlibr   Útypingr   r   r   r   Úfilelock._asyncr	   r
   r   r   r   r   r   Ú_syncr   Úcollections.abcr   r   Ú
concurrentr   Útypesr   Úfilelock._apir   Úfilelock._leaser   r   r   r   rV   Ú__all__r�   r;   r9   ú<module>r¨      sÕ  ðØ OÐ Oà "Ð "Ð "Ð "Ð "Ð "à €€€Ø Ð Ð Ð Ø 	€	€	€	Ø *Ð *Ð *Ð *Ð *Ð *Ø =Ð =Ð =Ð =Ð =Ð =Ð =Ð =Ð =Ð =Ð =Ð =ðð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð %Ð $Ð $Ð $Ð $Ð $àð 0Ø8Ð8Ð8Ð8Ð8Ð8Ð8Ð8Ø"Ð"Ð"Ð"Ð"Ð"Ø#Ð#Ð#Ð#Ð#Ð#à0Ð0Ð0Ð0Ð0Ð0Ø/Ð/Ð/Ð/Ð/Ð/à€Yˆt�_„_€Ø€WˆT�]„]€ð}mð }mð }mð }mð }mñ }mô }mð }mð@"ð "ð "ð "ð "ñ "ô "ð "ð& +Øð€€€r;   