+\h3ddlmZddlZddlZddlZddlZddlZddlZddlZddl Z ddl m Z m Z m Z mZmZmZmZmZmZddlmZddlmZmZddlmZmZmZmZmZddlm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(ddl)m*Z*m+Z+dd l,m-Z-m.Z.dd l/m0Z0m1Z1m2Z2dd l3m4Z4m5Z5m6Z6m7Z7dd l8m9Z9m:Z:dd l;mZ>ddl?m@Z@ddlAmBZBmCZCmDZDmEZEddlFmGZGddlHmIZIddlJmKZKddlLmMZMddlNmOZOddlPmQZQddlRmSZSe rLddlmTZTddlUmVZVddlWmXZXmYZYmZZZddl[m\Z\m]Z]ddl^m_Z_ddlFm`Z`ddlambZbddlNmcZcddldmeZemfZfdd lgmhZhmiZidd!ljmkZk dd"llmmZmmnZnmoZomlZld0d#Zpd%ZrGd&d'ZsGd(d)e'ZtGd*d+ZuGd,d-ZvGd.d/Zwy#eq$rd0d$ZpYAwxYw)1) annotationsN) TYPE_CHECKINGAny GeneratorMappingMutableMappingNoReturnOptionalSequenceUnion)DEFAULT_CODEC_OPTIONS)_csothelpers_shared) MAX_BSON_SIZEMAX_MESSAGE_SIZEMAX_WIRE_VERSIONMAX_WRITE_BATCH_SIZE ORDERED_TYPES) AutoReconnectConfigurationErrorDocumentTooLargeExecutionTimeoutInvalidOperationNotPrimaryErrorOperationFailure PyMongoErrorWaitQueueTimeoutError)Hello HelloCompat)_get_timeout_detailsformat_timeout_details) _cond_wait_create_condition _create_lock)_CONNECTION_LOGGER_ConnectionStatusMessage _debug_log _verbose_connection_error_reason)ConnectionCheckOutFailedReasonConnectionClosedReason)NetworkingInterfacereceive_messagesendall) PoolOptions) SSLErrors_CancellationContext_configured_socket_interface_raise_connection_failure)ReadPreference)_add_to_command) SERVER_TYPE) SocketChecker)_validate_session_write_concern)_handle_reauth)command) CodecOptions)ObjectId) SnappyContext ZlibContext ZstdContext)_OpMsg_OpReply) ReadConcern) _ServerMode) _AuthContext) ClientSession) MongoClient_MongoClientErrorHandler)_Address _CollationIn) WriteConcern)F_GETFDF_SETFD FD_CLOEXECfcntlcTt|t}t|t|tzy)z8Set the close-on-exec flag on the given file descriptor.N)rMrJrKrL)fdflagss [/root/niggaflix-v3/playground/venv/lib/python3.12/site-packages/pymongo/synchronous/pool.py_set_non_inheritable_non_atomicrRnsb'" b'5:-.cy)z6Dummy function for platforms that don't provide fcntl.N)rOs rQrRrRwsrSTceZdZdZ d$dZd%dZ d&dZd'dZd'dZd'dZ d(dZ d)d Z d*d Z d(d Z eej ed d d d dd d d dd d df d+dZd,dZd-dZd.dZd/dZ d0dZd1d2dZ d3dZd4dZd'dZd5dZ d6dZd7dZd'dZd8dZ d9dZ!d:dZ"d;d Z#d;d!Z$d ConnectionaStore a connection with some metadata. :param conn: a raw connection object :param pool: a Pool instance :param address: the server's (host, port) :param id: the id of this socket in it's pool :param is_sdam: SDAM connections do not call hello on creation c tj||_||_||_||_||_d|_tj|_ d|_ d|_ t|_t|_t"|_t&|_d|_d|_d|_d|_|j2j4|_|j8|_|j:|_|j2j<|_d|_ tC|_"d|_#d|_$d|_%|jL|_'|jNjQ|_)d|_*tW|_,|j2|_d|_-d|_.d|_/d|_0d|_1d|_2|j2jf|_4d|_5|jl|_6tj|_7d|_8y)NFg)9weakrefrefpool_refconnaddressidis_sdamclosedtime monotoniclast_checkin_timeperformed_handshake is_writablermax_wire_versionr max_bson_sizermax_message_sizermax_write_batch_sizesupports_sessionshello_ok is_mongosop_msg_enabledopts_event_listeners listenersenabled_for_cmapenabled_for_logging_compression_settingscompression_settingscompression_contextr6socket_checkeroidc_token_gen_idnegotiated_mechsauth_ctxgenpool_gen get_overall generationreadyr0cancel_context more_to_come service_idserver_connection_id pinned_txn pinned_cursoractivesocket_timeout last_timeout connect_rtt _client_id creation_time _cluster_time)selfr\poolr]r^r_s rQ__init__zConnection.__init__s D)     !%!1#( !& 0* 0$8!!&# #33 $ 5 5#'#;#; $(II$C$C!Y] -:_045904  --335 4H4JII "'.237! "  II44//!^^-!rSc|||jk(ry||_|jjj|y)z?Cache last timeout to avoid duplicate calls to conn.settimeout.N)rr\get_conn settimeout)rtimeouts rQset_conn_timeoutzConnection.set_conn_timeouts3 d'' ' # %%g.rSctj}|2|js%|j|jj ytj }| |j}||z }|dkrIt|j}t|}d|dd|dd|}t|dd|dd|j|t|dz|d <|j||S) Nrz5operation would exceed time limit, remaining timeout:z.5fz <= network round trip time: 2okerrmsgcode maxTimeMS) r remainingrrrnrget_rttrr r!rrfint) rclientcmdrrtt max_time_mstimeout_details formattedrs rQ apply_timeoutzConnection.apply_timeouts//# ?$$%%dii&>&>?mmo ;""Cm ?2499=O.?ILWUXMYuvyz}u~~AJ@KLF"FB7%%   ?";#56C  g&rSc.d|_|jrJyNT)rrrs rQpin_txnzConnection.pin_txns%%%%%rSc.d|_|jrJyr)rrrs rQ pin_cursorzConnection.pin_cursors!??""?rSc|j}|r|j|y|jtjyN)r[checkin close_connr*STALE)rrs rQunpinzConnection.unpins/}}  LL  OO288 9rSc|jjs"|js|jjrd|_t j diSt jdddiS)NThelloOk)rn server_apirk load_balancedrmrCMD LEGACY_CMDrs rQ hello_cmdzConnection.hello_cmdsO 99  4==DII4K4K"&D OOQ' '**Ay$? ?rSc&|jddSr)_hellors rQhellozConnection.hellos{{4&&rSc|j}|j }d}|rad|_|jj|d<|jr|jj |d<|jj rbd|d<n\|Z||d<|Jt|dz|d<d}|jjr(|j|jj|z|jj}|r|jd k(r+|jr|jd z|jz|d <d d lm}|j j#||j$}|r|j'} | | |d<nd}|rt)j*} |j-d|d|} |rt)j* z |_t1| |} | j2|_| j4|_| j6|_| j8|_| j:|_| j<duxr | j>|_ | j<|_| jB|_!| jDtFjHtFjJtFjLtFjNtFjPfv|_)| jDtFjTk(|_+| jDtFjXk(|_-|r8|jr,|jj]| j } | |_/d|_0| jb|_2|r| jf|_4|r(|jk| |jmr||_7|jj rR| jps tsd| jp|_8|jtjw|jp|_<| S)NFTr compression loadBalancedtopologyVersionrmaxAwaitTimeMSDEFAULT.saslSupportedMechsrauthspeculativeAuthenticateadmin)publish_eventsexhaust_allowed) awaitablez`Driver attempted to initialize in load balancing mode, but the server does not support this mode)=rrdrnmetadatart compressorsrrconnect_timeoutr _credentials mechanismusernamesourcepymongo.synchronousrrCfrom_credentialsr]speculate_commandrarbr9rrrerfrgrhrilogical_session_timeout_minutes is_readablerjrk server_typer5 RSPrimary RSSecondary RSArbiterRSOtherRSGhostis_repl Standalone is_standaloneMongosrlget_compression_contextrurm connection_idrsasl_supported_mechsrxparse_responsespeculate_succeededryrrr{getr})rtopology_versionheartbeat_frequencyrperforming_handshakercredsrryspeculative_authenticatestartdocrctxs rQrzConnection._hellosv nn#'#;#;; '+D $ II..CM((%)%>%>%J%JM"yy&&&*N#  )%5C! "&2 22$'(;d(B$CC !Iyy((%%dii&?&?BU&UV && )+,1LL3,>,O() 0((99%NH+3+E+E+G(+75MC12H NN$Ell7CylY #~~/%7D cY/ ,, % 6 6"00 % 6 6$)$>$>!  1 1 = S%BSBS ?D>c>c, ((  ! !  # #  ! !       -   #..+2H2HH**k.@.@@ D$=$=++CCEDUDUVC'*D $"$)$7$7! $)$>$>D !   # #E *++- ( 99 " "##(A$..DO"mm//@DO rSc|jd}|j|_|j}|d}tj||j |SNr)r,runpack_responser_check_command_responserf)rreply unpacked_docs response_docs rQ _next_replyzConnection._next_replyYsT$$T*!..--/ $Q' ..|T=R=RSrSTNFc|j| | t| |} t|ts t |}||j s | t d|j|| r| j|| |||j|| | |r |jnd}t|xr |j }|jr|j| t||||j||| | |||j ||j"|| | |j$|j||||S#t&t(f$rt*$r}|j-|Yd}~yd}~wwxYw)aExecute a command or raise an error. :param dbname: name of the database on which to run the command :param spec: a command document as a dict, SON, or mapping object :param read_preference: a read preference :param codec_options: a CodecOptions instance :param check: raise OperationFailure if there are errors :param allowable_errors: errors to ignore if `check` is True :param read_concern: The read concern for this command. :param write_concern: The write concern for this command. :param parse_write_concern_error: Whether to parse the ``writeConcernError`` field in the command response. :param collation: The collation for this command. :param session: optional ClientSession instance. :param client: optional MongoClient for gossipping $clusterTime. :param retryable_write: True if this command is a retryable write. :param publish_events: Should we publish events for this command? :param user_fields: Response fields that should be decoded using the TypeDecoders from codec_options, passed to bson._decode_all_selective. Nz3Collation is unsupported for unacknowledged writes.)parse_write_concern_error collationcompression_ctx use_op_msgunacknowledged user_fieldsr write_concern)validate_sessionr7 isinstancerdict acknowledgedradd_server_api _apply_tosend_cluster_timerpboolrm_raise_if_not_writabler9rlr]rgrurr BaseExceptionr2)rdbnamespecread_preference codec_optionscheckallowable_errors read_concernrrrsessionrretryable_writerrrrprerrors rQr9zConnection.commandasiR fg.1'=I$ .:D%)C)CyGX$%Z[ [ D!    dO_d K tWf5&4DNN$ mNM4N4N0NO     ' ' 7 2  ""*C# $ 8 8..-' /+- 0!/2   2  * *5 1 1 2sAD**EEEc|j)||jkDrtd||jfz t|jj|y#t $r}|j |Yd}~yd}~wwxYw)z}Send a raw BSON message or raise ConnectionFailure. If a network exception is raised, the socket is closed. NzfBSON document too large (%d bytes) - the connected server supports BSON document sizes up to %d bytes.)rgrr-r\rr r2)rmessage max_doc_sizers rQ send_messagezConnection.send_messages~    )lT=O=O.O"?BNPTPbPbAcd   2 DII&& 0 2  * *5 1 1 2s A A<!A77A<c t|||jS#t$r}|j|Yd}~yd}~wwxYw)zzReceive a raw BSON message or raise ConnectionFailure. If any exception is raised, the socket is closed. N)r,rhr r2)r request_idrs rQr,zConnection.receive_messages=  2"4T5J5JK K 2  * *5 1 1 2s =8=cB|r|jstdddddyy)z^Raise NotPrimaryError on unacknowledged write if this socket is not writable. z not primaryri{'rN)rer)rrs rQr z!Connection._raise_if_not_writables+ $"2"2!-]\a1bc c#3>rScJ|jd|j||y)zSend unack OP_MSG. Can raise ConnectionFailure or InvalidDocument. :param msg: bytes, an OP_MSG message. :param max_doc_size: size in bytes of the largest document in `msg`. TN)r r)rmsgrs rQ unack_writezConnection.unack_writes" ##D) #|,rSc|j|d|j|}|j|}tj||j |S)zSend "insert" etc. command, returning response as a dict. Can raise ConnectionFailure or OperationFailure. :param request_id: an int. :param msg: bytes, the command message. r)rr,command_responserrrf)rrrrrresults rQ write_commandzConnection.write_commandsQ #q!$$Z0'' 6 ..vt7L7LM rSc |r|jrd|_d|_|js)|jj}|rddlm}|j|||d|_tj|jz }|jr?|jJ|jj|j|j||j rwt#j$t&j(rSt+t"t,j.|j0|jd|jd|j|yyyy) zhAuthenticate to the server if needed. Can raise ConnectionFailure or OperationFailure. NFrr)reauthenticateTrrclientId serverHost serverPortdriverConnectionId durationMS)rdryr~rnrrr authenticaterarbrrqrppublish_connection_readyr]r^rrr% isEnabledForloggingDEBUGr'r& CONN_READYr)rr$rrdurations rQr+zConnection.authenticates '' $ DJzzII**E4!!%n!MDJ~~'$*<*<,K,KGMM,Z&4??!__#||A#||A'+ww'-['rSc<|r|j|ur tdyy)zValidate this session before use with client. Raises error if the client is not the one that created the session. z9Can only use session with the MongoClient that started itN)_clientr)rrrs rQrzConnection.validate_sessions) f,&'bcc- rSc |jry|j|r|jr?|jJ|jj |j |j ||jrtjtjr]tttj|j|j d|j d|j t!||yyyy)z$Close this connection with a reason.Nrrrr&r'r(r)reasonr)r` _close_connrqrppublish_connection_closedr]r^rrr%r-r.r/r'r& CONN_CLOSEDrr()rr6s rQrzConnection.close_conn)s ;;   $$~~11188twwPVW'',>,K,KGMM,Z&4@@!__#||A#||A'+ww;FC  -[' rSc|jryd|_|jj |jj y#t $rYywxYw)zClose this connection.NT)r`rcancelr\close Exceptionrs rQr7zConnection._close_conn>sJ ;;   ""$  IIOO    sA AActr/|jj|jjS|jj S)z?Return True if we know socket has been closed, False otherwise.)_IS_SYNCrv socket_closedr\r is_closingrs rQ conn_closedzConnection.conn_closedKs9 &&44TYY5G5GH H99'') )rSc.|r|j||yy)zAdd $clusterTime.N)_send_cluster_time)rr9rrs rQrzConnection.send_cluster_timeRs   % %gw 7 rScr|jjr!t||jjyy)zAdd server_api parameters.N)rnrr4)rr9s rQrzConnection.add_server_api\s( 99   GTYY%9%9 : rSc6tj|_yrrarbrcrs rQupdate_last_checkin_timez#Connection.update_last_checkin_timeas!%!1rSc||_yr)re)rres rQupdate_is_writablezConnection.update_is_writableds &rScDtj|jz S)z9Seconds since this socket was last checked into its pool.rGrs rQidle_time_secondszConnection.idle_time_secondsgs~~$"8"888rSc|jrd}ntj}|j|t |t t gtr.t|j}t|j||y)Nr) r~r*ERRORrrIOErrorOSErrorr/r rnr2r])rrr6detailss rQr2z$Connection._raise_connection_failureks\ ::F+11F  egw;; <*4995G %dllE7 S rSc4|j|jk(Sr)r\rothers rQ__eq__zConnection.__eq__syyEJJ&&rSc||k( SrrUrTs rQ__ne__zConnection.__ne__s5=  rSc,t|jSr)hashr\rs rQ__hash__zConnection.__hash__sDIIrScdjt|j|jxrdxsdt |S)NzConnection({}){} at {}z CLOSED)formatreprr\r`r^rs rQ__repr__zConnection.__repr__s8'.. O KK %I + tH  rS) r\r+rPoolr]ztuple[str, int]r^rr_r)rOptional[float]returnNone)rrErz"Optional[MutableMapping[str, Any]]rcrbrcrd)rcdict[str, Any])rcr)rz Optional[Any]r Optional[int]rczHello[dict[str, Any]])"r strr MutableMapping[str, Any]r rBrr:rrrz#Optional[Sequence[Union[str, int]]]rzOptional[ReadConcern]rzOptional[WriteConcern]rrrzOptional[_CollationIn]rOptional[ClientSession]rOptional[MongoClient]rrrrrzOptional[Mapping[str, Any]]rrrcrf)rbytesrrrcrd)rrgrczUnion[_OpReply, _OpMsg])rrrcrd)rrlrrrcrd)rrrrlrr:rcrf)F)r$rrcrd)rrkrrjrcrd)r6z Optional[str]rcrdrcr)r9rirrjrrkrcrd)r9rircrd)rerrcrd)rcfloat)rr rcr )rUrrcrrcr)rcrh)'__name__ __module__ __qualname____doc__rrrrrrrrrrr8r3PRIMARYr r9rr,r rr"r+rrr7rBrrrHrJrLr2rVrXr[r`rUrSrQrWrW~sn9"!9"9"! 9"  9"  9"v/!(J >&#:@'S'S+S  Sj (6'='=&;@D.204*/,0+/(, %#37 %#W2W2'W2% W2 $ W2  W2>W2,W2.W2$(W2*W2)W2&W2W2W2 1!W2"#W2$ %W2W2r2" 2d -$):F $ D d+ d6M d  d* *8)8)8& 8  8; 2'98'! rSrWceZdZdZy)_PoolClosedErrorzZInternal error raised when a thread tries to get a connection from a closed pool. N)rprqrrrsrUrSrQrvrvsrSrvc4eZdZddZddZd dZd dZd dZy) _PoolGenerationcNtjt|_d|_yr) collections defaultdictr _generations _generationrs rQrz_PoolGeneration.__init__s1<1H1H1MrSc<| |jS|j|S)z,Get the generation for the given service_id.r}r|rrs rQrz_PoolGeneration.gets%  ## #  ,,rSc|jS)z"Get the Pool's overall generation.)r}rs rQr|z_PoolGeneration.get_overallsrSc|xjdz c_|)|jD]}|j|xxdz cc<y|j|xxdz cc<y)z2Increment the generation for the given service_id.rNrrs rQincz_PoolGeneration.incs\ A  "// 3 !!*-2- 3   j )Q . )rSc*||j|k7S)z?Return if the given generation for a given service_id is stale.)rrrzrs rQstalez_PoolGeneration.stalesdhhz***rSNre)rOptional[ObjectId]rcrro)rrrcrdrzrrrrcr)rprqrrrrr|rrrUrSrQrxrxs -  /+rSrxceZdZdZdZdZy) PoolStaterN)rprqrrPAUSEDREADYCLOSEDrUrSrQrrs F E FrSrceZdZ d ddZddZeddZ d ddZddZ d ddZ ddZ dd Z dd Z dd Z dd d Zej d d!d Zd"dZ d d#dZd$dZd%dZd&dZddZy)'raNc|jrtj|_ntj|_d|_t j|_t|_ t|_ t|j|_d|_d|_d|_t%|_t)j*|_||_||_||_|j2 xr:|j0j4duxr |j0j4j6|_|j2 |_t|j|_d|_|j0j>|_|j>stAd|_t|j|_|j0jB|_"d|_#||_$|j6r\|j0j4J|j0j4jK|j.|j0jL|j8r~tOjPtRjTr[tWtNftXjZ|jH|j.d|j.dd|j0jLd|_.t|_/d|_0d|_1y)z :param address: a (hostname, port) tuple :param options: a PoolOptions instance :param is_sdam: whether to call hello for each new Connection rrNinfrr&r'r()2 pause_enabledrrstater_check_interval_secondsrzdequeconnssetactive_contextsr$lockr#_max_connecting_condactive_socketsnext_connection_idrerxrzosgetpidpidr]rnr_rorqrr size_condrequests max_pool_sizernmax_connecting_max_connecting_pendingrpublish_pool_creatednon_default_optionsr%r-r.r/r'r& POOL_CREATEDoperation_count_Pool__pinned_socketsncursorsntxns)rr]optionsr_ client_ids rQrz Pool.__init__sG  "))DJ"DJ()$)4(9(9(; :=% N $5dii$@!"#+/ #$99;     < **$6 < **;;  (,||#3 +4995 !YY44!!!&uD %6dii$@!#yy77 #  99--9 99 II & & ; ; dii;;   # #(:(G(G (V " 0==<<?<<?   ))//  %&25  rSc :|j5|jtjk7rtj|_|jrG|j j J|j j j|j|jritjtjrFtttj |j"|jd|jddddy#1swYyxYw)Nrrr)rrrrrqrnropublish_pool_readyr]rrr%r-r.r/r'r& POOL_READYrrs rQr~z Pool.readys YY zzY__,&__ ((9955AAAII..AA$,,O++0B0O0OPWP]P]0^* 8 C C!%#'<<?#'<<?    s C;DDc<|jtjk(Sr)rrrrs rQr`z Pool.closed-szzY----rSc|j}|j5|jr dddy|jjr:|r8|jj s"|jt jc}|_|jj|tj}|j|k7r||_ d|_ d|_|'|jt!j"c}|_ntt!j"}t!j"} |jD]4} | j$|k(r|j'| $| j'| 6|}| |_|rt j(|_|j*j-|jj-|r!|j.D]} | j1ddd|jj2} |rt4sAt7j8D cgc]!} | j;t<j>#c} ddin&D]!} | j;t<j>#|j@r| J| jC|jD|jFrktIjJtLjNrGtQtHtRj>|jT|jDd|jDdyyy|t jk7r|j@r"| J| jW|jD|||jFrjtIjJtLjNrGtQtHtRjX|jT|jDd|jDd|t4sAt7j8D cgc]!} | j;t<jZ#c} ddiyD]!} | j;t<jZ#y#1swYXxYwcc} wcc} w)Nrreturn_exceptionsTrr)rinterrupt_connections)rr&r'r( serviceId).rrr`rnrrrrrzrrrrrrrrzrrappendrr notify_allrr;ror?asynciogatherrr* POOL_CLOSEDrqpublish_pool_closedr]rrr%r-r.r/r'r&rpublish_pool_cleared POOL_CLEAREDr) rr<pauserr old_statenewpidsocketsdiscardkeepr\contextrps rQ_resetz Pool._reset1sxJJ ^^ %{{ % %yy&&59P9P(, I4D4D% 4: HHLL $YY[Fxx6!!&'#'($!&*jj+2C2C2E#-8->->-@*5*;*;*= JJ*D*4t, D) * "! &--  % % 0 0 2 NN % % '$#33%GNN$%? %DII..  V]^ddoo&<&H&HI^&* $HDOO$:$F$FGH$$ ,,,--dll;'',>,K,KGMM,Z&4@@!__#||A#||A -['I,,,(($00022 #-.C3 ++0B0O0OPWP]P]0^* 8 E E!%#'<<?#'<<?", PWXdoo&<&B&BCX&* $BDOO$:$@$@ABe % %R_JYsP4F.P4&Q&Q4P>c||_|j5|jD]}|j|j dddy#1swYyxYw)zXUpdates the is_writable attribute on all sockets currently in the Pool. N)rerrrJ)rre_sockets rQrJzPool.update_is_writablesO' YY =:: =**4+;+;< = = = =s -A  Ac,|jd||y)NF)r<rrr)rrrs rQresetz Pool.resets %JNc drSc*|jddy)NF)r<rrrs rQreset_without_pausezPool.reset_without_pauses %u -rSc(|jdy)NT)r<rrs rQr<z Pool.closes $ rSc:|jj||Sr)rzrrs rQstale_generationzPool.stale_generationsxx~~c:..rSc |j5|jtjk7r dddy ddd|jj .g}|j5|j r|j dj|jj kDrj|j|j j|j r5|j dj|jj kDrjdddtsAtj|Dcgc]!}|jtj#c}ddin&|D]!}|jtj# |j 5t#|j |j$z|jj&k\r dddy|j(|jj&k\r dddy|xj(dz c_dddd} |j*5|j,|j.k\r ddd|rD|j*5|xj,dzc_|j*j1ddd|j 5|xj(dzc_|j j1dddy|xj,dz c_d}ddd|j3}d}|j5|j4j7|k7rd}|s@|j j9||j:j=|j>ddd|r|jtj@ |rD|j*5|xj,dzc_|j*j1ddd|j 5|xj(dzc_|j j1dddy |rD|j*5|xj,dzc_|j*j1ddd|j 5|xj(dzc_|j j1ddd8#1swYxYw#1swYxYwcc}w#1swYxYw#1swY\xYw#1swYyxYw#1swYxYw#1swYxYw#1swY;xYw#1swYyxYw#1swYxYw#1swYxYw#|rQ|j*5|xj,dzc_|j*j1dddn #1swYnxYw|j 5|xj(dzc_|j j1dddw#1swYwxYwxYw)zRemoves stale sockets then adds new ones if pool is too small and has not been reset. The `reference_generation` argument specifies the `generation` at the point in time this operation was requested on the pool. NrTrF)!rrrrrnmax_idle_time_secondsrrLrpopr?rrrr*IDLErlenr min_pool_sizerrrrnotifyconnectrzr| appendleftrrrr)rreference_generation close_connsr\ incrementedrs rQremove_stale_socketszPool.remove_stale_socketssYY zzY__,  ,  99 * * 6K 9JJ 288:TYY=\=\\&&tzz~~'78JJ 288:TYY=\=\\ 9 OZ[tdoo&<&A&AB[&* (ADOO$:$?$?@A #tzz?T%8%88DII0T40U<S SS%(S25S>T U TU T%(T14T=U  W10V W1V W1,0W% W1%W. *W1c |j5|j}|xjdz c_t}|jj |ddd|j j }|jr |J|j|j|jrjtjtjrGttt j"|j$|jd|jd t'|j|j }tC|||j|jD}|j5|jj |jF|jj+dddjHr|jFjK |jDs!|jM|jN|_'|r|jQ|d|jS|r/|jVjXj[|j\|S#1swYxYw#t($re}|j5|jj+dddn #1swYnxYw|jr/|J|j-|jt.j0|jrtjtjrnttt j2|j$|jd|jdt5t.j0t.j0t7|t8t:gt<r-t?|j }tA|j||d}~wwxYw#1swY5xYw#t($rh|j5|jj+|jFdddn #1swYnxYw|jUt.j0wxYw) zConnect to Mongo and return a new Connection. Can raise ConnectionFailure. Note that the pool does not keep a reference to the socket -- you must call checkin() when you're done with it. rNrrr&r'r(r)r5rNF)completed_handshake)/rrr0raddrnrorqpublish_connection_createdr]rrr%r-r.r/r'r& CONN_CREATEDrr1r rr8r*rOr9r(rrPrQr/r r2rWr_r cancelledr;rrecontribute_socketr+rr _topologyreceive_cluster_timer) rhandlerconn_id tmp_contextrpnetworking_interfacerrRr\s rQrz Pool.connectscYY 2--G  # #q ( #.0K  $ $[ 1  2II..  ( ((  0 0w G  # #(:(G(G (V "0==<<?<<?#*   #? dii#X 6.dllGT\\Z YY 6  $ $T%8%8 9  ( ( 5 6     & & ( << #'#3#3 ))$E)J      NN $ $ 9 9$:L:L M S 2 20  :$$,,[9 : : :$$ ,,,33LL'+A+G+G'',>,K,KGMM,Z&4@@!__#||A#||A'.;>#&;;  ( ((  4 4T\\477H U  # #(:(G(G (V "0CC<<?<<?#'77#   >$$(()<)<= >J ?? %%))$/ a      #%%))$/ "  # #[[ LL 5 > >  __:(:(:F(+||~$'1x1dkk T"     # #sgF-M0 J=<&J1" J=.M1L07!M1L< (M1J:6J==A0L--M0L95M<MMc |jtjk7r:|rtj|z }|j rW|j jJ|j jj|jtj||jrztjtj rWt#tt$j&|j(|jd|jddtj|t+|j }t-|jt/d|yy)Nrr>+.CC((9955AAAII..RR &D&O&OQY++0B0O0OPWP]P]0^* 8 H H!%#'<<?#'<<?]<GG#+ +4995G % m,DEW^ + )rSc |jtjk7r|j|jr t j |z }|jrW|jjJ|jjj|jtj||jrztj t"j$rWt'tt(j*|j,|jd|jddtj|t/d|j05|xj2dz c_dddt5j6rt5j8}nD|jj:r,t j |jj:z}nd}|j<5|j?|d|j@|jBks|r|t j z nd}tE|j<|sD|j@|jBkr|j<jG|jI||j?|d|j@|jBks|xj@dz c_ dddd}d }d } |j05|xjJdz c_%d}ddd||jL5|j?|d |jNs|jP|jRks|r|t j z nd}tE|jL|sR|jNs|jP|jRkr|jLjGd}|jI||j?|d |jNs|jP|jRks |jNjU}ddd|r|jY|r[d}> |j[| }|jL5|xjPdzc_(|jLjGddd|d|_3|S#1swYDxYw#1swYxYw#1swYxYw#tV$r|xjPdz c_(YwxYw#1swYxYw#1swYmxYw#|jL5|xjPdzc_(|jLjGdddw#1swYwxYwxYw#t\$r|r|j_t`jb|j<5|xj@dzc_ |r|xjJdzc_%|j<jGdddn #1swYnxYw|st j |z }|jrW|jjJ|jjj|jtjd||jrztj t"j$rWt'tt(j*|j,|jd|jdd tjd|wxYw) z8Get or create a Connection. Can raise ConnectionFailure.NrrzConnection pool was closedrz?Attempted to check out a connection from closed connection poolT)rFrr)4rrrrr`rarbrqrnrorr]r)rrrr%r-r.r/r'r&rrrvrrr get_timeout get_deadlinewait_queue_timeoutrrrrr"r_raise_wait_queue_timeoutrrrrrpopleft IndexError _perishedrr rr*rOrr) rrrr1deadlinerr\r emitted_events rQrzPool._get_conns 88ryy{ "  $ $ & ;;~~'*??H$$yy11=== **NNLL"@"L"Lh'',>,K,KGMM,Z&4DD!__#||A#||A78DD' #Q YY &  A %  &    ))+H YY ) )~~'$))*F*FFHH ^^   $ $%:t $ L}}t'9'999A(T^^%55t!$..':}}t'9'99--/223HI(()>4(P}}t'9'99 MMQ M   @  ###q(#"  #,..+,,-Bu,U#zzT]]T=Q=Q-QAI(T^^-="=t)$*C*CWM $zzT]]T=Q=Q-Q $ 9 9 @ @ B,0M ::;PQ001FSX0Y $zzT]]T=Q=Q-Q+#zz113+"~~d+# ?#||G|<!66? MMQ.M 55<<>?9,|   & &  $ # #*&+ * +++2??T66? MMQ.M 55<<>???  6 < <= ( " ''1,'%%'  ( ( ( !>>+.CC((9955AAAII..RR &D&O&OQY++0B0O0OPWP]P]0^* 8 H H!%#'<<?#'<<?]<GG#+  9 sR.-CR;<R; U&,SU&C4S9S+U& T U&)0T U&.R8;SS U&S63S95S66S99T>U&T U& U#0U U#U U##U&&7[>AW-$ [>-W6 2D [>c n|j}|j}d|_d|_d|_|jj ||j j }|j5|jj |jddd|jr*|J|j|j|j|jrttj t"j$rQt'tt(j*|j,|jd|jd|j|j.t1j2k7r|j5n|j6r!|j9t:j<n|j6r|jr9|J|j?|j|jt:j@|jrgtj t"j$rCt'tt(jB|j,|jd|jd|jtEt:j@t:j@nd}|j5|jG|jH|jJrd}ni|jM|jOtQ|jR|jTjW||jXj[ddd|r|j9t:j\|j^5|r|xj`dzc_0n|r|xjbdzc_1|xjddzc_2|xjfdzc_3|xjhdzc_4|j^j[dddy#1swYxYw#1swYxYw#1swYyxYw)zReturn the connection to the pool, or if it's closed discard it. :param conn: The connection to check into the pool. FNrrrr5T)5rrrrrrnrorrrrqpublish_connection_checked_inr]r^rrr%r-r.r/r'r& CHECKEDINrrrrrr`rr*rr8rOr9r(rr}rrHrJrrerrrrrrrrrrr)rr\txncursorrprs rQrz Pool.checkin's oo## " %%d+II.. YY >  ( ()<)< = >  ( ((  3 3DLL$'' J  # #(:(G(G (V "0::<<?<<?#'77   88ryy{ "  $ $ &{{ 6 B BC(($00077 dgg/E/K/K++0B0O0OPWP]P]0^* 8 D D!%#'<<?#'<<?+/77?@V@\@\]4:: # YY ;,,T__dooN%) 557//T5E5E0FG --d31188: ;OO$:$@$@A ^^ $ a  " MMQ M   1 $   A % NN ! ! # $ $k > >N ; ; $ $s&+&P8BPB P+PP(+P4c|j}|jj9||jjkDr |jtj y|j N|j dk(s||j kDr0|jr |jtjy|j|j|jr |jtjyy)aReturn True and close the connection if it is "perished". This side-effecty function checks if this socket has been idle for for longer than the max idle time, or if the socket has been closed by some external network error, or if the socket's generation is outdated. Checking sockets lets us avoid seeing *some* :class:`~pymongo.errors.AutoReconnect` exceptions on server hiccups, etc. We only check if the socket was closed by an external error if it has been > 1 second since the socket was checked into the pool, to keep performance reasonable - we can't avoid AutoReconnects completely anyway. TrF) rLrnrrr*rrrBrOrr}rr)rr\rLs rQrzPool._perishedrs!224 II + + 7!DII$C$CC OO277 8  ' ' 3  ( (A -1BTEaEa1a! 6 < <=  $// B OO288 9rSc |jj}tj|z }|jr/|J|j |j tj||jrztjtjrWtttj |j"|j d|j ddtj|t%j&xs|jj(}|jj*rl|j,|j.z |j0z }t3dj5|jj6|j.|j0||t3d|jj6d|)NrrzBWait queue timeout elapsed without a connection becoming availablerzTimeout waiting for connection from the connection pool. maxPoolSize: {}, connections in use by cursors: {}, connections in use by transactions: {}, connections in use by other operations: {}, timeout: {}zMTimed out while checking out a connection from connection pool. maxPoolSize: z , timeout: )rnrorarbrqrr]r)TIMEOUTrrr%r-r.r/r'r&rrrrr rrrrrr^r)rrrpr1r other_opss rQr zPool._raise_wait_queue_timeoutsmII.. >>#&;;  ( ((  9 9 <DDh   # #(:(G(G (V "0@@<<?<<?[4<<# ##%E)E)E 99 " "++dmm;djjHI'78>vII++MMJJ 8  $  II334Ky J  rScVtr#|jD]}|jdyyr)r?rr)rr\s rQ__del__z Pool.__del__s+   &% & rS)FN)r]rGrr.r_rrrrerm)TNF) r<rrrrrrrrcrd)rezOptional[bool]rcrd)NF)rrrrrcrdr)rrrcrdr)r"Optional[_MongoClientErrorHandler]rcrW)rrrczGenerator[Connection, None])rrnrrrcrd)rrnrrrcrW)r\rWrcrd)r\rWrcr)rrnrcr )rprqrrrr~propertyr`rrJrrr<rrr contextlibcontextmanagerrrrrrr rrUrSrQrarasc (, TTT T & Tl".. )-&+ [B[B[B' [B $ [B  [Bz=TYe,eLPe e . /C,JQf<@L9L $LL\6[_%*5W BI$V"H% N&rSra)rOrrcrd)x __future__rrrzrr.rrrarYtypingrrrrrr r r r bsonr pymongorrpymongo.commonrrrrrpymongo.errorsrrrrrrrrr pymongo.hellorrpymongo.helpers_sharedr r! pymongo.lockr"r#r$pymongo.loggerr%r&r'r(pymongo.monitoringr)r*pymongo.network_layerr+r,r-pymongo.pool_optionsr.pymongo.pool_sharedr/r0r1r2pymongo.read_preferencesr3pymongo.server_apir4pymongo.server_typer5pymongo.socket_checkerr6"pymongo.synchronous.client_sessionr7pymongo.synchronous.helpersr8pymongo.synchronous.networkr9r: bson.objectidr;pymongo.compression_supportr<r=r>pymongo.messager?r@pymongo.read_concernrArBpymongo.synchronous.authrCrD pymongo.synchronous.mongo_clientrErFpymongo.typingsrGrHpymongo.write_concernrIrMrJrKrLrR ImportErrorr?rWrvrxrrarUrSrQr>s8#    ')   -O  PO, 4.+0N6/!& 1045@V62 E99/ W W t| ++>~ &~ &eEE Es2E88 FF