Ë
    °ëjÃB  ã                  ó<  — d Z ddlmZ g d¢Zddl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mZ ddlmZmZmZmZmZmZmZmZ ddlmZ dd	lmZ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-y)zIAsync wrapper around :class:`SoftReadWriteLock` for use with ``asyncio``.é    )Úannotations)Úasynciozfilelock._asynczfilelock._errorÚ	functoolsÚ	threadingN)Úasynccontextmanager)ÚTYPE_CHECKINGÚFinalÚLiteralÚ	ParamSpecÚTypeVar)Ú_TASKS_THREAD_IDÚ_BackendOutcomeÚ_capture_callÚ_drain_futureÚ_future_resultÚ_raise_cancelled_errorÚ_task_owners_forÚ_wait_until_done)ÚTimeout)ÚSoftReadWriteLockÚ_lost_hold_error)ÚAsyncGeneratorÚCallable)Úfutures)ÚTracebackType)ÚAcquireReturnProxy)ÚLeaseCompromiseÚ_PÚ_Rc            
      óš  — e Zd ZdZ	 d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d$d„«       Z
ed%d„«       Zed&d„«       Zed'ddœd(d„«       Zed'ddœd(d„«       Z	 d'ddœ	 	 	 	 	 d)d„Z	 d'ddœ	 	 	 	 	 d)d„Zd*d„Zddœd+d„Zd,d„Zd,d„Zd"d„Zd,d„Zd-d„Z	 	 	 	 	 	 	 	 d.d„Zy)/Ú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, and closing one ends only the holds taken through it.

    :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Úexecutorc          
     óò   — t        j                  «       | _        d| _        | | _        t        «       | _        t        ||||||||¬«      | _        t        | j                  «      | _
        |	| _        |
| _        y )NF)r"   r#   r$   r%   r&   r'   )ÚosÚgetpidÚ_creator_pidÚ_closedÚ_owns_backendÚobjectÚ_viar   Ú_lockr   Ú_ownersÚ_loopÚ	_executor)ÚselfÚ	lock_fileÚtimeoutr"   r#   r$   r%   r&   r'   r(   r)   s              úe/home/oem/CyberBrain26-unified/dev-env/.venv/lib/python3.12/site-packages/filelock/_soft_rw/_async.pyÚ__init__zAsyncSoftReadWriteLock.__init__B   sq   € ô ŸI™I›KˆÔØˆŒØ!-Ð-ˆÔä!›8ˆŒ	Ü&ØØØØ%Ø1Ø+Ø'Ø'ô	
ˆŒ
ô (¨¯
©
Ó3ˆŒØˆŒ
Ø!ˆ�ó    c                ó.   — | j                   j                  S )z4The path to the lock file passed to the constructor.)r2   r7   ©r6   s    r9   r7   z AsyncSoftReadWriteLock.lock_filec   s   € ð �z‰z×#Ñ#Ð#r;   c                ó.   — | j                   j                  S )z\The default timeout applied when ``acquire_read`` / ``acquire_write`` is called without one.)r2   r8   r=   s    r9   r8   zAsyncSoftReadWriteLock.timeouth   s   € ð �z‰z×!Ñ!Ð!r;   c                ó.   — | j                   j                  S )zYWhether ``acquire_*`` defaults to blocking; ``False`` makes contention raise immediately.)r2   r"   r=   s    r9   r"   zAsyncSoftReadWriteLock.blockingm   s   € ð �z‰z×"Ñ"Ð"r;   c                ó.   — | j                   j                  S )z_The generation the current hold was granted at, a fencing token; ``None`` when no lock is held.)r2   Ú
generationr=   s    r9   rA   z!AsyncSoftReadWriteLock.generationr   ó   € ð �z‰z×$Ñ$Ð$r;   c                ó.   — | j                   j                  S )zhHow the current hold was lost, or ``None`` while it stands; acquiring raises until the hold is released.)r2   Ú
compromiser=   s    r9   rD   z!AsyncSoftReadWriteLock.compromisew   rB   r;   c                ó   — | j                   S )zNThe event loop used for ``run_in_executor``, or ``None`` for the running loop.)r4   r=   s    r9   r(   zAsyncSoftReadWriteLock.loop|   s   € ð �z‰zÐr;   c                ó   — | j                   S )zPThe executor used for ``run_in_executor``, or ``None`` for the default executor.)r5   r=   s    r9   r)   zAsyncSoftReadWriteLock.executor�   s   € ð �~‰~Ðr;   ©r"   c              óÂ   K  — | j                  ||¬«      ƒ d{  –—†  	 d­–— | j                  «       ƒ d{  –—†  y7 Œ#7 Œ# | j                  «       ƒ d{  –—†7   w xY w­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
        :raises TypeError: if *timeout* is a :class:`bool` or not a real number, or *blocking* is not a :class:`bool`
        :raises ValueError: if a blocking call gets a ``nan`` *timeout* or a negative one other than ``-1``

        rG   N)Úacquire_readÚrelease©r6   r8   r"   s      r9   Ú	read_lockz AsyncSoftReadWriteLock.read_lock†   sR   è ø€ ð ×Ñ °(ÐÓ;×;Ð;ð	!Üà—,‘,“.× Ñ ð	 	<øð !ù�$—,‘,“.× Ò üó>   ‚A™=šAŸA ¤A·?¸A¿AÁAÁAÁAÁAc              óÂ   K  — | j                  ||¬«      ƒ d{  –—†  	 d­–— | j                  «       ƒ d{  –—†  y7 Œ#7 Œ# | j                  «       ƒ d{  –—†7   w xY w­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
        :raises TypeError: if *timeout* is a :class:`bool` or not a real number, or *blocking* is not a :class:`bool`
        :raises ValueError: if a blocking call gets a ``nan`` *timeout* or a negative one other than ``-1``

        rG   N)Úacquire_writerJ   rK   s      r9   Ú
write_lockz!AsyncSoftReadWriteLock.write_lockš   sR   è ø€ ð × Ñ  °8Ð Ó<×<Ð<ð	!Üà—,‘,“.× Ñ ð	 	=øð !ù�$—,‘,“.× Ò ürM   c             ƒ  ó~   K  — | j                  «        | j                  d||¬«      ƒ d{  –—†  t        | ¬«      S 7 Œ­w)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
        :raises TypeError: if *timeout* is a :class:`bool` or not a real number, or *blocking* is not a :class:`bool`
        :raises ValueError: if a blocking call gets a ``nan`` *timeout* or a negative one other than ``-1``

        ÚreadrG   N©Úlock©Ú_raise_if_unusableÚ_acquireÚ$AsyncAcquireSoftReadWriteReturnProxyrK   s      r9   rI   z#AsyncSoftReadWriteLock.acquire_read®   s=   è ø€ ð* 	×ÑÔ!Ø�m‰m˜F G°hˆmÓ?×?Ð?Ü3¸Ô>Ð>ð 	@úó   ‚(=ª;«=c             ƒ  ó~   K  — | j                  «        | j                  d||¬«      ƒ d{  –—†  t        | ¬«      S 7 Œ­w)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
        :raises TypeError: if *timeout* is a :class:`bool` or not a real number, or *blocking* is not a :class:`bool`
        :raises ValueError: if a blocking call gets a ``nan`` *timeout* or a negative one other than ``-1``

        ÚwriterG   NrS   rU   rK   s      r9   rO   z$AsyncSoftReadWriteLock.acquire_writeÇ   s=   è ø€ ð* 	×ÑÔ!Ø�m‰m˜G W°xˆmÓ@×@Ð@Ü3¸Ô>Ð>ð 	AúrY   c          	   ƒ  ó  ‡ ‡‡K  — ‰€‰ j                   j                  n‰Šdˆˆˆ fd„}dˆˆ fd„}‰ j                  j                  ‰|€‰ j                   j                  n|‰‰ j
                  ‰ j                  ||¬«      ƒ d {  –—†  y 7 Œ­w)Nc           	   “  óÄ   •K  — ‰j                  «        ‰j                  t        j                  ‰j                  j
                  t        ‰| ‰¬«      «      ƒ d {  –—†  y 7 Œ­w)NrG   )rV   Ú_run_acquirer   Úpartialr2   Ú_acquire_level_ofr   )Ú	remainingr"   Úmoder6   s    €€€r9   Úenterz.AsyncSoftReadWriteLock._acquire.<locals>.enterã   sR   øè ø€ à×#Ñ#Ô%Ø×#Ñ#Ü×!Ñ!Ø—J‘J×0Ñ0Ü$ØØØ%ôó÷ ò ús   ƒAA ÁAÁA c                 ó¢   •— ‰j                  «        ‰j                  j                  x} �t        ‰j                  ‰| «      ‚‰j                  «       S ©N)rV   r2   rD   r   r7   Ú_backend_holds)rD   rb   r6   s    €€r9   Újoinablez1AsyncSoftReadWriteLock._acquire.<locals>.joinableð   sF   ø€ Ø×#Ñ#Ô%Ø"Ÿj™j×3Ñ3Ð3�
Ð@Ü& t§~¡~°t¸ZÓHÐHØ×&Ñ&Ó(Ð(r;   )r8   r"   r7   Úviarc   rg   )ra   ÚfloatÚreturnÚNone©rj   Úbool)r2   r"   r3   Úacquirer8   r7   r1   )r6   rb   r8   r"   rc   rg   s   `` `  r9   rW   zAsyncSoftReadWriteLock._acquireà   sw   úè ø€ Ø*2Ð*:�4—:‘:×&Ò&Àˆ÷	ö	)ð �l‰l×"Ñ"ØØ*1¨/�D—J‘J×&Ò&¸wØØ—n‘nØ—	‘	ØØð #ó 
÷ 	
ò 	
ús   …A;BÂ BÂBF)Úforcec          	   ƒ  ó0  K  — | j                   t        j                  «       k(  ro| j                  j	                  || j
                  | j                  t        j                  | j                  | j                  «      | j                  ¬«      ƒ d{  –—†  yy7 Œ­w)aÒ  
        Release one level of the calling task's hold.

        The wrapper releases the lock once no task holds it.

        :param force: if ``True``, end every level the calling task took through this wrapper. Levels taken through
            other wrappers on the same path stay. A wrapper that holds no level for the task releases nothing.

        :raises RuntimeError: if the calling task holds no level through this wrapper and *force* is ``False``

        )ro   r7   rh   ÚleaveÚ
still_heldN)r-   r+   r,   r3   rJ   r7   r1   r   r_   Ú_submitÚ_leave_backendrf   )r6   ro   s     r9   rJ   zAsyncSoftReadWriteLock.release   s{   è ø€ ð ×Ñ¤§	¡	£Ò+Ø—,‘,×&Ñ&ØØŸ.™.Ø—I‘IÜ×'Ñ'¨¯©°d×6IÑ6IÓJØ×.Ñ.ð 'ó ÷ ñ ð ,ðús   ‚BBÂBÂBc              ƒ  ó&  K  — | j                   t        j                  «       k7  s| j                  ryd| _        	 | j                  j                  | j                  rdn| j                  t        j                  | j                  | j                  r| j                  j                  n| j                  «      | j                  ¬«      ƒ d{  –—†  y7 Œ# t        $ r7}t!        |t"        j$                  «      s| j                  «       rd| _        ‚ d}~ww xY w­w)a²  
        End the holds of the tasks that acquired through this instance and release the lock once no task holds it.

        Idempotent. After calling this method the instance can no longer acquire locks. With ``is_singleton=False`` it
        also closes the underlying :class:`SoftReadWriteLock`. A singleton wrapper leaves the shared one open, so tasks
        that acquired through another wrapper and synchronous users of the same path keep their holds. The next acquire
        notices a synchronous ``close()`` or forced release of that shared lock. One that lands in the few bytecodes
        between that check and the admission still admits the task into the ended hold.

        NT)rq   rr   F)r-   r+   r,   r.   r3   Úretirer/   r1   r   r_   rs   r2   Úclosert   rf   ÚBaseExceptionÚ
isinstancer   ÚCancelledError)r6   Úerrors     r9   rw   zAsyncSoftReadWriteLock.close  sÑ   è ø€ ð ×Ñ¤§	¡	£Ò+¨t¯|ª|ØàˆŒð
	Ø—,‘,×%Ñ%Ø×*Ò*‘°·	±	Ü×'Ñ'¨¯©È$×J\ÒJ\°d·j±j×6FÒ6FÐbf×buÑbuÓvØ×.Ñ.ð &ó ÷ ò ùô
 ò 	ä˜e¤W×%;Ñ%;Ô<À×ATÑATÔAVØ$�”Øûð		üs;   ‚6D¹BC ÃCÃC ÃDÃC Ã	DÃ2D	Ä	DÄDc                óÊ   — | j                   t        j                  «       k7  rd| j                  › d�}t	        |«      ‚| j
                  rd| j                  › d�}t	        |«      ‚y )NzAsyncSoftReadWriteLock on z4 was inherited across fork; construct a new instancez has been closed)r-   r+   r,   r7   ÚRuntimeErrorr.   )r6   Úmsgs     r9   rV   z)AsyncSoftReadWriteLock._raise_if_unusable0  s`   € Ø×Ñ¤§	¡	£Ò+Ø.¨t¯~©~Ð.>Ð>rÐsˆCÜ˜sÓ#Ð#Ø�<Š<Ø.¨t¯~©~Ð.>Ð>NÐOˆCÜ˜sÓ#Ð#ð r;   c                ó@   — | j                   j                  t        «      S re   )r2   Ú_holds_level_ofr   r=   s    r9   rf   z%AsyncSoftReadWriteLock._backend_holds8  s   € à�z‰z×)Ñ)Ô*:Ó;Ð;r;   c                óB   — | j                   j                  t        «       y re   )r2   Ú_release_level_ofr   r=   s    r9   rt   z%AsyncSoftReadWriteLock._leave_backend<  s   € à�
‰
×$Ñ$Ô%5Õ6r;   c              ƒ  ó.  K  — t        j                  «       }| j                  ||j                  ¬«      }	 t	        |«      ƒ d {  –—†  t        |«       y 7 Œ# t
        j                  $ r©}|j                  «        	 t        |«      ƒ d {  –—†7   n-# t        $ r |d ‚t        $ r}t        ||«       Y d }~nd }~ww xY w	 t        | j                  | j                  «      «      ƒ d {  –—†7   ‚ # t        $ r}t        ||«       Y d }~‚ d }~ww xY wd }~ww xY w­w)N)Úcancel_check)r   ÚEventrs   Úis_setr   r   rz   Úsetr   r   rx   r   rt   r   )r6   rn   Ú	abandonedÚacquire_futureÚcancellationr{   s         r9   r^   z#AsyncSoftReadWriteLock._run_acquire@  sô   è ø€ ô —O‘OÓ%ˆ	ØŸ™ g¸I×<LÑ<L˜ÓMˆð	Ü" >Ó2×2Ð2ô  	�~Õ&ð! 3ùÜ×%Ñ%ò 	à�M‰MŒOð<Ü# NÓ3×3Ò3øÜò -à"¨Ð,Ü ò <Ü& |°U×;Ñ;ûð<úð<Ü# D§L¡L°×1DÑ1DÓ$EÓF×FÑFð øô !ò <Ü& |°U×;Ð;Øûð<þð	üs¦   ‚2DµA ÁAÁA ÁDÁA ÁDÁ)DÁ:BÂBÂ	BÂDÂB9Â#B4Â/DÂ4B9Â9DÂ='C+Ã$C'Ã%C+Ã*DÃ+	D
Ã4DÄ DÄD
Ä
DÄDÄDc           	     ó¶   — | j                   xs t        j                  «       }|j                  | j                  t
        t        j                  |g|¢­i |¤Ž«      S re   )r4   r   Úget_running_loopÚrun_in_executorr5   r   r   r_   )r6   ÚfuncÚargsÚkwargsr(   s        r9   rs   zAsyncSoftReadWriteLock._submitY  sL   € ð �z‰zÒ7œW×5Ñ5Ó7ˆØ×#Ñ# D§N¡N´MÄ9×CTÑCTÐUYÐCkÐ\`ÒCkÐdjÑCkÓlÐlr;   )éÿÿÿÿ)r7   zstr | os.PathLike[str]r8   ri   r"   rm   r#   rm   r$   ri   r%   úfloat | Noner&   ri   r'   z(Callable[[LeaseCompromise], None] | Noner(   ú asyncio.AbstractEventLoop | Noner)   úfutures.Executor | Nonerj   rk   )rj   Ústr)rj   ri   rl   )rj   z
int | None)rj   zLeaseCompromise | None)rj   r“   )rj   r”   re   )r8   r’   r"   úbool | Nonerj   zAsyncGenerator[None])r8   r’   r"   r–   rj   rX   )rb   zLiteral['read', 'write']r8   r’   r"   r–   rj   rk   )ro   rm   rj   rk   )rj   rk   )rn   z!Callable[..., AcquireReturnProxy]rj   rk   )rŽ   zCallable[_P, _R]r�   z_P.argsr�   z	_P.kwargsrj   z#asyncio.Future[_BackendOutcome[_R]])Ú__name__Ú
__module__Ú__qualname__Ú__doc__r:   Úpropertyr7   r8   r"   rA   rD   r(   r)   r   rL   rP   rI   rO   rW   rJ   rw   rV   rf   rt   r^   rs   © r;   r9   r!   r!   '   s	  „ ñð: ð"ð
 Ø!Ø$(Ø(,Ø#ØBFØ15Ø,0ñ"à)ð"ð ð"ð
 ð"ð ð"ð "ð"ð &ð"ð ð"ð @ð"ð /ð"ð *ð"ð 
ó"ðB ò$ó ð$ð ò"ó ð"ð ò#ó ð#ð ò%ó ð%ð ò%ó ð%ð òó ðð òó ðð ð!ÐW[ô !ó ð!ð& ð!ÐX\ô !ó ð!ð( '+ð?ØGKñ?Ø#ð?Ø9Dð?à	-ó?ð4 '+ð?ØGKñ?Ø#ð?Ø9Dð?à	-ó?ó2
ð@ .3õ ó*ó6$ó<ó7ó'ð2mØ$ðmØ-4ðmØ@Iðmà	,ômr;   r!   c                  ó8   — e Zd ZdZdd„Zdd„Z	 	 	 	 	 	 	 	 dd„Zy)	rX   zTAsync context-aware object that releases an :class:`AsyncSoftReadWriteLock` on exit.c                ó   — || _         y re   rS   )r6   rT   s     r9   r:   z-AsyncAcquireSoftReadWriteReturnProxy.__init__c  s	   € Øˆ�	r;   c              ƒ  ó"   K  — | j                   S ­wre   rS   r=   s    r9   Ú
__aenter__z/AsyncAcquireSoftReadWriteReturnProxy.__aenter__f  s   è ø€ Ø�y‰yÐùs   ‚c              ƒ  óT   K  — | j                   j                  «       ƒ d {  –—†  y 7 Œ­wre   )rT   rJ   )r6   Úexc_typeÚ	exc_valueÚ	tracebacks       r9   Ú	__aexit__z.AsyncAcquireSoftReadWriteReturnProxy.__aexit__i  s   è ø€ ð �i‰i×ÑÓ!×!Ò!ús   ‚( &¡(N)rT   r!   rj   rk   )rj   r!   )r¢   ztype[BaseException] | Noner£   zBaseException | Noner¤   zTracebackType | Nonerj   rk   )r—   r˜   r™   rš   r:   r    r¥   rœ   r;   r9   rX   rX   `  s:   „ Ù^óóð"à,ð"ð (ð"ð (ð	"ð
 
ô"r;   rX   ).rš   Ú
__future__r   Ú__lazy_modules__r   r   r+   r   Ú
contextlibr   Útypingr   r	   r
   r   r   Úfilelock._asyncr   r   r   r   r   r   r   r   Úfilelock._errorr   Úfilelock._soft_rw._syncr   r   Úcollections.abcr   r   Ú
concurrentr   Útypesr   Úfilelock._apir   Úfilelock._leaser   r   r   r!   rX   Ú__all__rœ   r;   r9   ú<module>r³      s‰   ðÙ Oå "â^Ð ã Û Û 	Û Ý *ß DÕ D÷	÷ 	ó 	õ $ß Gáß8Ý"Ý#å0Ý/áˆtƒ_€ÙˆTƒ]€÷vmñ vm÷r	"ñ "ð& +Øð�r;   