+\hUdZddlmZddlZddlZddlZddlmZddlm Z ddl m Z m Z ddl mZmZmZmZmZmZmZmZerddlmZe d d Zd ed <e d d Zded <e ded Zded<d&dZd'dZd(dZd(dZ d)dZ!d'dZ"d*dZ#Gdde Z$ededefZ%d+dZ& d,dZ'dZ(d ed!<d"Z)d ed#<Gd$d%Z*y)-zInternal helpers for CSOT.) annotationsN)deque)AbstractContextManager) ContextVarToken) TYPE_CHECKINGAnyCallableDequeMutableMappingOptionalTypeVarcast) WriteConcernTIMEOUT)defaultzContextVar[Optional[float]]RTTzContextVar[float]DEADLINEinfctjdtjdtjt dy)Nrr)rsetrrfloatP/root/niggaflix-v3/playground/venv/lib/python3.12/site-packages/pymongo/_csot.py reset_allr#s) KKGGCL LLurc,tjdSN)rgetrrr get_timeoutr!)s ;;t rc*tjSr)rr rrrget_rttr#-s 779rc*tjSr)rr rrr get_deadliner%1s <<>rc.tj|yr)rr)rtts rset_rttr(5s GGCLrcjtsytjtjz Sr)r!rr time monotonicrrr remainingr,9s" = <<>DNN, ,,rc6t}||St||S)z4Return the remaining timeout clamped to a max value.)r,min) max_timeouttimeouts rclamp_remainingr1?s!kG w $$rc(eZdZdZddZddZddZy) _TimeoutContextzInternal timeout context manager. Use :func:`pymongo.timeout` instead:: with pymongo.timeout(0.5): client.test.test.insert_one({}) c ||_d|_yr)_timeout_tokens)selfr0s r__init__z_TimeoutContext.__init__Ps \` rcVtj|j}tj }|jr!t j |jzn td}tjt||}tjd}|||f|_ y)Nrr) rrr5rr r*r+rr.rr6)r7 timeout_token prev_deadline next_deadlinedeadline_token rtt_tokens r __enter__z_TimeoutContext.__enter__Tsq DMM2   <@MM(4==8uUZ| !c-&GHGGCL %~yA rc|jrP|j\}}}tj|tj|tj|yyr)r6rresetrr)r7exc_typeexc_valexc_tbr:r=r>s r__exit__z_TimeoutContext.__exit__\sB <<7;|| 4M>9 MM- ( NN> * IIi rN)r0Optional[float]returnNone)rBr rCr rDr rHrI)__name__ __module__ __qualname____doc__r8r?rErrrr3r3GsaB!rr3F.)boundctjrtjdfd }ntjdfd }t t |S)zbApply the client's timeoutMS to this operation. Can wrap both asynchronous and synchronous methodscKt7|j}|)t|5|g|i|d{cdddS|g|i|d{S7!#1swYxYw7wrr!r5r3r7argskwargsr0funcs r csot_wrapperzapply..csot_wrapperls|}$--&(1A%)$%@%@%@@AAd4T4V44 4 AAA4s7$A)AAAA)A'A)AA$ A)ct/|j}|!t|5|g|i|cdddS|g|i|S#1swYxYwrrRrSs rrWzapply..csot_wrappervsc}$--&(1;#D:4:6:;;.t.v. .;;s AA)r7r rTr rUr rHr )inspectiscoroutinefunction functoolswrapsrrN)rVrWs` rapplyr]hsX""4(   5  5   /  / <  rc|r |jry|j}t|jdd|r||d<yy)z+Apply the given write concern to a command.Nwtimeout writeConcern)is_server_defaultdocumentr!pop)cmd write_concernwcs rapply_write_concernrgsE M;;   B}  z4   N r int_MAX_RTT_SAMPLES_MIN_RTT_SAMPLESc<eZdZUdZded<d dZd dZd dZd dZy) MovingMinimumz4Tracks a minimum RTT within the last 10 RTT samples.z Deque[float]samplesc.tt|_y)N)maxlen)rrjror7s rr8zMovingMinimum.__init__s$45 rc`|dkrtd||jj|y)Nrzduration cannot be negative ) ValueErrorroappend)r7samples r add_samplezMovingMinimum.add_samples. A:;F8DE E F#rcft|jtk\rt|jSy)z7Get the min, or 0.0 if there aren't enough samples yet.r)lenrorlr.rrs rr zMovingMinimum.gets& t||  0 0t||$ $rc8|jjyr)roclearrrs rrAzMovingMinimum.resets rNrG)rvrrHrIrHr) rJrKrLrM__annotations__r8rwr rArrrrnrns> 6$  rrnrG)rHrFr|)r'rrHrI)r/rrHr)rVrNrHrN)rdzMutableMapping[str, Any]rezOptional[WriteConcern]rHrI)+rM __future__rr[rYr* collectionsr contextlibr contextvarsrrtypingrr r r r r rrpymongo.write_concernrrr}rrrrr!r#r%r(r,r1r3rNr]rgrjrlrnrrrrs!" -)___2'1)T'J $J#E377(U5\J J - %!,!< CxS)*!4 ! ! !2H !  !##r