
    i                       S SK Jr  S SKrS SKrS SKrS SKrS SKrS SKrS SKrS SK	r	S SK
JrJrJrJrJrJrJrJr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  S SKJ r J!r!J"r"J#r#J$r$J%r%J&r&J'r'J(r(  S SK)J*r*J+r+  S S	K,J-r-J.r.  S S
K/J0r0J1r1J2r2  S SK3J4r4J5r5J6r6J7r7  S SK8J9r9J:r:  S SK;J<r<J=r=J>r>  S SK?J@r@  S SKAJBrBJCrCJDrDJErE  S SKFJGrG  S SKHJIrI  S SKJJKrK  S SKLJMrM  S SKNJOrO  S SKPJQrQ  S SKRJSrS  \(       aL  S SKJTrT  S SKUJVrV  S SKWJXrXJYrYJZrZ  S SK[J\r\J]r]  S SK^J_r_  S SKFJ`r`  S SKaJbrb  S SKNJcrc  S SKdJereJfrf  S S KgJhrhJiri  S S!KjJkrk  S"rl " S# S$5      rm " S% S&\'5      rn " S' S(5      ro " S) S*5      rp " S+ S,5      rqg)-    )annotationsN)	TYPE_CHECKINGAny	GeneratorMappingMutableMappingNoReturnOptionalSequenceUnion)DEFAULT_CODEC_OPTIONS)_csothelpers_shared)MAX_BSON_SIZEMAX_MESSAGE_SIZEMAX_WIRE_VERSIONMAX_WRITE_BATCH_SIZEORDERED_TYPES)	AutoReconnectConfigurationErrorDocumentTooLargeExecutionTimeoutInvalidOperationNotPrimaryErrorOperationFailurePyMongoErrorWaitQueueTimeoutError)HelloHelloCompat)_get_timeout_detailsformat_timeout_details)
_cond_wait_create_condition_create_lock)_CONNECTION_LOGGER_ConnectionStatusMessage
_debug_log _verbose_connection_error_reason)ConnectionCheckOutFailedReasonConnectionClosedReason)NetworkingInterfacereceive_messagesendall)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)WriteConcernTc                  *   \ rS rSrS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	 jrS+S
 jr      S,S jrS*S jr\\R"                  \SSSSSSSSSSSS4                                 S-S jj5       rS.S jrS/S jrS0S jrS1S jr        S2S jrS3S4S jjr      S5S jrS6S jrS)S jrS7S jr        S8S jrS9S 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# jr&S?S$ jr'S%r(g)@
Connectiono   a  Store 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                   [         R                  " U5      U l        Xl        X0l        X@l        XPl        SU l        [        R                  " 5       U l
        SU l        SU l        [        U l        [        U l        ["        U l        [&        U l        SU l        SU l        SU l        SU l        UR2                  R4                  U l        UR8                  U l        UR:                  U l        UR2                  R<                  U l        S U l         [C        5       U l"        S U l#        S U l$        S U l%        URL                  U l'        U RN                  RQ                  5       U l)        SU l*        [W        5       U l,        UR2                  U l        SU l-        S U l.        S U l/        SU l0        SU l1        SU l2        U R2                  Rf                  U l4        SU l5        URl                  U l6        [        R                  " 5       U l7        S U l8        g )NFg        )9weakrefrefpool_refconnaddressidis_sdamclosedtime	monotoniclast_checkin_timeperformed_handshakeis_writabler   max_wire_versionr   max_bson_sizer   max_message_sizer   max_write_batch_sizesupports_sessionshello_ok	is_mongosop_msg_enabledopts_event_listeners	listenersenabled_for_cmapenabled_for_logging_compression_settingscompression_settingscompression_contextr6   socket_checkeroidc_token_gen_idnegotiated_mechsauth_ctxgenpool_genget_overall
generationreadyr0   cancel_contextmore_to_come
service_idserver_connection_id
pinned_txnpinned_cursoractivesocket_timeoutlast_timeoutconnect_rtt
_client_idcreation_time_cluster_time)selfrQ   poolrR   rS   rT   s         E/app/mltbenv/lib/python3.13/site-packages/pymongo/synchronous/pool.py__init__Connection.__init__y   s     D)	!%!1#( !& 0* 0$8!!&##33 $ 5 5#'#;#; $(II$C$C!Y] -:_045904 --335
4H4JII	"'.237!  " II44//!^^-!    c                z    XR                   :X  a  gXl         U R                  R                  R                  U5        g)z?Cache last timeout to avoid duplicate calls to conn.settimeout.N)r|   rQ   get_conn
settimeout)r   timeouts     r   set_conn_timeoutConnection.set_conn_timeout   s/    '''#		%%g.r   c                   [         R                  " 5       nUc7  U R                  (       d%  U R                  U R                  R
                  5        g [         R                  " 5       nUc  U R                  nX4-
  nUS:  aI  [        U R                  5      n[        U5      nSUS SUS SU 3n[        USSUSS.U R                  5      eUb  [        US-  5      US	'   U R                  U5        U$ )
Nr   z5operation would exceed time limit, remaining timeout:z.5fz <= network round trip time: 2   okerrmsgcode  	maxTimeMS)r   	remainingru   r   rc   r{   get_rttr}   r    r!   r   r[   int)	r   clientcmdr   rttmax_time_mstimeout_details	formattedr   s	            r   apply_timeoutConnection.apply_timeout   s     //#?$$%%dii&>&>?mmo;""Cm?2499=O.?ILWUXMYuvyz}u~~  AJ  @K  LF"FB7%%	  ?";#56Cg&r   c                8    SU l         U R                  (       a   eg NT)rx   ry   r   s    r   pin_txnConnection.pin_txn   s    %%%%%r   c                8    SU l         U R                  (       a   eg r   )ry   rx   r   s    r   
pin_cursorConnection.pin_cursor   s    !??""?r   c                    U R                  5       nU(       a  UR                  U 5        g U R                  [        R                  5        g N)rP   checkin
close_connr*   STALE)r   r   s     r   unpinConnection.unpin   s/    }}LLOO2889r   c                    U R                   R                  (       d,  U R                  (       d  U R                   R                  (       a  SU l        [
        R                  S0$ [
        R                  SSS0$ )NT   helloOk)rc   
server_apir`   load_balancedrb   r   CMD
LEGACY_CMDr   s    r   	hello_cmdConnection.hello_cmd   sO     994==DII4K4K"&DOOQ''**Ay$??r   c                &    U R                  S S 5      $ r   )_hellor   s    r   helloConnection.hello   s    {{4&&r   c                   U R                  5       nU R                  (       + nSnU(       ak  SU l        U R                  R                  US'   U R                  (       a  U R                  R
                  US'   U R                  R                  (       a  SUS'   ObUb_  XS'   Uc   e[        US-  5      US'   SnU R                  R                  (       a(  U R                  U R                  R                  U-   5        U R                  R                  nU(       a  UR                  S	:X  a0  UR                  (       a  UR                  S
-   UR                  -   US'   SSKJn  UR                   R#                  X`R$                  5      nU(       a  UR'                  5       n	U	b  XS'   OS nU(       a  [(        R*                  " 5       n
U R-                  SUSUS9nU(       a  [(        R*                  " 5       W
-
  U l        [1        XS9nUR2                  U l        UR4                  U l        UR6                  U l        UR8                  U l        UR:                  U l        UR<                  S L=(       a    UR>                  U l         UR<                  U l        URB                  U l!        URD                  [F        RH                  [F        RJ                  [F        RL                  [F        RN                  [F        RP                  4;   U l)        URD                  [F        RT                  :H  U l+        URD                  [F        RX                  :H  U l-        U(       a<  U R                  (       a+  U R                  R]                  UR
                  5      nXl/        SU l0        URb                  U l2        U(       a  URf                  U l4        U(       a,  URk                  U5        URm                  5       (       a  Xl7        U R                  R                  (       aW  URp                  (       d  [s        S5      eURp                  U l8        U Rt                  Rw                  U Rp                  5      U l<        U$ )NFTr   compressionloadBalancedtopologyVersionr   maxAwaitTimeMSDEFAULT.saslSupportedMechsr   authspeculativeAuthenticateadmin)publish_eventsexhaust_allowed)	awaitablez`Driver attempted to initialize in load balancing mode, but the server does not support this mode)=r   rY   rc   metadatari   compressorsr   r   connect_timeoutr   _credentials	mechanismusernamesourcepymongo.synchronousr   rC   from_credentialsrR   speculate_commandrV   rW   r9   r}   r   rZ   r[   r\   r]   r^   logical_session_timeout_minutesis_readabler_   r`   server_typer5   	RSPrimaryRSSecondary	RSArbiterRSOtherRSGhostis_repl
Standaloneis_standaloneMongosra   get_compression_contextrj   rb   connection_idrw   sasl_supported_mechsrm   parse_responsespeculate_succeededrn   rv   r   rp   getrr   )r   topology_versionheartbeat_frequencyr   performing_handshaker   credsr   rn   speculative_authenticatestartdocr   ctxs                 r   r   Connection._hello   so   
 nn#'#;#;;	'+D$ II..CM((%)%>%>%J%JM"yy&&&*N#)%5!"&222$'(;d(B$CC !Iyy((%%dii&?&?BU&UV		&&)+,1LL3,>,O()0((99%NH+3+E+E+G(+75M12HNN$Ell7CylY#~~/%7Dc/ ,, % 6 6"00 % 6 6$)$>$>!11=S%BSBS 	 ?D>c>c,((!!##!!-
 
 #..+2H2HH**k.@.@@D$=$=++CCEDUDUVC'*$"$)$7$7!$)$>$>D!##E*++-- (99""##(A  $..DO"mm//@DOr   c                    U R                  S 5      nUR                  U l        UR                  5       nUS   n[        R                  " X0R
                  5        U$ Nr   )r,   ru   unpack_responser   _check_command_responser[   )r   replyunpacked_docsresponse_docs       r   _next_replyConnection._next_replyJ  sR    $$T*!..--/$Q'..|=R=RSr   TNFc                   U R                  X5        [        X5      n[        U[        5      (       d  [	        U5      nUb  UR
                  (       d  U
b  [        S5      eU R                  U5        U(       a  UR                  X-X05        U R                  X+U5        U(       a  U R                  OSn[        U=(       a    UR
                  (       + 5      nU R                  (       a  U R                  U5         [        U UUU R                  UUUUUUU R                   UU R"                  UU	U
U R$                  U R                  UUUUS9$ ! [&        [(        4 a    e [*         a  nU R-                  U5         SnAgSnAff = f)a  Execute 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	collationcompression_ctx
use_op_msgunacknowledgeduser_fieldsr   write_concern)validate_sessionr7   
isinstancer   dictacknowledgedr   add_server_api	_apply_tosend_cluster_timere   boolrb   _raise_if_not_writabler9   ra   rR   r\   rj   r   r   BaseExceptionr2   )r   dbnamespecread_preferencecodec_optionscheckallowable_errorsread_concernr  r   r   sessionr   retryable_writer   r   r   re   r   errors                       r   r9   Connection.commandR  sb   R 	f.1'I $..:D%)C)CyGX$%Z[[D!d_Ktf5&4DNN$	mNM4N4N0NO''7	2 ""*C# $ 8 8..-' /+- 0 !/2 	 	2**511	2s   6AE E; E66E;c                    U R                   b(  X R                   :  a  [        SX R                   4-  5      e [        U R                  R                  U5        g! [
         a  nU R                  U5         SnAgSnAff = f)zmSend 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.)r\   r   r-   rQ   r   r  r2   )r   messagemax_doc_sizer  s       r   send_messageConnection.send_message  sy    
 )l=O=O.O"?BNPbPbAcd 
	2DII&&0 	2**511	2s    A 
A="A88A=c                     [        XU R                  5      $ ! [         a  nU R                  U5         SnAgSnAff = f)zjReceive a raw BSON message or raise ConnectionFailure.

If any exception is raised, the socket is closed.
N)r,   r]   r  r2   )r   
request_idr  s      r   r,   Connection.receive_message  s;    
	2"4T5J5JKK 	2**511	2s    
=8=c                V    U(       a"  U R                   (       d  [        SSSSS.5      egg)zNRaise NotPrimaryError on unacknowledged write if this socket is not
writable.
znot primaryr   i{'  r   N)rZ   r   )r   r   s     r   r
  !Connection._raise_if_not_writable  s+     $"2"2!-]\a1bcc #3>r   c                H    U R                  S5        U R                  X5        g)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  )r   msgr  s      r   unack_writeConnection.unack_write  s      	##D)#,r   c                    U R                  US5        U R                  U5      nUR                  U5      n[        R                  " XPR
                  5        U$ )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   )r  r,   command_responser   r   r[   )r   r  r"  r  r   results         r   write_commandConnection.write_command  sO     	#q!$$Z0''6 	..v7L7LMr   c           
        U(       a  U R                   (       a  SU l        SU l        U R                  (       Gd9  U R                  R                  nU(       a  SSKJn  UR                  X US9  SU l        [        R                  " 5       U R                  -
  nU R                  (       a@  U R                  c   eU R                  R                  U R                  U R                  U5        U R                   (       az  ["        R$                  " [&        R(                  5      (       aP  [+        ["        [,        R.                  U R0                  U R                  S   U R                  S   U R                  US9  gggg)	zXAuthenticate to the server if needed.

Can raise ConnectionFailure or OperationFailure.
NFr   r   )reauthenticateTr   r  clientId
serverHost
serverPortdriverConnectionId
durationMS)rY   rn   rs   rc   r   r   r   authenticaterV   rW   r   rf   re   publish_connection_readyrR   rS   rg   r%   isEnabledForloggingDEBUGr'   r&   
CONN_READYr~   )r   r+  r   r   durations        r   r2  Connection.authenticate  s    '' $DJzzzII**E4!!%n!MDJ~~'$*<*<<H$$~~11177dggxX'',>,K,KGMM,Z,Z&4??!__#||A#||A'+ww' -[' r   c                H    U(       a  UR                   ULa  [        S5      egg)zsValidate 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   )r   r   r  s      r   r  Connection.validate_session  s)     f,&'bcc - r   c                $   U R                   (       a  gU R                  5         U(       a  U R                  (       a@  U R                  c   eU R                  R	                  U R
                  U R                  U5        U R                  (       a  [        R                  " [        R                  5      (       aZ  [        [        [        R                  U R                  U R
                  S   U R
                  S   U R                  [!        U5      US9  gggg)z$Close this connection with a reason.Nr   r   r  r-  r.  r/  r0  reasonr  )rU   _close_connrf   re   publish_connection_closedrR   rS   rg   r%   r4  r5  r6  r'   r&   CONN_CLOSEDr~   r(   )r   r?  s     r   r   Connection.close_conn  s    ;;$$~~11188twwPVW'',>,K,KGMM,Z,Z&4@@!__#||A#||A'+ww;FC 	 -['	 r   c                    U R                   (       a  gSU l         U R                  R                  5          U R                  R	                  5         g! [
         a     gf = f)zClose this connection.NT)rU   rt   cancelrQ   close	Exceptionr   s    r   r@  Connection._close_conn/  sJ    ;;""$	IIOO 		s   A 
AAc                    [         (       a/  U R                  R                  U R                  R                  5      $ U R                  R                  5       $ )z?Return True if we know socket has been closed, False otherwise.)_IS_SYNCrk   socket_closedrQ   r   
is_closingr   s    r   conn_closedConnection.conn_closed<  s;    8&&44TYY5G5GHH99''))r   c                6    U(       a  UR                  X5        gg)zAdd $clusterTime.N)_send_cluster_time)r   r9   r  r   s       r   r  Connection.send_cluster_timeC  s     %%g7 r   c                z    U R                   R                  (       a   [        XR                   R                  5        gg)zAdd server_api parameters.N)rc   r   r4   )r   r9   s     r   r  Connection.add_server_apiM  s&    99GYY%9%9:  r   c                8    [         R                  " 5       U l        g r   rV   rW   rX   r   s    r   update_last_checkin_time#Connection.update_last_checkin_timeR  s    !%!1r   c                    Xl         g r   )rZ   )r   rZ   s     r   update_is_writableConnection.update_is_writableU  s    &r   c                F    [         R                  " 5       U R                  -
  $ )z9Seconds since this socket was last checked into its pool.rU  r   s    r   idle_time_secondsConnection.idle_time_secondsX  s    ~~$"8"888r   c                   U R                   (       a  S nO[        R                  nU R                  U5        [	        U[
        [        /[        Q75      (       a*  [        U R                  5      n[        U R                  XS9  g e )Nr   )rs   r*   ERRORr   r  IOErrorOSErrorr/   r    rc   r2   rR   )r   r  r?  detailss       r   r2   $Connection._raise_connection_failure\  s]      ::F+11Fegw;;<<*4995G%dllESr   c                4    U R                   UR                   :H  $ r   )rQ   r   others     r   __eq__Connection.__eq__x  s    yyEJJ&&r   c                    X:X  + $ r    rf  s     r   __ne__Connection.__ne__{  s      r   c                ,    [        U R                  5      $ r   )hashrQ   r   s    r   __hash__Connection.__hash__~  s    DIIr   c                    SR                  [        U R                  5      U R                  =(       a    S=(       d    S[	        U 5      5      $ )NzConnection({}){} at {}z CLOSED )formatreprrQ   rU   rS   r   s    r   __repr__Connection.__repr__  s8    '..OKK%I+tH
 	
r   )-r~   r   rz   rR   rn   rt   rU   rj   ri   rQ   r}   r   rf   rg   rr   r`   rS   ra   r   rT   r   rZ   rX   r|   re   r   r\   r]   r[   r^   ru   rm   rl   rb   rc   rY   ry   rx   rp   rP   rs   rw   rv   rk   r_   )
rQ   r+   r   PoolrR   ztuple[str, int]rS   r   rT   r	  )r   Optional[float]returnNone)r   zMongoClient[Any]r   z"Optional[MutableMapping[str, Any]]rz  ry  rz  r{  )rz  dict[str, Any])rz  Hello[dict[str, Any]])r   zOptional[Any]r   Optional[int]rz  r~  )"r  strr  MutableMapping[str, Any]r  rB   r  CodecOptions[Mapping[str, Any]]r  r	  r  z#Optional[Sequence[Union[str, int]]]r  zOptional[ReadConcern]r  zOptional[WriteConcern]r   r	  r   zOptional[_CollationIn]r  Optional[ClientSession]r   Optional[MongoClient[Any]]r  r	  r   r	  r   zOptional[Mapping[str, Any]]r   r	  rz  r}  )r  bytesr  r   rz  r{  )r  r  rz  zUnion[_OpReply, _OpMsg])r   r	  rz  r{  )r"  r  r  r   rz  r{  )r  r   r"  r  r  r  rz  r}  )F)r+  r	  rz  r{  )r   r  r  r  rz  r{  )r?  zOptional[str]rz  r{  rz  r	  )r9   r  r  r  r   r  rz  r{  )r9   r  rz  r{  )rZ   r	  rz  r{  )rz  float)r  r  rz  r	   )rg  r   rz  r	  rz  r   )rz  r  ))__name__
__module____qualname____firstlineno____doc__r   r   r   r   r   r   r   r   r   r   r8   r3   PRIMARYr   r9   r  r,   r
  r#  r(  r2  r  r   r@  rM  r  r  rV  rY  r\  r2   rh  rl  rp  rv  __static_attributes__rk  r   r   rK   rK   o   sn   9"!9" 9" !	9"
 9" 9"v/&-O	>&#:@'S'S +S 
	Sj 
 (6'='=9N@D.204*/,0+/-1 %#37 %#W2W2 'W2 %	W2
 7W2 W2 >W2 ,W2 .W2 $(W2 *W2 )W2 +W2 W2 W2  1!W2" #W2$ 
%W2 W2r2"	2d	-$):Y	$ D	d0	d;R	d		d**8)8 )8 +	8
 
8;
2'98'!
r   rK   c                      \ rS rSrSrSrg)_PoolClosedErrori  zRInternal error raised when a thread tries to get a connection from a
closed pool.
rk  N)r  r  r  r  r  r  rk  r   r   r  r    s    r   r  c                  F    \ rS rSrS	S jrS
S jrSS jrSS jrSS jrSr	g)_PoolGenerationi  c                P    [         R                  " [        5      U l        SU l        g r   )collectionsdefaultdictr   _generations_generationr   s    r   r   _PoolGeneration.__init__  s    1<1H1H1Mr   c                >    Uc  U R                   $ U R                  U   $ )z,Get the generation for the given service_id.r  r  r   rv   s     r   r   _PoolGeneration.get  s%    ###  ,,r   c                    U R                   $ )z"Get the Pool's overall generation.)r  r   s    r   rq   _PoolGeneration.get_overall  s    r   c                    U =R                   S-  sl         Uc+  U R                   H  nU R                  U==   S-  ss'   M     gU R                  U==   S-  ss'   g)z2Increment the generation for the given service_id.r   Nr  r  s     r   inc_PoolGeneration.inc  sW    A"//
!!*-2- 0 j)Q.)r   c                (    XR                  U5      :g  $ )z?Return if the given generation for a given service_id is stale.)r   r   ro   rv   s      r   stale_PoolGeneration.stale  s    hhz***r   r  Nr|  )rv   Optional[ObjectId]rz  r   r  )rv   r  rz  r{  ro   r   rv   r  rz  r	  )
r  r  r  r  r   r   rq   r  r  r  rk  r   r   r  r    s    - /+r   r  c                       \ rS rSrSrSrSrSrg)	PoolStatei  r         rk  N)r  r  r  r  PAUSEDREADYCLOSEDr  rk  r   r   r  r    s    FEFr   r  c                  R   \ rS rSr  S       SS jjrSS jr\SS j5       r   S         SS jjrSS jr	 S     SS jjr
SS	 jrSS
 jrSS jrS S jrS!S"S jjr\R"                   S!   S#S jj5       rS$S jr S!     S%S jjrS&S jrS'S jrS(S jrSS jrSrg))rx  i  Nc                >   UR                   (       a  [        R                  U l        O[        R                  U l        SU l        [        R                  " 5       U l        [        5       U l
        [        5       U l        [        U R                  5      U l        SU l        SU l        SU l        [%        5       U l        [(        R*                  " 5       U l        Xl        X l        X0l        U R2                  (       + =(       a?    U R0                  R4                  SL=(       a     U R0                  R4                  R6                  U l        U R2                  (       + U l        [        U R                  5      U l        SU l        U R0                  R>                  U l        U R>                  (       d  [A        S5      U l        [        U R                  5      U l        U R0                  RB                  U l"        SU l#        X@l$        U R6                  (       a]  U R0                  R4                  c   eU R0                  R4                  RK                  U R.                  U R0                  RL                  5        U R8                  (       a  [N        RP                  " [R        RT                  5      (       a[  [W        [N        4[X        RZ                  U RH                  U R.                  S   U R.                  S   S.U R0                  RL                  D6  SU l.        [        5       U l/        SU l0        SU l1        g)z
:param address: a (hostname, port) tuple
:param options: a PoolOptions instance
:param is_sdam: whether to call hello for each new Connection
r   r   Ninfr  r-  r.  r/  )2pause_enabledr  r  stater  _check_interval_secondsr  dequeconnssetactive_contextsr$   lockr#   _max_connecting_condactive_socketsnext_connection_idrZ   r  ro   osgetpidpidrR   rc   rT   rd   rf   rg   	size_condrequestsmax_pool_sizer  max_connecting_max_connecting_pendingr~   publish_pool_creatednon_default_optionsr%   r4  r5  r6  r'   r&   POOL_CREATEDoperation_count_Pool__pinned_socketsncursorsntxns)r   rR   optionsrT   	client_ids        r   r   Pool.__init__  sC      "))DJ"DJ ()$ 5@4E4E4G
:=% N	$5dii$@!"#+/
 #$99;	  <		**$6<		**;; 	
 (,||#3 
 +4995!YY44!!!&uD %6dii$@!#yy77#  99--999II&&;;dii;; ##(:(G(G(V(V"0==<<?<<? ))// %& 25
r   c           	     b   U R                      U R                  [        R                  :w  a  [        R                  U l        U R                  (       aH  U R
                  R                  c   eU R
                  R                  R                  U R                  5        U R                  (       al  [        R                  " [        R                  5      (       aC  [        [        [        R                   U R"                  U R                  S   U R                  S   S9  S S S 5        g ! , (       d  f       g = f)Nr   r   r  )r  r  r  r  rf   rc   rd   publish_pool_readyrR   rg   r%   r4  r5  r6  r'   r&   
POOL_READYr~   r   s    r   rs   
Pool.ready  s    YYzzY__,&__
((9955AAAII..AA$,,O++0B0O0OPWP]P]0^0^* 8 C C!%#'<<?#'<<? YYs   D
D  
D.c                <    U R                   [        R                  :H  $ r   )r  r  r  r   s    r   rU   Pool.closed  s    zzY----r   c           	     R	   U R                   nU R                     U R                  (       a
   S S S 5        g U R                  R                  (       aC  U(       a<  U R                  R
                  (       d!  U R                   [        R                  soPl         U R                  R                  U5        [        R                  " 5       nU R                  U:w  a  X`l        SU l        SU l        Uc'  U R                  [         R"                  " 5       sopl        Oy[         R"                  " 5       n[         R"                  " 5       n	U R                   H7  n
U
R$                  U:X  a  UR'                  U
5        M&  U	R'                  U
5        M9     UnXl        U(       a  [        R(                  U l         U R*                  R-                  5         U R                  R-                  5         U(       a#  U R.                   H  nUR1                  5         M     S S S 5        U R                  R2                  nU(       Ga(  [4        (       dD  [6        R8                  " W V
s/ s H!  oR;                  [<        R>                  5      PM#     sn
SS06  O(W H"  n
U
R;                  [<        R>                  5        M$     U R@                  (       a   Uc   eURC                  U RD                  5        U RF                  (       an  [H        RJ                  " [L        RN                  5      (       aD  [Q        [H        [R        R>                  U RT                  U RD                  S   U RD                  S   S9  g g g U[        R                  :w  a  U R@                  (       a   Uc   eURW                  U RD                  UUS9  U RF                  (       am  [H        RJ                  " [L        RN                  5      (       aD  [Q        [H        [R        RX                  U RT                  U RD                  S   U RD                  S   US9  [4        (       dD  [6        R8                  " W V
s/ s H!  oR;                  [<        RZ                  5      PM#     sn
SS06  g W H"  n
U
R;                  [<        RZ                  5        M$     g ! , (       d  f       GN= fs  sn
f s  sn
f )Nr   return_exceptionsTr   r  )rv   interrupt_connections)r  r-  r.  r/  	serviceId).r  r  rU   rc   r  r   r  r  ro   r  r  r  r  r  r  r  r  r  rv   appendr  r  
notify_allr  rE  rd   rJ  asynciogatherr   r*   POOL_CLOSEDrf   publish_pool_closedrR   rg   r%   r4  r5  r6  r'   r&   r~   publish_pool_clearedPOOL_CLEAREDr   )r   rF  pauserv   r  	old_statenewpidsocketsdiscardkeeprQ   contextre   s                r   _resetPool._reset   s_    JJ	^^{{ ^ yy&&59P9P(,

I4D4D%	:HHLL$YY[Fxx6!!&'#'($!&*jj+2C2C2E#-8->->-@*5*;*;*= JJD*4t,D)	 '
 "!
&--
%%002NN%%'$#33GNN$  4? D II..	 8V]^V]doo&<&H&HIV]^&*
 $DOO$:$F$FG $$$ ,,,--dll;'',>,K,KGMM,Z,Z&4@@!__#||A#||A -[' I,,,(($00022#-.C 3 
 ++0B0O0OPWP]P]0^0^* 8 E E!%#'<<?#'<<?", 8PWXPWoo&<&B&BCPWX&*
 $DOO$:$@$@A $e ^R _J Ys   RGR	(R4(R$
Rc                    Xl         U R                     U R                   H  nUR                  U R                   5        M      SSS5        g! , (       d  f       g= f)zHUpdates the is_writable attribute on all sockets currently in the
Pool.
N)rZ   r  r  rY  )r   rZ   _sockets      r   rY  Pool.update_is_writable}  s=     'YY::**4+;+;< & YYs   /A
Ac                $    U R                  SXS9  g )NF)rF  rv   r  r  )r   rv   r  s      r   reset
Pool.reset  s     	%Jdr   c                $    U R                  SSS9  g )NF)rF  r  r  r   s    r   reset_without_pausePool.reset_without_pause  s    %u-r   c                "    U R                  SS9  g )NT)rF  r  r   s    r   rF  
Pool.close  s    $r   c                8    U R                   R                  X5      $ r   )ro   r  r  s      r   stale_generationPool.stale_generation  s    xx~~c..r   c                   U R                      U R                  [        R                  :w  a
   SSS5        g SSS5        U R                  R
                  GbE  / nU R                      U R                  (       a  U R                  S   R                  5       U R                  R
                  :  aq  UR                  U R                  R                  5       5        U R                  (       a7  U R                  S   R                  5       U R                  R
                  :  a  Mq  SSS5        [        (       dD  [        R                  " U Vs/ s H!  o3R                  [        R                  5      PM#     snSS06  O(U H"  nUR                  [        R                  5        M$      U R                      [#        U R                  5      U R$                  -   U R                  R&                  :  a
   SSS5        gU R(                  U R                  R&                  :  a
   SSS5        gU =R(                  S-  sl        SSS5        Sn U R*                     U R,                  U R.                  :  a   SSS5        U(       aD  U R*                     U =R,                  S-  sl        U R*                  R1                  5         SSS5        U R                      U =R(                  S-  sl        U R                   R1                  5         SSS5        gU =R,                  S-  sl        SnSSS5        U R3                  5       nSnU R                      U R4                  R7                  5       U:w  a  SnU(       d@  U R                  R9                  U5        U R:                  R=                  UR>                  5        SSS5        U(       a  UR                  [        R@                  5         U(       aD  U R*                     U =R,                  S-  sl        U R*                  R1                  5         SSS5        U R                      U =R(                  S-  sl        U R                   R1                  5         SSS5        g U(       aD  U R*                     U =R,                  S-  sl        U R*                  R1                  5         SSS5        U R                      U =R(                  S-  sl        U R                   R1                  5         SSS5        GMV  ! , (       d  f       GN= f! , (       d  f       GN= fs  snf ! , (       d  f       GN= f! , (       d  f       GN= f! , (       d  f       g= f! , (       d  f       GNE= f! , (       d  f       GN= f! , (       d  f       GNi= f! , (       d  f       g= f! , (       d  f       N= f! , (       d  f       N= f! U(       aV  U R*                     U =R,                  S-  sl        U R*                  R1                  5         SSS5        O! , (       d  f       O= fU R                      U =R(                  S-  sl        U R                   R1                  5         SSS5        f ! , (       d  f       f = f= f)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.
Nr  Tr   F)!r  r  r  r  rc   max_idle_time_secondsr  r\  r  poprJ  r  r  r   r*   IDLEr  lenr  min_pool_sizer  r  r  r  notifyconnectro   rq   
appendleftr  r  rt   r   )r   reference_generationclose_connsrQ   incrementedr   s         r   remove_stale_socketsPool.remove_stale_sockets  sR    YYzzY__, Y,  99**6KJJ

288:TYY=\=\\&&tzz~~'78 JJ

288:TYY=\=\\  8OZ[{too&<&A&AB{[&*
 (DOO$:$?$?@ ( tzz?T%8%88DII<S<SS   ==DII$;$;;   "    K,.. }}(<(<<	 /* 22*1188: 3 ^^MMQ&MNN))+ $^- MMQ&M"&K / ||~"
YY xx++-1EE%)
%

--d3,,44T5H5HI  OO$:$@$@A22*1188: 3 ^^MMQ&MNN))+ $^  22*1188: 3 ^^MMQ&MNN))+ $K + Y  \  @ 32 $^7 /. Y 32 $^	 32 $^ 22*1188: 322 ^^MMQ&MNN))+ $^^s    S3%B6T(T)<T.%TT<V: U$V: ?0T.0U <U&V: 9A(U#!.V: #0U5'0V40V80V)3
T
T
T+.
T= 
U
U V: #
U2-V: 5
V
V
V&)
V7:Y.0X>	Y.
XY.$0Y	Y.
Y+'Y.c                8	   U R                      U R                  nU =R                  S-  sl        [        5       nU R                  R	                  U5        SSS5        U R
                  R                  nU R                  (       a!  Uc   eUR                  U R                  W5        U R                  (       am  [        R                  " [        R                  5      (       aD  [        [        [         R"                  U R$                  U R                  S   U R                  S   WS9   ['        U R                  U R
                  5      n[C        XPU R                  WU RD                  5      nU R                      U R                  R	                  URF                  5        U R                  R+                  W5        SSS5        WRH                  (       a  URF                  RK                  5          U RD                  (       d!  URM                  5         URN                  U l'        U(       a  URQ                  USS9  URS                  5         U(       a/  URV                  RX                  R[                  UR\                  5        U$ ! , (       d  f       GN*= f! [(         Gay  nU R                      U R                  R+                  W5        SSS5        O! , (       d  f       O= fU R                  (       a0  Uc   eUR-                  U R                  W[.        R0                  5        U R                  (       a  [        R                  " [        R                  5      (       ak  [        [        [         R2                  U R$                  U R                  S   U R                  S   W[5        [.        R0                  5      [.        R0                  S9  [7        U[8        [:        /[<        Q75      (       a)  [?        U R
                  5      n[A        U R                  XgS9  e SnAff = f! , (       d  f       GNe= f! [(         am    U R                      U R                  R+                  URF                  5        SSS5        O! , (       d  f       O= fURU                  [.        R0                  5        e f = f)	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.
r   Nr   r  r-  r.  r/  r0  r>  r_  F)completed_handshake)/r  r  r0   r  addrc   rd   rf   publish_connection_createdrR   rg   r%   r4  r5  r6  r'   r&   CONN_CREATEDr~   r1   r  r  rA  r*   r`  rB  r(   r  ra  rb  r/   r    r2   rK   rT   rt   	cancelledrE  r   rZ   contribute_socketr2  r   r   	_topologyreceive_cluster_timer   )	r   handlerconn_idtmp_contextre   networking_interfacer  rc  rQ   s	            r   r  Pool.connect  s>    YY--G##q(#.0K  $$[1  II..	  (((00wG##(:(G(G(V(V"0==<<?<<?#*	#?dii#X 6 .dllGT\\ZYY  $$T%8%89  ((5    &&(	<<

#'#3#3 ))$E)J NN$$99$:L:LMS Y0  	$$,,[9 $$ ,,,33LL'+A+G+G '',>,K,KGMM,Z,Z&4@@!__#||A#||A'.;<R<X<XY066	 %'7!?Y!?@@.tyy9)$,,W/	4 Y  	$$,,T-@-@A OO2889		so   AI7# J	 1AP&AP" 7
J	PP K<	P
K	D9PP
P"R8&Q'	R'
Q5	1(Rc           
   #  ,  #    U R                   R                  n[        R                  " 5       nU R                  (       a   Uc   eUR                  U R                  5        U R                  (       al  [        R                  " [        R                  5      (       aC  [        [        [        R                  U R                  U R                  S   U R                  S   S9  U R!                  X1S9n[        R                  " 5       U-
  nU R                  (       a,  Uc   eUR#                  U R                  UR$                  U5        U R                  (       ax  [        R                  " [        R                  5      (       aO  [        [        [        R&                  U R                  U R                  S   U R                  S   UR$                  US9   U R(                     U R*                  R-                  UR.                  5        SSS5        Uv   UR2                  (       aF  U R(                     U R@                  R-                  U5        U =RB                  S-  sl!        SSS5        gUR4                  (       aF  U R(                     U R@                  R-                  U5        U =RD                  S-  sl"        SSS5        gUR<                  (       a  U R?                  U5        gg! , (       d  f       N= f! [0         az    UR2                  =(       d    UR4                  nU(       a)  [6        R8                  " 5       u  pxn	UR;                  Xx5        U(       d"  UR<                  (       a  U R?                  U5        e f = f! , (       d  f       g= f! , (       d  f       g= f7f)a  Get a connection from the pool. Use with a "with" statement.

Returns a :class:`Connection` object wrapping a connected
:class:`socket.socket`.

This method should always be used in a with-statement::

    with pool.get_conn() as connection:
        connection.send_message(msg)
        data = connection.receive_message(op_code, request_id)

Can raise ConnectionFailure or OperationFailure.

:param handler: A _MongoClientErrorHandler.
Nr   r   r  r  r,  )#rc   rd   rV   rW   rf   $publish_connection_check_out_startedrR   rg   r%   r4  r5  r6  r'   r&   CHECKOUT_STARTEDr~   	_get_connpublish_connection_checked_outrS   CHECKOUT_SUCCEEDEDr  r  r  rt   r  rx   ry   sysexc_infohandlerz   r   r  r  r  )
r   r  re   checkout_started_timerQ   r8  pinnedexc_typeexc_val_s
             r   checkoutPool.checkout,  sy    & II..	 $ 0  (((::4<<H##(:(G(G(V(V"0AA<<?<<? ~~3~E>>#&;;  (((44T\\477HU##(:(G(G(V(V"0CC<<?<<?#'77#	$$(()<)<= J  ??%%))$/

a
  %%))$/"  [[LL 5   	
 __:(:(:F (+||~$1x1dkkT"	  sg   GN
K+ &K<K+ N%1M2&N<1N--N
K($K+ +BM//N2
N <N
NNc                   U R                   [        R                  :w  GaK  U(       Ga  [        R                  " 5       U-
  nU R
                  (       aX  U R                  R                  c   eU R                  R                  R                  U R                  [        R                  U5        U R                  (       a}  [        R                  " [        R                   5      (       aT  [#        [        [$        R&                  U R(                  U R                  S   U R                  S   S[        R                  US9  [+        U R                  5      n[-        U R                  [/        S5      US9  g g )Nr   r   <An error occurred while trying to establish a new connectionr  r-  r.  r/  r?  r  r1  zconnection pool pausedr_  )r  r  r  rV   rW   rf   rc   rd   #publish_connection_check_out_failedrR   r)   
CONN_ERRORrg   r%   r4  r5  r6  r'   r&   CHECKOUT_FAILEDr~   r    r2   r   )r   r$  
emit_eventr8  rc  s        r   _raise_if_not_readyPool._raise_if_not_ready{  s   ::(>>+.CC((9955AAAII..RR&D&O&OQY ++0B0O0OPWP]P]0^0^* 8 H H!%#'<<?#'<<?]<GG#+	 +4995G%m,DEW^+ )r   c                (   U R                   [        R                  " 5       :w  a  U R                  5         U R                  (       Ga  [
        R                  " 5       U-
  nU R                  (       aX  U R                  R                  c   eU R                  R                  R                  U R                  [        R                  U5        U R                  (       a}  [        R                   " ["        R$                  5      (       aT  ['        [        [(        R*                  U R,                  U R                  S   U R                  S   S[        R                  US9  [/        S5      eU R0                     U =R2                  S-  sl        SSS5        [4        R6                  " 5       (       a  [4        R8                  " 5       nOJU R                  R:                  (       a-  [
        R                  " 5       U R                  R:                  -   nOSnU R<                     U R?                  USS9  U R@                  U RB                  :  d  U(       a  U[
        R                  " 5       -
  OSn[E        U R<                  U5      (       dE  U R@                  U RB                  :  a  U R<                  RG                  5         U RI                  U5        U R?                  USS9  U R@                  U RB                  :  d  M  U =R@                  S-  sl         SSS5        SnS	nS	n U R0                     U =RJ                  S-  sl%        SnSSS5        UGc  U RL                     U R?                  US	S9  U RN                  (       d  U RP                  U RR                  :  d  U(       a  U[
        R                  " 5       -
  OSn[E        U RL                  U5      (       dX  U RN                  (       d  U RP                  U RR                  :  a  U RL                  RG                  5         SnU RI                  U5        U R?                  US	S9  U RN                  (       d  U RP                  U RR                  :  d  M   U RN                  RU                  5       nSSS5        U(       a  U RY                  U5      (       a  SnGMb  OT U R[                  US
9nU RL                     U =RP                  S-  sl(        U RL                  RG                  5         SSS5        Uc  GM  SUl3        U$ ! , (       d  f       GN= f! , (       d  f       GN= f! , (       d  f       GN= f! [V         a    U =RP                  S-  sl(         Nf = f! , (       d  f       N= f! , (       d  f       N= f! U RL                     U =RP                  S-  sl(        U RL                  RG                  5         SSS5        f ! , (       d  f       f = f= f! [\         Ga    U(       a  UR_                  [`        Rb                  5        U R<                     U =R@                  S-  sl         U(       a  U =RJ                  S-  sl%        U R<                  RG                  5         SSS5        O! , (       d  f       O= fU(       Gd  [
        R                  " 5       U-
  nU R                  (       aX  U R                  R                  c   eU R                  R                  R                  U R                  [        Rd                  U5        U R                  (       a}  [        R                   " ["        R$                  5      (       aT  ['        [        [(        R*                  U R,                  U R                  S   U R                  S   S[        Rd                  US9  e f = f)z8Get or create a Connection. Can raise ConnectionFailure.Nr   r   zConnection pool was closedr-  z?Attempted to check out a connection from closed connection poolT)r1  Fr  r,  )4r  r  r  r  rU   rV   rW   rf   rc   rd   r.  rR   r)   r  rg   r%   r4  r5  r6  r'   r&   r0  r~   r  r  r  r   get_timeoutget_deadlinewait_queue_timeoutr  r2  r  r  r"   r  _raise_wait_queue_timeoutr  r  r  r  r  popleft
IndexError	_perishedr  r  r   r*   r`  r/  rz   )	r   r$  r  r8  deadliner   rQ   r  emitted_events	            r   r  Pool._get_conn  sy    88ryy{"$$&;;;~~'*??H$$yy11===		**NNLL"@"L"Lh '',>,K,KGMM,Z,Z&4DD!__#||A#||A78DD'	 #Q  YY  A%   ))+HYY))~~'$))*F*FFHH^^$$%:t$L}}t'9'999A(T^^%55t!$..':: }}t'9'99--/223HI(()>4(P }}t'9'99 MMQM  @	##q(#"  , ..,,-Bu,U#zzT]]T=Q=Q-QAI(T^^-="=t)$*C*CWMM  $zzT]]T=Q=Q-Q $ 9 9 @ @ B,0M ::;PQ001FSX0Y  $zzT]]T=Q=Q-Q+#zz113 /" ~~d++#  ,?#||G|<!66 MMQ.M 55<<> 79 ,|  Y ^$ * & +*+ /.2 76T66 MMQ.M 55<<> 766  	 6 < <="''1,'%%'	   !>>+.CC((9955AAAII..RR&D&O&OQY ++0B0O0OPWP]P]0^0^* 8 H H!%#'<<?#'<<?]<GG#+	 9	s   ,S>CT(TW T"0W DUT40+W U; +W 70U*'W >
T
T"
T1,W 4UUUU
U'#W *
U84W ;W0W8	W
WWW =^AY'	^'
Y5	1D ^c                 	   UR                   nUR                  nSUl        SUl         SUl        U R                  R	                  U5        U R
                  R                  nU R                     U R                  R	                  UR                  5        SSS5        U R                  (       a+  Uc   eUR                  U R                  UR                  5        U R                  (       aw  [        R                   " ["        R$                  5      (       aN  ['        [        [(        R*                  U R,                  U R                  S   U R                  S   UR                  S9  U R.                  [0        R2                  " 5       :w  a  U R5                  5         GOU R6                  (       a!  UR9                  [:        R<                  5        GOUR6                  (       a  U R                  (       a:  Uc   eUR?                  U R                  UR                  [:        R@                  5        U R                  (       a  [        R                   " ["        R$                  5      (       au  ['        [        [(        RB                  U R,                  U R                  S   U R                  S   UR                  [E        [:        R@                  5      [:        R@                  S9  OSnU R                     U RG                  URH                  URJ                  5      (       a  SnOiURM                  5         URO                  [Q        U RR                  5      5        U RT                  RW                  U5        U RX                  R[                  5         SSS5        U(       a  UR9                  [:        R\                  5        U R^                     U(       a  U =R`                  S-  sl0        OU(       a  U =Rb                  S-  sl1        U =Rd                  S-  sl2        U =Rf                  S-  sl3        U =Rh                  S-  sl4        U R^                  R[                  5         SSS5        g! , (       d  f       GN= f! , (       d  f       N= f! , (       d  f       g= f)zvReturn the connection to the pool, or if it's closed discard it.

:param conn: The connection to check into the pool.
FNr   r   r  r>  T)5rx   ry   rz   r  r  rc   rd   r  r  rt   rf   publish_connection_checked_inrR   rS   rg   r%   r4  r5  r6  r'   r&   	CHECKEDINr~   r  r  r  r  rU   r   r*   r  rA  r`  rB  r(   r  rr   rv   rV  rY  r	  rZ   r  r  r  r  r   r  r  r  r  r  r  )r   rQ   txncursorre   r   s         r   r   Pool.checkin  s   
 oo##"%%d+II..	YY  (()<)<=   (((33DLL$''J##(:(G(G(V(V"0::<<?<<?#'77 88ryy{"$$&{{ 6 B BC(($00077dgg/E/K/K ++0B0O0OPWP]P]0^0^* 8 D D!%#'<<?#'<<?+/77?@V@\@\]4::	 #
YY ,,T__dooNN%)
557//T5E5E0FG

--d31188:  OO$:$@$@A^^

a
"MMQM1$  A% NN!!# ^k YN Y ^s&   +&QBQ0BQ/
Q
Q,/
Q=c                   UR                  5       nU R                  R                  b9  X R                  R                  :  a   UR                  [        R
                  5        gU R                  bT  U R                  S:X  d  X R                  :  a5  UR                  5       (       a   UR                  [        R                  5        gU R                  UR                  UR                  5      (       a   UR                  [        R                  5        gg)aY  Return 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.
Tr   F)r\  rc   r  r   r*   r   r  rM  r`  r  rr   rv   r   )r   rQ   r\  s      r   r;  Pool._perisheda  s     !224 II++7!II$C$CCOO2778''3((A-1BEaEa1a!! 6 < <=  $//BBOO2889r   c                   U R                   R                  n[        R                  " 5       U-
  nU R                  (       a0  Uc   eUR                  U R                  [        R                  U5        U R                  (       a}  [        R                  " [        R                  5      (       aT  [        [        [        R                   U R"                  U R                  S   U R                  S   S[        R                  US9  [$        R&                  " 5       =(       d    U R                   R(                  nU R                   R*                  (       al  U R,                  U R.                  -
  U R0                  -
  n[3        SR5                  U R                   R6                  U R.                  U R0                  UU5      5      e[3        SU R                   R6                   SU 35      e)Nr   r   zBWait queue timeout elapsed without a connection becoming availabler-  zTimeout 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: )rc   rd   rV   rW   rf   r.  rR   r)   TIMEOUTrg   r%   r4  r5  r6  r'   r&   r0  r~   r   r5  r7  r   r  r  r  r   rt  r  )r   r$  re   r8  r   	other_opss         r   r8  Pool._raise_wait_queue_timeout  sp   II..	>>#&;;  (((99<DDh ##(:(G(G(V(V"0@@<<?<<?[4<<#	 ##%E)E)E99""++dmm;djjHI'7 8>vII++MMJJ8	  $ II334KyJ
 	
r   c                d    [         (       a%  U R                   H  nUR                  S 5        M     g g r   )rJ  r  r   )r   rQ   s     r   __del__Pool.__del__  s(     8

% # r   )__pinned_socketsr  r~   r  r  r  r  r  rR   r  rf   rg   ro   rT   rZ   r  r  r  r  r  r  rc   r  r  r  r  )FN)rR   rG   r  r.   rT   r	  r  r  r|  r  )TNF)
rF  r	  r  r	  rv   r  r  r	  rz  r{  )rZ   zOptional[bool]rz  r{  )NF)rv   r  r  r	  rz  r{  r  )r  r   rz  r{  r   )r  "Optional[_MongoClientErrorHandler]rz  rK   )r  rO  rz  zGenerator[Connection, None])r$  r  r1  r	  rz  r{  )r$  r  r  rO  rz  rK   )rQ   rK   rz  r{  )rQ   rK   rz  r	  )r$  r  rz  r	   )r  r  r  r  r   rs   propertyrU   r  rY  r  r  rF  r  r	  r  
contextlibcontextmanagerr)  r2  r  r   r;  r8  rL  r  rk  r   r   rx  rx    sc   
 (,TT T 	T
 &Tl" . . )-&+[B[B [B '	[B
  $[B 
[Bz= TYe,eLPe	e
. /C,JQf <@L9L	$L L\6 [_%*5W	BI$V"H%
N&r   rx  )r
__future__r   r  r  rQ  r5  r  r!  rV   rN   typingr   r   r   r   r   r	   r
   r   r   bsonr   pymongor   r   pymongo.commonr   r   r   r   r   pymongo.errorsr   r   r   r   r   r   r   r   r   pymongo.hellor   r   pymongo.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/   r0   r1   r2   pymongo.read_preferencesr3   pymongo.server_apir4   pymongo.server_typer5   pymongo.socket_checkerr6   "pymongo.synchronous.client_sessionr7   pymongo.synchronous.helpersr8   pymongo.synchronous.networkr9   r:   bson.objectidr;   pymongo.compression_supportr<   r=   r>   pymongo.messager?   r@   pymongo.read_concernrA   rB   pymongo.synchronous.authrC   rD    pymongo.synchronous.mongo_clientrE   rF   pymongo.typingsrG   rH   pymongo.write_concernrI   rJ  rK   r  r  r  rx  rk  r   r   <module>rp     s   #     	 
  
 
 
 ' ) 
 
 
 - O 
  P O ,  4 . + 0 N 6 /!& 
 1045@V62 W
 W
t| + +> ~& ~&r   