
    @h                       % S r SSKJr  SSKrSSKrSSKrSSKJr  SSKJ	r	  SSK
JrJr  SSKJrJrJrJrJrJrJrJr  \(       a  SSKJr  \" S	SS
9rS\S	'   \" SSS
9rS\S'   \" S\" S5      S
9rS\S'   S&S jrS'S jrS(S jrS(S jr S)S jr!S'S jr"S*S jr# " S S\	5      r$\" S\S\4   S9r%S+S jr&      S,S jr'Sr(S \S!'   S"r)S \S#'    " S$ S%5      r*g)-zInternal helpers for CSOT.    )annotationsN)deque)AbstractContextManager)
ContextVarToken)TYPE_CHECKINGAnyCallableDequeMutableMappingOptionalTypeVarcast)WriteConcernTIMEOUT)defaultzContextVar[Optional[float]]RTT        zContextVar[float]DEADLINEinfc                     [         R                  S 5        [        R                  S5        [        R                  [	        S5      5        g )Nr   r   )r   setr   r   float     RC:\Suresh\moveshuttle\MDcreated\moveengine\venv\Lib\site-packages\pymongo/_csot.py	reset_allr   #   s)    KKGGCLLLur   c                 ,    [         R                  S 5      $ N)r   getr   r   r   get_timeoutr!   )   s    ;;tr   c                 *    [         R                  5       $ r   )r   r    r   r   r   get_rttr#   -   s    779r   c                 *    [         R                  5       $ r   )r   r    r   r   r   get_deadliner%   1   s    <<>r   c                .    [         R                  U 5        g r   )r   r   )rtts    r   set_rttr(   5   s    GGCLr   c                 v    [        5       (       d  g [        R                  5       [        R                  " 5       -
  $ r   )r!   r   r    time	monotonicr   r   r   	remainingr,   9   s$    ==<<>DNN,,,r   c                6    [        5       nUc  U $ [        X5      $ )z4Return the remaining timeout clamped to a max value.)r,   min)max_timeouttimeouts     r   clamp_remainingr1   ?   s    kGw$$r   c                  6    \ rS rSrSrSS jrS	S jrS
S jrSrg)_TimeoutContextG   zInternal timeout context manager.

Use :func:`pymongo.timeout` instead::

  with pymongo.timeout(0.5):
      client.test.test.insert_one({})
c                    Xl         S U l        g r   _timeout_tokens)selfr0   s     r   __init___TimeoutContext.__init__P   s    \`r   c                ^   [         R                  U R                  5      n[        R	                  5       nU R                  (       a"  [
        R                  " 5       U R                  -   O
[        S5      n[        R                  [        X#5      5      n[        R                  S5      nXU4U l
        g )Nr   r   )r   r   r7   r   r    r*   r+   r   r.   r   r8   )r9   timeout_tokenprev_deadlinenext_deadlinedeadline_token	rtt_tokens         r   	__enter___TimeoutContext.__enter__T   sm    DMM2 <@MM(4==8uUZ|!c-&GHGGCL	%yAr   c                    U R                   (       aO  U R                   u  pEn[        R                  U5        [        R                  U5        [        R                  U5        g g r   )r8   r   resetr   r   )r9   exc_typeexc_valexc_tbr=   r@   rA   s          r   __exit___TimeoutContext.__exit__\   s@    <<7;||4M9MM-(NN>*IIi 	 r   r6   N)r0   Optional[float]returnNone)rF   r	   rG   r	   rH   r	   rM   rN   )	__name__
__module____qualname____firstlineno____doc__r:   rB   rI   __static_attributes__r   r   r   r3   r3   G   s    aB!r   r3   F.)boundc                   ^  [         R                  " T 5      (       a"  [        R                  " T 5      SU 4S jj5       nO![        R                  " T 5      SU 4S jj5       n[	        [
        U5      $ )zbApply the client's timeoutMS to this operation. Can wrap both asynchronous and synchronous methodsc                   >#    [        5       c8  U R                  nUb)  [        U5         T" U /UQ70 UD6I S h  vN sS S S 5        $ T" U /UQ70 UD6I S h  vN $  N!! , (       d  f       N$= f N7fr   r!   r7   r3   r9   argskwargsr0   funcs       r   csot_wrapperapply.<locals>.csot_wrapperl   sl     }$--&(1%)$%@%@%@@ 21d4T4V444  A 214s7   &A0AAAA0A.A0A
A+'A0c                   > [        5       c0  U R                  nUb!  [        U5         T" U /UQ70 UD6sS S S 5        $ T" U /UQ70 UD6$ ! , (       d  f       N= fr   rY   rZ   s       r   r^   r_   v   sZ    }$--&(1#D:4:6: 21.t.v.. 21s   A		
A)r9   r	   r[   r	   r\   r	   rM   r	   )inspectiscoroutinefunction	functoolswrapsr   rU   )r]   r^   s   ` r   applyre   h   s[    ""4((			5 
	5 
		/ 
	/ <  r   c                    U(       a  UR                   (       a  gUR                  n[        5       b  UR                  SS5        U(       a  X S'   gg)z+Apply the given write concern to a command.NwtimeoutwriteConcern)is_server_defaultdocumentr!   pop)cmdwrite_concernwcs      r   apply_write_concernro      sC     M;;			B} 
z4 	 N 
r   
   int_MAX_RTT_SAMPLES   _MIN_RTT_SAMPLESc                  L    \ rS rSr% SrS\S'   SS jrSS jrSS jrSS jr	S	r
g
)MovingMinimum   z4Tracks a minimum RTT within the last 10 RTT samples.zDeque[float]samplesc                (    [        [        S9U l        g )N)maxlen)r   rr   rx   r9   s    r   r:   MovingMinimum.__init__   s    $45r   c                b    US:  a  [        SU 35      eU R                  R                  U5        g )Nr   zduration cannot be negative )
ValueErrorrx   append)r9   samples     r   
add_sampleMovingMinimum.add_sample   s.    A:;F8DEEF#r   c                h    [        U R                  5      [        :  a  [        U R                  5      $ g)z7Get the min, or 0.0 if there aren't enough samples yet.r   )lenrx   rt   r.   r{   s    r   r    MovingMinimum.get   s&    t|| 00t||$$r   c                8    U R                   R                  5         g r   )rx   clearr{   s    r   rE   MovingMinimum.reset   s    r   )rx   NrL   )r   r   rM   rN   rM   r   )rO   rP   rQ   rR   rS   __annotations__r:   r   r    rE   rT   r   r   r   rv   rv      s    >6$
r   rv   rL   )rM   rK   r   )r'   r   rM   rN   )r/   r   rM   r   )r]   rU   rM   rU   )rl   zMutableMapping[str, Any]rm   zOptional[WriteConcern]rM   rN   )+rS   
__future__r   rc   ra   r*   collectionsr   
contextlibr   contextvarsr   r   typingr   r	   r
   r   r   r   r   r   pymongo.write_concernr   r   r   r   r   r   r   r!   r#   r%   r(   r,   r1   r3   rU   re   ro   rr   rt   rv   r   r   r   <module>r      s    ! "     - ) _ _ _2'1)T'J	$ J#E37 7(U5\J
 J-%!, !< CxS)*!4
!	!
!2H
!	
!  #  #  r   