
    mBNjs:                    z   U d dl m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
 g dZej                  Z G d d	ej                        Z G d
 d      Z G d d      Z G d d      Zej$                  Zded<   ej                  Zded<   ej                  Zded<   ej*                  Zded<   ej*                  Zded<   y)    )annotationsN   )_typing   )wait_for)
AsyncConditionAsyncCooperativeLockAsyncCooperativeRLock	AsyncLock
AsyncRLock	ConditionCooperativeLockCooperativeRLockLockRLockc                       e Zd ZdZ ej
                  d      Z fdZ fdZddZ	 fdZ
 fdZddZeZ fd	Zd
 Zd Z xZS )r   a  
    Reentrant asyncio.lock.

    Inspired by Python's RLock implementation.

    .. warning::
        In async Python there are no threads. This implementation uses
        :meth:`asyncio.current_task` to determine the owner of the lock. This
        means that the owner changes when using :meth:`asyncio.wait_for` or
        any other method that wraps the work in a new :class:`asyncio.Task`.
    z (?:\W|^)waiters[:=](\d+)(?:\W|$)c                @    t        |   |i | d | _        d| _        y Nr   )super__init___owner_count)selfargskwargs	__class__s      p/Users/ahmed/devFolder/Ultron/claude-voice/.venv/lib/python3.12/site-packages/neo4j/_async_compat/concurrency.pyr   zAsyncRLock.__init__<   s#    $)&)    c                P   t         j                  |       }t        |          }| j                  dkD  rdnd}|d| j                   z  }| j                  j                  |      }|r|d|j                  d       z  }| j                  r|d| j                   z  }d|dd	  d
| dS )Nr   lockedunlockedz count=z	 waiters=r   z owner=< []>)object__repr__r   r   _WAITERS_REsearchgroupr   )r   res	lock_reprextrawaiters_matchr   s        r   r'   zAsyncRLock.__repr__A   s    ood#G$&	 KK!O74;;-((((//	:y!4!4Q!7 899E;;wt{{m,,E3q9+Rwb))r   c                L    |t        j                         }| j                  |k(  S N)asynciocurrent_taskr   )r   tasks     r   is_ownerzAsyncRLock.is_ownerM   s$    <'')D{{d""r   c                  K   | j                  |      r| xj                  dz  c_        yt        |          }t	        j
                  |      }	 t	        j                  d       d {    |j                         r#|j                         }||| _        d| _        y||j                          y7 H# t        j                  $ r% t	        j                         j                          Y }w xY ww)Nr3   r   Tr   F)r4   r   r   acquirer1   ensure_futuresleepCancelledErrorr2   canceldone	exceptionr   )r   meacquire_coror3   r=   r   s        r   _acquire_non_blockingz AsyncRLock._acquire_non_blockingR   s     ==b=!KK1Kw($$\2	,--""" 99;(I  ! #%% 	,
   "))+	,s=   AC.B3 (B1)B3 -AC.1B3 35C+(C.*C++C.c                   K   | j                  |      r| xj                  dz  c_        y t        |           d {    || _        d| _        y 7 w)Nr6   r   )r4   r   r   r7   r   r   r>   r   s     r   _acquirezAsyncRLock._acquirem   sI     ==b=!KK1Kgo 	 s   :AAAc                F  K   t        j                         }|dk  r|dk7  rt        d      |s|dk7  rt        d      |s| j                  |       d{   S |r|dk(  r| j	                  |       d{    y	 t        j
                  | j	                  |            }	 t        ||       d{    y7 `7 B7 	# t         j                  $ r7 |j                         r |j                          }|r| j                  |        w xY w# t         j                  $ r Y yw xY ww)zAcquire the lock.r   r#   ztimeout value must be positivez/can't specify a timeout for a non-blocking callNTF)r1   r2   
ValueErrorr@   rC   r8   r   r:   	cancelledr;   _releaseTimeoutError)r   blockingtimeoutr>   futalready_finisheds         r   r7   zAsyncRLock.acquireu   s    !!#Q;7b==>>GrMNOO33B7772--###	''b(9:CsG,,, % 8#
 -)) 	==?'*zz|#3 # MM"%	 ## 		sm   AD!B5D!4B75D!;$D  B; /B90B; 4D!7D!9B; ;A
DD DD!DD!c                    | j                  |      s"| j                  t        d      t        d      | xj                  dz  c_        | j                  sd | _        t        |           y y )Nr6   z Cannot release un-acquired lock.zCannot release foreign lock.r   )r4   r   RuntimeErrorr   r   releaserB   s     r   rG   zAsyncRLock._release   s^    }}"}%{{""#EFF=>>q{{DKGO r   c                L    t        j                         }| j                  |      S )zRelease the lock.)r1   r2   rG   r   r>   s     r   rO   zAsyncRLock.release   s    !!#}}R  r   c                ,   K   | j                          y wr0   rO   r   tvtbs       r   	__aexit__zAsyncRLock.__aexit__           r0   )Tr#   )__name__
__module____qualname____doc__recompiler(   r   r'   r4   r@   rC   r7   
__aenter__rG   rO   rX   __classcell__r   s   @r   r   r   -   sO    
 "**@AK

*#
6< J!
r   r   c                  P     e Zd ZdZd Z fdZd Zd Zd ZeZ	d Z
d Zd	 Z xZS )
r	   a6  
    Lock placeholder for asyncio Python when working fully cooperatively.

    This lock doesn't do anything in async Python. Its threaded counterpart,
    however, is an ordinary :class:`threading.Lock`.
    The AsyncCooperativeLock only works if there is no await being used
    while the lock is held.
    c                    d| _         y )NF_lockedr   s    r   r   zAsyncCooperativeLock.__init__   s	    r   c                X    t         |          }| j                  rdnd}d|dd  d| dS )Nr    r!   r"   r   r#   r$   r%   )r   r'   rg   r   r+   r-   r   s      r   r'   zAsyncCooperativeLock.__repr__   s8    g  LLj3q9+Rwb))r   c                    | j                   S ) Return True if lock is acquired.rf   rh   s    r   r    zAsyncCooperativeLock.locked   s    ||r   c                @    | j                   rt        d      d| _         y)a  
        Acquire a lock.

        This method will raise a RuntimeError where an ordinary
        (non-placeholder) lock would need to block. I.e., when the lock is
        already taken.

        Returns True if the lock was successfully acquired.
        z)Cannot acquire a locked cooperative lock.Trg   rN   rh   s    r   r7   zAsyncCooperativeLock.acquire   s!     <<JKKr   c                @    | j                   rd| _         yt        d      )z
        Release a lock.

        When the lock is locked, reset it to unlocked, and return.

        When invoked on an unlocked lock, a RuntimeError is raised.

        There is no return value.
        FLock is not acquired.Nrn   rh   s    r   rO   zAsyncCooperativeLock.release   s     << DL677r   c                $    | j                          y r0   rS   rT   s       r   __exit__zAsyncCooperativeLock.__exit__       r   c                *   K   | j                         S wr0   )	__enter__rh   s    r   ra   zAsyncCooperativeLock.__aenter__   s     ~~s   c                2   K   | j                  |||       y wr0   )rr   rT   s       r   rX   zAsyncCooperativeLock.__aexit__   s     aBs   )r[   r\   r]   r^   r   r'   r    r7   rO   ru   rr   ra   rX   rb   rc   s   @r   r	   r	      s7    *
8 I  r   r	   c                  D     e Zd ZdZd Z fdZd Zd Zd ZeZ	d Z
 xZS )r
   a0  
    Reentrant lock placeholder for cooperative asyncio Python.

    This lock doesn't do anything in async Python. It's threaded counterpart,
    however, is an ordinary :class:`threading.Lock`.
    The AsyncCooperativeLock only works if there is no await being used
    while the lock is acquired.
    c                     d | _         d| _        y r   )r   r   rh   s    r   r   zAsyncCooperativeRLock.__init__   s    r   c                    t         |          }| j                  d| j                   d| j                   }nd}d|dd  d| dS )	Nzlocked z times by owner:r!   r"   r   r#   r$   r%   )r   r'   r   r   rj   s      r   r'   zAsyncCooperativeRLock.__repr__   sU    g ;;"dkk]*:4;;-HEE3q9+Rwb))r   c                    | j                   duS )rl   N)r   rh   s    r   r    zAsyncCooperativeRLock.locked   s    {{$&&r   c                    t        j                         }| j                  || _        d| _        y| j                  |u r| xj                  dz  c_        yt	        d      )a  
        Acquire a lock.

        This method will raise a RuntimeError where an ordinary
        (non-placeholder) lock would need to block. I.e., when the lock is
        already taken by another Task.

        Returns True if the lock was successfully acquired.
        r   Tz1Cannot acquire a foreign locked cooperative lock.)r1   r2   r   r   rN   rQ   s     r   r7   zAsyncCooperativeRLock.acquire  sV     !!#;;DKDK;;"KK1KNOOr   c                    t        j                         }| j                  t        d      | j                  |urt        d      | xj                  dz  c_        | j                  sd| _        yy)z
        Release a lock.

        When the lock is locked, reset it to unlocked, and return.

        When invoked on an unlocked or foreign lock, a RuntimeError is raised.

        There is no return value.
        Nrp   zCannot release a foreign lock.r   )r1   r2   r   rN   r   rQ   s     r   rO   zAsyncCooperativeRLock.release  sa     !!#;;677;;b ?@@q{{DK r   c                $    | j                          y r0   rS   rT   s       r   rr   zAsyncCooperativeRLock.__exit__+  rs   r   )r[   r\   r]   r^   r   r'   r    r7   rO   ru   rr   rb   rc   s   @r   r
   r
      s.    *'P(& Ir   r
   c                       e Zd ZdZddZdZ ej                         Zd Z	d Z
d Z fdZddZdd	Zd
 ZddZd Z xZS )r   a$  
    Asynchronous equivalent to threading.Condition.

    This class implements condition variable objects. A condition variable
    allows one or more coroutines to wait until they are notified by another
    coroutine.

    A new Lock object is created and used as the underlying lock.
    Nc                    |
t               }|| _        |j                  | _        |j                  | _        |j                  | _        t        j                         | _        y r0   )r   _lockr    r7   rO   collectionsdeque_waiters)r   locks     r   r   zAsyncCondition.__init__B  sF    <;D
kk||||#))+r   c                
   	 t        j                         }| j                  (| j                  5  | j                  || _        d d d        || j                  urt        | d      |S # t        $ r d }Y _w xY w# 1 sw Y   8xY w)Nz# is bound to a different event loop)r1   get_running_looprN   _loop
_loop_lock)r   loops     r   	_get_loopzAsyncCondition._get_loopQ  s    	++-D ::::%!%DJ ! tzz!$)LMNN  	D	 !s   A( A9(A65A69Bc                   K   t        | j                  t        t        f      r| j                  j	                          y | j	                          d {    y 7 wr0   )
isinstancer   r	   r
   r7   rh   s    r   ra   zAsyncCondition.__aenter___  s?     JJ-/DE
 JJ ,,.  s   AAAAc                ,   K   | j                          y wr0   rS   )r   exc_typeexcrW   s       r   rX   zAsyncCondition.__aexit__g  rY   rZ   c                    t         |          }| j                         rdnd}| j                  r| dt	        | j                         }d|dd  d| dS )	Nr    r!   z
, waiters:r"   r   r#   r$   r%   )r   r'   r    r   lenrj   s      r   r'   zAsyncCondition.__repr__j  s[    g  KKMz==gZDMM(:';<E3q9+Rwb))r   c                t  K   | j                         st        d      d}t        | j                  t              r| j                  j                  |       n| j                  j                          	 | j                         j                         }| j                  j                  |       	 t        ||       d{    	 | j                  j                  |       t        | j                  t        t        f      r| j                  j                          nc	 	 t        | j                  t              r$| j                  j!                  |       d{    n"| j                  j                          d{    	 |rt"        j$                  y7 7 =7 # t"        j$                  $ r d}Y nw xY w# t"        j&                  $ r Y | j                  j                  |       t        | j                  t        t        f      r| j                  j                          n	 	 t        | j                  t              r%| j                  j!                  |       d{  7   n#| j                  j                          d{  7   n# t"        j$                  $ r d}Y nw xY w|rt"        j$                  yt"        j$                  $ r d} w xY w# | j                  j                  |       w xY w# t        | j                  t        t        f      r| j                  j                          n	 	 t        | j                  t              r%| j                  j!                  |       d{  7   n#| j                  j                          d{  7   n# t"        j$                  $ r d}Y nw xY w|rt"        j$                  w xY ww)a  
        Wait until notified.

        If the calling coroutine has not acquired the lock when this
        method is called, a RuntimeError is raised.

        This method releases the underlying lock, and then blocks
        until it is awakened by a notify() or notify_all() call for
        the same condition variable in another coroutine.  Once
        awakened, it re-acquires the lock and returns True.
        zcannot wait on un-acquired lockFNT)r    rN   r   r   r   rG   rO   r   create_futurer   appendr   remover	   r
   r7   rC   r1   r:   rH   )r   rJ   r>   rF   rK   s        r   _waitzAsyncCondition._waitq  s     {{}@AA	djj*-JJ#JJ 	-.."002CMM  %	*sG,,, $$S) 

13HI 

""$)%djj*="&**"5"5b"999"&**"4"4"666 ,,, 5 -( :6"11 )$(	)  '' 
 $$S) 

13HI 

""$)%djj*="&**"5"5b"999"&**"4"4"666"11 )$(	)  ,,, - ))  	 $$S) 

13HI 

""$)%djj*="&**"5"5b"999"&**"4"4"666"11 )$(	)  ,,, s,  A.N819K% +F. :F;F.  K% <N88F F"F 3F4F 8N8F. F F F*'N8)F**N8.KK K% <N88I= I#I= 6I97I= <N8=JN8JN8,KK K""K% %=N5#8NM#N?N NN5NN5NN55N8c                l   K   t        j                         }| j                  ||       d {   S 7 w)N)rJ   r>   )r1   r2   r   )r   rJ   r>   s      r   waitzAsyncCondition.wait  s-     !!#ZZBZ7777s   +424c                h   K    |       }|s"| j                          d{     |       }|s"|S 7 w)z
        Wait until a predicate becomes true.

        The predicate should be a callable which result will be
        interpreted as a boolean value.  The final predicate value is
        the return value.
        N)r   )r   	predicateresults      r   r   zAsyncCondition.wait_for  s9      ))+[F   s   2022c                    | j                         st        d      d}| j                  D ]0  }||k\  r y|j                         r|dz  }|j	                  d       2 y)a_  
        Wake up a single threads waiting on this condition.

        By default, wake up one coroutine waiting on this condition, if any.
        If the calling coroutine has not acquired the lock when this method
        is called, a RuntimeError is raised.

        This method wakes up at most n of the coroutines waiting for the
        condition variable; it is a no-op if no coroutines are waiting.

        Note: an awakened coroutine does not actually return from its
        wait() call until it can reacquire the lock. Since notify() does
        not release the lock, its caller should.
        z!cannot notify on un-acquired lockr   r   FN)r    rN   r   r<   
set_result)r   nidxrK   s       r   notifyzAsyncCondition.notify  sT     {{}BCC==Cax88:qu% !r   c                L    | j                  t        | j                               y)a  
        Wake up all threads waiting on this condition.

        This method acts like notify(), but wakes up all waiting threads
        instead of one. If the calling thread has not acquired the lock when
        this method is called, a RuntimeError is raised.
        N)r   r   r   rh   s    r   
notify_allzAsyncCondition.notify_all  s     	C&'r   r0   )NN)r   )r[   r\   r]   r^   r   r   	threadingr   r   r   ra   rX   r'   r   r   r   r   r   rb   rc   s   @r   r   r   /  sP    $
, E!J!*3-j8&6(r   r   zt.TypeAliasr   r   r   r   r   )
__future__r   r1   r   r_   r    r   rU   shimsr   __all__r   r   r   r	   r
   r   r   __annotations__r   r   r    r   r   <module>r      s   " #   	    LL	x xv=  = @D DNl( l(^ #,,	; ,(~~ -NNk " ) + /__{ $r   