
    &g)                        S r SSKJr  SSKrSSKrSSKJrJr  SSKJ	r	J
r
Jr  \R                  " 5       r " S S5      r " S S	5      r " S
 S\\5      r " S S\\5      rg)zLock and Condition classes vendored from https://github.com/python/cpython/blob/main/Lib/asyncio/locks.py
to port 3.13 fixes to older versions of Python.
Can be removed once we drop Python 3.12 support.    )annotationsN)events
exceptions)Any	CoroutineOptionalc                  "    \ rS rSrSrSS jrSrg)_LoopBoundMixin   Nc                    [         R                  " 5       nU R                  c"  [           U R                  c  Xl        S S S 5        XR                  La  [	        U < S35      eU$ ! , (       d  f       N-= f)Nz# is bound to a different event loop)r   _get_running_loop_loop_global_lockRuntimeError)selfloops     ZC:\Suresh\moveshuttle\MDcreated\moveengine\venv\Lib\site-packages\pymongo/_asyncio_lock.py	_get_loop_LoopBoundMixin._get_loop   s]    '')::::%!%J  zz!$)LMNN s   A$$
A2)r   )returnr   )__name__
__module____qualname____firstlineno__r   r   __static_attributes__     r   r
   r
      s    E	r   r
   c                  (    \ rS rSrSS jrSS jrSrg)_ContextManagerMixin    c                @   #    U R                  5       I S h  vN   g  N7fN)acquirer   s    r   
__aenter___ContextManagerMixin.__aenter__!   s     lln 	 	s   c                ,   #    U R                  5         g 7fr"   )release)r   exc_typeexctbs       r   	__aexit___ContextManagerMixin.__aexit__'   s     s   r   Nr   None)r)   r   r*   r   r+   r   r   r/   )r   r   r   r   r%   r,   r   r   r   r   r   r       s    r   r   c                  b   ^  \ rS rSrSrS
S jrSU 4S jjrSS jrSS jrS
S jr	S
S jr
S	rU =r$ )Lock+   a  Primitive lock objects.

A primitive lock is a synchronization primitive that is not owned
by a particular task when locked.  A primitive lock is in one
of two states, 'locked' or 'unlocked'.

It is created in the unlocked state.  It has two basic methods,
acquire() and release().  When the state is unlocked, acquire()
changes the state to locked and returns immediately.  When the
state is locked, acquire() blocks until a call to release() in
another task changes it to unlocked, then the acquire() call
resets it to locked and returns.  The release() method should only
be called in the locked state; it changes the state to unlocked
and returns immediately.  If an attempt is made to release an
unlocked lock, a RuntimeError will be raised.

When more than one task is blocked in acquire() waiting for
the state to turn to unlocked, only one task proceeds when a
release() call resets the state to unlocked; successive release()
calls will unblock tasks in FIFO order.

Locks also support the asynchronous context management protocol.
'async with lock' statement should be used.

Usage:

    lock = Lock()
    ...
    await lock.acquire()
    try:
        ...
    finally:
        lock.release()

Context manager usage:

    lock = Lock()
    ...
    async with lock:
         ...

Lock objects can be tested for locking state:

    if not lock.locked():
       await lock.acquire()
    else:
       # lock is acquired
       ...

c                     S U l         SU l        g )NF)_waiters_lockedr$   s    r   __init__Lock.__init___   s    59r   c                   > [         TU ]  5       nU R                  (       a  SOSnU R                  (       a  U S[	        U R                  5       3nSUSS  SU S3$ 	Nlockedunlockedz
, waiters:<   z [z]>)super__repr__r5   r4   lenr   resextra	__class__s      r   r@   Lock.__repr__c   sY    g  LLj==gZDMM(:';<E3q9+Rwb))r   c                    U R                   $ )z Return True if lock is acquired.)r5   r$   s    r   r:   Lock.lockedj   s    ||r   c                n  #    U R                   (       d6  U R                  b!  [        S U R                   5       5      (       a  SU l         gU R                  c  [        R                  " 5       U l        U R                  5       R                  5       nU R                  R                  U5          UI Sh  vN   U R                  R                  U5        SU l         g N'! U R                  R                  U5        f = f! [        R                   a#    U R                   (       d  U R                  5         e f = f7f)ziAcquire a lock.

This method blocks until the lock is unlocked, then sets it to
locked and returns True.
Nc              3  @   #    U  H  oR                  5       v   M     g 7fr"   )	cancelled).0ws     r   	<genexpr>Lock.acquire.<locals>.<genexpr>w   s     (N1s   T)r5   r4   allcollectionsdequer   create_futureappendremover   CancelledError_wake_up_firstr   futs     r   r#   Lock.acquiren   s      ||MM!S(N(N%N%NDL== '--/DMnn,,.S!	*		$$S)  $$S)(( 	 <<##%	sB   B(D5,C 1C2C 6C; D5C C88C; ;7D22D5c                j    U R                   (       a  SU l         U R                  5         g[        S5      e)a  Release a lock.

When the lock is locked, reset it to unlocked, and return.
If any other tasks are blocked waiting for the lock to become
unlocked, allow exactly one of them to proceed.

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

There is no return value.
FzLock is not acquiredN)r5   rW   r   r$   s    r   r(   Lock.release   s*     << DL!566r   c                    U R                   (       d  g [        [        U R                   5      5      nUR	                  5       (       d  UR                  S5        gg! [         a     gf = f)z*Ensure that the first waiter will wake up.NT)r4   nextiterStopIterationdone
set_resultrX   s     r   rW   Lock._wake_up_first   sV    }}	tDMM*+C
 xxzzNN4  	  		s   A 
A'&A')r5   r4   r.   r   strr   bool)r   r   r   r   __doc__r6   r@   r:   r#   r(   rW   r   __classcell__rE   s   @r   r1   r1   +   s-    1f*$L7"! !r   r1   c                  t   ^  \ rS rSrSrSSS jjrSU 4S jjrSS jrSS jrSSS jjr	SS jr
SS	 jrS
rU =r$ )	Condition   a  Asynchronous equivalent to threading.Condition.

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

A new Lock object is created and used as the underlying lock.
c                    Uc
  [        5       nXl        UR                  U l        UR                  U l        UR                  U l        [
        R                  " 5       U l        g r"   )r1   _lockr:   r#   r(   rQ   rR   r4   )r   locks     r   r6   Condition.__init__   sD    <6D
kk||||+6+<+<+>r   c                   > [         TU ]  5       nU R                  5       (       a  SOSnU R                  (       a  U S[	        U R                  5       3nSUSS  SU S3$ r9   )r?   r@   r:   r4   rA   rB   s      r   r@   Condition.__repr__   s]    g  KKMMz==gZDMM(:';<E3q9+Rwb))r   c                   #    U R                  5       (       d  [        S5      eU R                  5       R                  5       nU R	                  5           U R
                  R                  U5         UI Sh  vN    U R
                  R                  U5        Sn  U R                  5       I Sh  vN    Ub   Ueg ND N! [        R                   a  nUn SnAOSnAff = fMJ  ! Snf = f! U R
                  R                  U5        f = f! Sn  U R                  5       I Sh  vN    O%! [        R                   a  nUn SnAOSnAff = fM@  Ub
   Ue! Snf = ff = f! [         a    U R                  S5        e f = f7f)a  Wait until notified.

If the calling task 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 task.  Once
awakened, it re-acquires the lock and returns True.

This method may return spuriously,
which is why the caller should always
re-check the state and be prepared to wait() again.
zcannot wait on un-acquired lockNTr=   )r:   r   r   rS   r(   r4   rT   rU   r#   r   rV   BaseException_notify)r   rY   erres       r   waitCondition.wait   sv     {{}}@AAnn,,.!	#$$S).IIMM((-  "lln,, ?#!	 ##  -%44   	  #% MM((-  "lln,,%44   	  ?#!	"	 #
  	 LLO	s   AE>D	 /C) 4B95C) :D	 E B= ,B;-B= 1E 6C" 8E>9C) ;B= =CCE CE "C&&E )DD	 	ED(!D$"D('E(E<E>EEEEEEE E;;E>c                ~   #    U" 5       nU(       d(  U R                  5       I Sh  vN   U" 5       nU(       d  M(  U$  N7f)zWait until a predicate becomes true.

The predicate should be a callable whose result will be
interpreted as a boolean value.  The method will repeatedly
wait() until it evaluates to true.  The final predicate value is
the return value.
N)ry   )r   	predicateresults      r   wait_forCondition.wait_for  s:      ))+[F &  s   "=;==c                f    U R                  5       (       d  [        S5      eU R                  U5        g)a  By default, wake up one task waiting on this condition, if any.
If the calling task has not acquired the lock when this method
is called, a RuntimeError is raised.

This method wakes up n of the tasks waiting for the condition
 variable; if fewer than n are waiting, they are all awoken.

Note: an awakened task 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 lockN)r:   r   rv   )r   ns     r   notifyCondition.notify  s&     {{}}BCCQr   c                    SnU R                    H7  nX!:  a    g UR                  5       (       a  M!  US-  nUR                  S5        M9     g )Nr   r=   F)r4   ra   rb   )r   r   idxrY   s       r   rv   Condition._notify%  s=    ==Cx88::qu% !r   c                L    U R                  [        U R                  5      5        g)zWake up all tasks waiting on this condition. This method acts
like notify(), but wakes up all waiting tasks instead of one. If the
calling task has not acquired the lock when this method is called,
a RuntimeError is raised.
N)r   rA   r4   r$   s    r   
notify_allCondition.notify_all/  s     	C&'r   )ro   r4   r#   r:   r(   r"   )rp   zOptional[Lock]r   r/   rd   rf   )r|   r   r   r   )r=   )r   intr   r/   r.   )r   r   r   r   rh   r6   r@   ry   r~   r   rv   r   r   ri   rj   s   @r   rl   rl      s1    
?*5n &( (r   rl   )rh   
__future__r   rQ   	threadingasyncior   r   typingr   r   r   r1   r   r
   r   rl   r   r   r   <module>r      sa   4 #   & + +~~  E! E!PB($o B(r   