
    &gU                       % 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\	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      $ N)r   get     RC:\Suresh\moveshuttle\MDcreated\moveengine\venv\Lib\site-packages\pymongo/_csot.py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!   +   s    <<>r   c                .    [         R                  U 5        g r   )r   set)rtts    r   set_rttr%   /   s    GGCLr   c                 v    [        5       (       d  g [        R                  5       [        R                  " 5       -
  $ r   )r   r   r   time	monotonicr   r   r   	remainingr)   3   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_remainingr.   9   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)_TimeoutContextA   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)selfr-   s     r   __init___TimeoutContext.__init__J   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#   r4   r   r   r'   r(   floatr+   r   r5   )r6   timeout_tokenprev_deadlinenext_deadlinedeadline_token	rtt_tokens         r   	__enter___TimeoutContext.__enter__N   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   )r5   r   resetr   r   )r6   exc_typeexc_valexc_tbr;   r>   r?   s          r   __exit___TimeoutContext.__exit__V   s@    <<7;||4M9MM-(NN>*IIi 	 r   r3   N)r-   Optional[float]returnNone)rD   r	   rE   r	   rF   r	   rK   rL   )	__name__
__module____qualname____firstlineno____doc__r7   r@   rG   __static_attributes__r   r   r   r0   r0   A   s    aB!r   r0   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   r4   r0   r6   argskwargsr-   funcs       r   csot_wrapperapply.<locals>.csot_wrapperf   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   rW   rX   s       r   r\   r]   p   sZ    }$--&(1#D:4:6: 21.t.v.. 21s   A		
A)r6   r	   rY   r	   rZ   r	   rK   r	   )inspectiscoroutinefunction	functoolswrapsr   rS   )r[   r\   s   ` r   applyrc   b   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_concernrm   |   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   rp   rv   r6   s    r   r7   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 )
ValueErrorrv   append)r6   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   )lenrv   rr   r+   ry   s    r   r   MovingMinimum.get   s&    t|| 00t||$$r   c                8    U R                   R                  5         g r   )rv   clearry   s    r   rC   MovingMinimum.reset   s    r   )rv   NrJ   )r~   r:   rK   rL   rK   r:   )rM   rN   rO   rP   rQ   __annotations__r7   r   r   rC   rR   r   r   r   rt   rt      s    >6$
r   rt   )rK   rI   r   )r$   r:   rK   rL   )r,   r:   rK   r:   )r[   rS   rK   rS   )rj   zMutableMapping[str, Any]rk   zOptional[WriteConcern]rK   rL   )*rQ   
__future__r   ra   r_   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.   r0   rS   rc   rm   rp   rr   rt   r   r   r   <module>r      s    ! "     - ) _ _ _2'1)T'J	$ J#E37 7(U5\J
 J-%!, !< CxS)*!4
!	!
!2H
!	
!  #  #  r   