
    @h                       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.J/r/  S S
K0J1r1J2r2J3r3J4r4  S SK5J6r6J7r7  S SK8J9r9J:r:J;r;  S SK<J=r=  S SK>J?r?J@r@JArAJBrBJCrCJDrD  S SKEJFrF  S SKGJHrH  S SKIJJrJ  S SKKJLrL  S SKMJNrN  S SKOJPrP  S SKQJRrR  \(       aL  S SKJSrS  S SKTJUrU  S SKVJWrWJXrXJYrY  S SKZJ[r[J\r\  S SK]J^r^  S SKEJ_r_  S SK`Jara  S SKMJbrb  S SKcJdrdJere  S SKfJgrgJhrh  S S KiJjrj   S S!KkJlrlJmrmJnrnJkrk  S/S" jroS$rq " S% S&5      rr " S' S(\'5      rs " S) S*5      rt " S+ S,5      ru " S- S.5      rvg! \p a    S/S# jro NCf = f)0    )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)
_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_get_timeout_details_raise_connection_failureformat_timeout_details)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_GETFDF_SETFD
FD_CLOEXECfcntlc                T    [        U [        5      n[        U [        U[        -  5        g)z8Set the close-on-exec flag on the given file descriptor.N)rM   rJ   rK   rL   )fdflagss     ]C:\Suresh\moveshuttle\MDcreated\moveengine\venv\Lib\site-packages\pymongo/synchronous/pool.py_set_non_inheritable_non_atomicrR   o   s    b'"b'5:-.    c                    g)z6Dummy function for platforms that don't provide fcntl.N )rO   s    rQ   rR   rR   x   s    rS   Tc                  *   \ 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)@
Connection   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readyr.   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)selfr]   poolr^   r_   r`   s         rQ   __init__Connection.__init__   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//!^^-!rS   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   r]   get_conn
settimeout)r   timeouts     rQ   set_conn_timeoutConnection.set_conn_timeout   s/    '''#		%%g.rS   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   	remainingr   r   ro   r   get_rttr   r0   r2   r   rg   int)	r   clientcmdr   rttmax_time_mstimeout_details	formattedr   s	            rQ   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&rS   c                8    SU l         U R                  (       a   eg NT)r   r   r   s    rQ   pin_txnConnection.pin_txn   s    %%%%%rS   c                8    SU l         U R                  (       a   eg r   )r   r   r   s    rQ   
pin_cursorConnection.pin_cursor   s    !??""?rS   c                    U R                  5       nU(       a  UR                  U 5        g U R                  [        R                  5        g N)r\   checkin
close_connr(   STALE)r   r   s     rQ   unpinConnection.unpin   s/    }}LLOO2889rS   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)ro   
server_apirl   load_balancedrn   r   CMD
LEGACY_CMDr   s    rQ   	hello_cmdConnection.hello_cmd   sO     994==DII4K4K"&DOOQ''**Ay$??rS   c                &    U R                  S S 5      $ r   )_hellor   s    rQ   helloConnection.hello  s    {{4&&rS   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   re   ro   metadataru   compressorsr   r   connect_timeoutr   _credentials	mechanismusernamesourcepymongo.synchronousr   rC   from_credentialsr^   speculate_commandrb   rc   r9   r   r   rf   rg   rh   ri   rj   logical_session_timeout_minutesis_readablerk   rl   server_typer5   	RSPrimaryRSSecondary	RSArbiterRSOtherRSGhostis_repl
Standaloneis_standaloneMongosrm   get_compression_contextrv   rn   connection_idr   sasl_supported_mechsry   parse_responsespeculate_succeededrz   r   r   r|   getr~   )r   topology_versionheartbeat_frequencyr   performing_handshaker   credsr   rz   speculative_authenticatestartdocr   ctxs                 rQ   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rS   c                    U R                  S 5      nUR                  U l        UR                  5       nUS   n[        R                  " X0R
                  5        U$ Nr   )r*   r   unpack_responser   _check_command_responserg   )r   replyunpacked_docsresponse_docs       rQ   _next_replyConnection._next_replyZ  sR    $$T*!..--/$Q'..|=R=RSrS   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_timerq   boolrn   _raise_if_not_writabler9   rm   r^   rh   rv   r   r   BaseExceptionr1   )r   dbnamespecread_preferencecodec_optionscheckallowable_errorsread_concernr  r  r  sessionr   retryable_writer   r
  r   rq   r	  errors                       rQ   r9   Connection.commandb  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.)rh   r   r+   r]   r   r  r1   )r   messagemax_doc_sizer  s       rQ   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*   ri   r  r1   )r   
request_idr  s      rQ   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)rf   r   )r   r	  s     rQ   r  !Connection._raise_if_not_writable  s+     $"2"2!-]\a1bcc #3>rS   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      rQ   unack_writeConnection.unack_write  s      	##D)#,rS   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   rg   )r   r'  r,  r  r   results         rQ   write_commandConnection.write_command  sO     	#q!$$Z0''6 	..v7L7LMrS   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)re   rz   r   ro   r   r   r   authenticaterb   rc   r   rr   rq   publish_connection_readyr^   r_   rs   r#   isEnabledForloggingDEBUGr%   r$   
CONN_READYr   )r   r5  r   r   durations        rQ   r<  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' -[' rS   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      rQ   r  Connection.validate_session  s)     f,&'bcc - rS   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"  r7  r8  r9  r:  reasonr  )ra   _close_connrr   rq   publish_connection_closedr^   r_   rs   r#   r>  r?  r@  r%   r$   CONN_CLOSEDr   r&   )r   rI  s     rQ   r   Connection.close_conn*  s    ;;$$~~11188twwPVW'',>,K,KGMM,Z,Z&4@@!__#||A#||A'+ww;FC 	 -['	 rS   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)ra   r   cancelr]   close	Exceptionr   s    rQ   rJ  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_SYNCrw   socket_closedr]   r   
is_closingr   s    rQ   conn_closedConnection.conn_closedL  s;    8&&44TYY5G5GHH99''))rS   c                6    U(       a  UR                  X5        gg)zAdd $clusterTime.N)_send_cluster_time)r   r9   r  r   s       rQ   r  Connection.send_cluster_timeS  s     %%g7 rS   c                z    U R                   R                  (       a   [        XR                   R                  5        gg)zAdd server_api parameters.N)ro   r   r4   )r   r9   s     rQ   r  Connection.add_server_api]  s&    99GYY%9%9:  rS   c                8    [         R                  " 5       U l        g r   rb   rc   rd   r   s    rQ   update_last_checkin_time#Connection.update_last_checkin_timeb  s    !%!1rS   c                    Xl         g r   )rf   )r   rf   s     rQ   update_is_writableConnection.update_is_writablee  s    &rS   c                F    [         R                  " 5       U R                  -
  $ )z9Seconds since this socket was last checked into its pool.r_  r   s    rQ   idle_time_secondsConnection.idle_time_secondsh  s    ~~$"8"888rS   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   )r   r(   ERRORr   r  IOErrorOSErrorr-   r0   ro   r1   r^   )r   r  rI  detailss       rQ   r1   $Connection._raise_connection_failurel  s]      ::F+11Fegw;;<<*4995G%dllESrS   c                4    U R                   UR                   :H  $ r   )r]   r   others     rQ   __eq__Connection.__eq__  s    yyEJJ&&rS   c                    X:X  + $ r   rU   rp  s     rQ   __ne__Connection.__ne__  s      rS   c                ,    [        U R                  5      $ r   )hashr]   r   s    rQ   __hash__Connection.__hash__  s    DIIrS   c                    SR                  [        U R                  5      U R                  =(       a    S=(       d    S[	        U 5      5      $ )NzConnection({}){} at {}z CLOSED )formatreprr]   ra   r_   r   s    rQ   __repr__Connection.__repr__  s8    '..OKK%I+tH
 	
rS   )-r   r   r   r^   rz   r   ra   rv   ru   r]   r   r   rr   rs   r~   rl   r_   rm   r   r`   r   rf   rd   r   rq   r   rh   ri   rg   rj   r   ry   rx   rn   ro   re   r   r   r|   r\   r   r   r   rw   rk   )
r]   r)   r   Poolr^   ztuple[str, int]r_   r   r`   r  )r   Optional[float]returnNone)r   rE   r   z"Optional[MutableMapping[str, Any]]r  r  r  r  )r  dict[str, Any])r  r   )r   zOptional[Any]r   Optional[int]r  zHello[dict[str, Any]])"r  strr  MutableMapping[str, Any]r  rB   r  r:   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]r  r  r   r  r
  zOptional[Mapping[str, Any]]r   r  r  r  )r"  bytesr#  r   r  r  )r'  r  r  zUnion[_OpReply, _OpMsg])r	  r  r  r  )r,  r  r#  r   r  r  )r'  r   r,  r  r  r:   r  r  )F)r5  r  r  r  )r   r  r  r  r  r  )rI  zOptional[str]r  r  r  r  )r9   r  r  r  r   r  r  r  )r9   r  r  r  )rf   r  r  r  )r  float)r  r  r  r	   )rq  r   r  r  r  r   )r  r  ))__name__
__module____qualname____firstlineno____doc__r   r   r   r   r   r   r   r   r   r  r8   r3   PRIMARYr   r9   r$  r*   r  r-  r2  r<  r  r   rJ  rW  r  r  r`  rc  rf  r1   rr  ru  ry  r  __static_attributes__rU   rS   rQ   rW   rW      sn   9"!9" 9" !	9"
 9" 9"v/!(J	>&#:@'S'S +S 
	Sj 
 (6'='=&;@D.204*/,0+/(, %#37 %#W2W2 'W2 %	W2
 $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	-$):F	$ D	d+	d6M	d		d**8)8 )8 &	8
 
8;
2'98'!
rS   rW   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.
rU   N)r  r  r  r  r  r  rU   rS   rQ   r  r    s    rS   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    rQ   r   _PoolGeneration.__init__  s    1<1H1H1MrS   c                >    Uc  U R                   $ U R                  U   $ )z,Get the generation for the given service_id.r  r  r   r   s     rQ   r   _PoolGeneration.get  s%    ###  ,,rS   c                    U R                   $ )z"Get the Pool's overall generation.)r  r   s    rQ   r}   _PoolGeneration.get_overall  s    rS   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     rQ   inc_PoolGeneration.inc  sW    A"//
!!*-2- 0 j)Q.)rS   c                (    XR                  U5      :g  $ )z?Return if the given generation for a given service_id is stale.)r   r   r{   r   s      rQ   stale_PoolGeneration.stale  s    hhz***rS   r  Nr  )r   Optional[ObjectId]r  r   r  )r   r  r  r  r{   r   r   r  r  r  )
r  r  r  r  r   r   r}   r  r  r  rU   rS   rQ   r  r    s    - /+rS   r  c                       \ rS rSrSrSrSrSrg)	PoolStatei  r         rU   N)r  r  r  r  PAUSEDREADYCLOSEDr  rU   rS   rQ   r  r    s    FEFrS   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))r  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"  r7  r8  r9  )2pause_enabledr  r  stater  _check_interval_secondsr  dequeconnssetactive_contextsr"   lockr!   _max_connecting_condactive_socketsnext_connection_idrf   r  r{   osgetpidpidr^   ro   r`   rp   rr   rs   	size_condrequestsmax_pool_sizer  max_connecting_max_connecting_pendingr   publish_pool_creatednon_default_optionsr#   r>  r?  r@  r%   r$   POOL_CREATEDoperation_count_Pool__pinned_socketsncursorsntxns)r   r^   optionsr`   	client_ids        rQ   r   Pool.__init__  sB      "))DJ"DJ ()$ )4(9(9(;
:=% 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
rS   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  rr   ro   rp   publish_pool_readyr^   rs   r#   r>  r?  r@  r%   r$   
POOL_READYr   r   s    rQ   r   
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    rQ   ra   Pool.closed.  s    zzY----rS   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  )r   interrupt_connections)r"  r7  r8  r9  	serviceId).r  r  ra   ro   r  r   r  r  r{   r  r  r  r  r  r  r  r  r  r   appendr  r  
notify_allr  rO  rp   rT  asynciogatherr   r(   POOL_CLOSEDrr   publish_pool_closedr^   rs   r#   r>  r?  r@  r%   r$   r   publish_pool_clearedPOOL_CLEAREDr   )r   rP  pauser   r  	old_statenewpidsocketsdiscardkeepr]   contextrq   s                rQ   _resetPool._reset2  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)rf   r  r  rc  )r   rf   _sockets      rQ   rc  Pool.update_is_writable  s=     'YY::**4+;+;< & YYs   /A
Ac                $    U R                  SXS9  g )NF)rP  r   r  r  )r   r   r  s      rQ   reset
Pool.reset  s     	%JdrS   c                $    U R                  SSS9  g )NF)rP  r  r  r   s    rQ   reset_without_pausePool.reset_without_pause  s    %u-rS   c                "    U R                  SS9  g )NT)rP  r  r   s    rQ   rP  
Pool.close  s    $rS   c                8    U R                   R                  X5      $ r   )r{   r  r  s      rQ   stale_generationPool.stale_generation  s    xx~~c..rS   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  ro   max_idle_time_secondsr  rf  r  poprT  r  r  r   r(   IDLEr  lenr  min_pool_sizer  r  r  r  notifyconnectr{   r}   
appendleftr  r  r   r   )r   reference_generationclose_connsr]   incrementedr   s         rQ   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"  r7  r8  r9  r:  rH  ri  F)completed_handshake)/r  r  r.   r  addro   rp   rr   publish_connection_createdr^   rs   r#   r>  r?  r@  r%   r$   CONN_CREATEDr   r/   r  r  rK  r(   rj  rL  r&   r  rk  rl  r-   r0   r1   rW   r`   r   	cancelledrO  r   rf   contribute_socketr<  r   r   	_topologyreceive_cluster_timer   )	r   handlerconn_idtmp_contextrq   networking_interfacer  rm  r]   s	            rQ   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  r6  )#ro   rp   rb   rc   rr   $publish_connection_check_out_startedr^   rs   r#   r>  r?  r@  r%   r$   CHECKOUT_STARTEDr   	_get_connpublish_connection_checked_outr_   CHECKOUT_SUCCEEDEDr  r  r  r   r  r   r   sysexc_infohandler   r   r  r  r  )
r   r  rq   checkout_started_timer]   rB  pinnedexc_typeexc_val_s
             rQ   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"  r7  r8  r9  rI  r  r;  zconnection pool pausedri  )r  r  r  rb   rc   rr   ro   rp   #publish_connection_check_out_failedr^   r'   
CONN_ERRORrs   r#   r>  r?  r@  r%   r$   CHECKOUT_FAILEDr   r0   r1   r   )r   r+  
emit_eventrB  rm  s        rQ   _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^+ )rS   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 closedr4  z?Attempted to check out a connection from closed connection poolT)r8  Fr"  r3  )4r  r  r  r  ra   rb   rc   rr   ro   rp   r5  r^   r'   r  rs   r#   r>  r?  r@  r%   r$   r7  r   r  r  r  r   get_timeoutget_deadlinewait_queue_timeoutr  r9  r  r  r    r
  _raise_wait_queue_timeoutr  r  r  r  r  popleft
IndexError	_perishedr  r  r   r(   rj  r6  r   )	r   r+  r  rB  deadliner   r]   r  emitted_events	            rQ   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  rH  T)5r   r   r   r  r  ro   rp   r  r  r   rr   publish_connection_checked_inr^   r_   rs   r#   r>  r?  r@  r%   r$   	CHECKEDINr   r  r  r  r  ra   r   r(   r  rK  rj  rL  r&   r  r~   r   r`  rc  r  rf   r  r  r  r
  r   r  r  r  r  r  r  )r   r]   txncursorrq   r   s         rQ   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)rf  ro   r  r   r(   r  r  rW  rj  r  r~   r   r   )r   r]   rf  s      rQ   rB  Pool._perisheds  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rS   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 availabler4  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: )ro   rp   rb   rc   rr   r5  r^   r'   TIMEOUTrs   r#   r>  r?  r@  r%   r$   r7  r   r   r<  r>  r   r  r  r  r   r}  r  )r   r+  rq   rB  r   	other_opss         rQ   r?  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
 	
rS   c                d    [         (       a%  U R                   H  nUR                  S 5        M     g g r   )rT  r  r   )r   r]   s     rQ   __del__Pool.__del__  s(     8

% # rS   )__pinned_socketsr  r   r  r  r  r  r  r^   r  rr   rs   r{   r`   rf   r  r  r  r  r  r  ro   r  r  r  r  )FN)r^   rG   r  r,   r`   r  r  r  r  r  )TNF)
rP  r  r  r  r   r  r  r  r  r  )rf   zOptional[bool]r  r  )NF)r   r  r  r  r  r  r  )r  r   r  r  r   )r  "Optional[_MongoClientErrorHandler]r  rW   )r  rV  r  zGenerator[Connection, None])r+  r  r8  r  r  r  )r+  r  r  rV  r  rW   )r]   rW   r  r  )r]   rW   r  r  )r+  r  r  r	   )r  r  r  r  r   r   propertyra   r  rc  r  r  rP  r  r  r  
contextlibcontextmanagerr0  r9  r%  r   rB  r?  rS  r  rU   rS   rQ   r  r    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&rS   r  )rO   r   r  r  )w
__future__r   r  r  rX  r?  r  r(  rb   rZ   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.lockr    r!   r"   pymongo.loggerr#   r$   r%   r&   pymongo.monitoringr'   r(   pymongo.network_layerr)   r*   r+   pymongo.pool_optionsr,   pymongo.pool_sharedr-   r.   r/   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   rM   rJ   rK   rL   rR   ImportErrorrT  rW   r  r  r  r  rU   rS   rQ   <module>rw     s5   #     	 
  
 
 
 ' ) 
 
 
 - 
  P O ,  4 . + 0 N 6 /!& 
 1045@V62E99/ W
 W
t| + +> ~& ~&e  EE	Es   3E: :FF