
    &gQ                       S r 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J	r	J
r
JrJrJr  SSKJr  SSKJr  SSKJrJrJrJr  SSKJrJrJr  SS	KJr  SS
KJrJr  \	(       a  SSK J!r!  SSK"J#r#   SSK$J%r%J&r&J'r'J$r$  S(S jr(Sr*Sr+Sr,\RZ                  S:X  aG   SSK.r/S r0 \/Rb                  " \/Rd                  S5       r3\0" \3SS5      r4\0" \3SS5      r5SSS5        S r7O
S)S jr8S*S jr7  S+         S,S jjr9S-S jr:S.S jr; " S  S!5      r<S/S" jr=      S0S# jr>      S1S$ jr?S/S% jr@S0S& jrAS2S' jrBg! \) a    S(S jr( Nf = f! \) a    SSK/r/ Nf = f! , (       d  f       N= f! \6 a    Sr4Sr5 Nf = f)3z)Pool utilities and shared helper methods.    )annotationsN)TYPE_CHECKINGAnyNoReturnOptionalUnion)_csot)_getaddrinfo)AutoReconnectConnectionFailureNetworkTimeout_CertificateError)AsyncNetworkingInterfaceNetworkingInterfacePyMongoProtocol)PoolOptions)HAS_SNISSLError)_sslConn)_Address)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)r   r   r   r   )fdflagss     XC:\Suresh\moveshuttle\MDcreated\moveengine\venv\Lib\site-packages\pymongo/pool_shared.py_set_non_inheritable_non_atomicr   2   s    b'"b'5:-.    c                    g)z6Dummy function for platforms that don't provide fcntl.N )r   s    r   r   r   ;   s    r    x   
   	   win32c                z     [         R                  " X5      u  p4[        U5      $ ! [        [        4 a    Us $ f = fN)winregQueryValueExintOSError
ValueError)keynamedefaultvalue_s        r   _queryr3   I   s>    	**35HEu:$ 	 N	s   "% ::z2SYSTEM\CurrentControlSet\Services\Tcpip\ParametersKeepAliveTimei m KeepAliveInterval  c                    [        [        [        S-  5      n[        [        [        S-  5      nU[        :  d
  U[        :  a#  U R                  [        R                  SX45        g g )Nr6      )min_WINDOWS_TCP_IDLE_MS_MAX_TCP_KEEPIDLE_WINDOWS_TCP_INTERVAL_MS_MAX_TCP_KEEPINTVLioctlsocketSIO_KEEPALIVE_VALS)sockidle_msinterval_mss      r   _set_keepalive_timesrD   _   sX    *,=,DE24F4MN))[;S-SJJv001g2KL .Tr    c                    [        [        U5      (       aX  [        [        U5      n U R                  [        R                  U5      nXB:  a!  U R                  [        R                  X25        g g g ! [         a     g f = fr(   )hasattrr?   getattr
getsockoptIPPROTO_TCP
setsockoptr,   )rA   
tcp_option	max_valuesockoptr0   s        r   _set_tcp_optionrN   g   sp    6:&&fj1G //&*<*<gF&OOF$6$6K ' '  s   AA/ /
A<;A<c                j    [        U S[        5        [        U S[        5        [        U S[        5        g )NTCP_KEEPIDLETCP_KEEPINTVLTCP_KEEPCNT)rN   r;   r=   _MAX_TCP_KEEPCNTrA   s    r   rD   rD   t   s)    n.?@o/ABm-=>r    c                :   U u  pEUb  SXEU4-  nOU SU 3nU(       a  X&-   nSU;  a  U[        U5      -  n[        U[        R                  5      (       a  [	        U5      Ue[        U[
        5      (       a  S[        U5      ;   a  [	        U5      Ue[        U5      Ue)z9Convert a socket.error to ConnectionFailure and raise it.z	%s:%d: %s: zconfigured timeouts	timed out)format_timeout_details
isinstancer?   timeoutr   r   strr   )addresserror
msg_prefixtimeout_detailshostportmsgs          r   _raise_connection_failurerc   z   s     JDT//b C'%o66%((S!u,	E8	$	$E
)B
 S!u,C e+r    c                    0 n[         R                  " 5       nU R                  nU R                  nU(       a  US-  US'   U(       a  U(       d  US-  US'   U(       a  US-  US'   U$ )Nr6   	timeoutMSsocketTimeoutMSconnectTimeoutMS)r	   get_timeoutsocket_timeoutconnect_timeout)optionsdetailsrZ   ri   rj   s        r   _get_timeout_detailsrm      si    G!G++N--O&~g%3d%:!"&5&<"#Nr    c                r    SnU (       a-  US-  nS H  nX ;   d  M
  USU SX    S3-  nM     US S nUS-  nU$ )	N z (configured timeouts:)rf   re   rg    rV   zms,)r"   )rl   resultrZ   s      r   rX   rX      s^    F**KG!AgYb)9(:#>> L #Mr    c                  <    \ rS rSrSS jrSS jr\SS j5       rSrg)	_CancellationContext   c                    SU l         g )NF
_cancelledselfs    r   __init___CancellationContext.__init__   s	    r    c                    SU l         g)zCancel this context.TNrx   rz   s    r   cancel_CancellationContext.cancel   s	    r    c                    U R                   $ )zWas cancel called?rx   rz   s    r   	cancelled_CancellationContext.cancelled   s     r    rx   N)returnNone)r   bool)	__name__
__module____qualname____firstlineno__r|   r   propertyr   __static_attributes__r"   r    r   ru   ru      s        r    ru   c           
     &  #    U u  p#UR                  S5      (       aq  [        [        S5      (       d  [        S5      e[        R                  " [        R                  5      n[        UR                  5       5         UR                  U5        U$ [        R                  n[        R                  (       a  US:w  a  [        R                  nSn[        X#U[        R                  S9I Sh  vN  GH  nUu  ppn [        R                  " X[        [        SS5      -  U
5      n[        UR                  5       5         UR!                  [        R"                  [        R$                  S	5        [&        R(                  " 5       nUc  UR*                  nOUS::  a  [        R,                  " S
5      eUR/                  U5        UR!                  [        R0                  [        R2                  S5        [5        U5        UR                  U5        Us  $    Ub  Ue[        S5      e! [         a    UR                  5         e f = f GNT! [         a    [        R                  " XU
5      n GNBf = f! [         a  nUnUR                  5          SnAGM  SnAff = f7fzGiven (host, port) and PoolOptions, connect and return a raw socket object.

Can raise socket.error.

This is a modified version of create_connection from CPython >= 2.7.
z.sockAF_UNIXz-UNIX-sockets are not supported on this system	localhostN)familytypeSOCK_CLOEXECr   r8   rW   Tzgetaddrinfo failed)endswithrF   r?   r   r   r   filenoconnectr,   closeAF_INEThas_ipv6	AF_UNSPECr
   SOCK_STREAMrG   rJ   rI   TCP_NODELAYr	   	remainingrj   rZ   
settimeout
SOL_SOCKETSO_KEEPALIVErD   r\   rk   r`   ra   rA   r   errresafsocktypeprotodummysarZ   es                  r   _async_create_connectionr      s     JD }}Wvy))#$STT}}V^^,'6	LLK ^^F4;.!!
C!$V&BTBTUUU),&eB	6==PQ0R%RTYZD 	(6	OOF..0B0BAFoo'G!11Ann[11OOG$OOF--v/B/BDI &LLK3 V< 	 *++c  	JJL	 V  	6 ==u5D	6&  	CJJLL	sz   A8J;H AJ'H;(J7)H> J:CI&JH88J>!I#J"I##J&
J0J	J	JJc           	       #    [        X5      I Sh  vN nUR                  nUc  UR                  UR                  5        U$ U S   n [        (       aM  [
        R                  " 5       nUR                  S[        R                  " UR                  X$S95      I Sh  vN nO;[
        R                  " 5       nUR                  SUR                  U5      I Sh  vN n UR"                  (       aF  UR$                  (       d5  UR&                  (       d$   [(        R*                  " WR-                  5       US9  WR                  UR                  5        U$  GN> N N~! [         a    UR                  5         e [        [        4 a0  nUR                  5         [        U5      n[!        XSUS9   SnANSnAff = f! [         a    WR                  5         e f = f7fzGiven (host, port) and PoolOptions, return a raw configured socket.

Can raise socket.error, ConnectionFailure, or _CertificateError.

Sets socket's SSL and timeout options.
Nr   server_hostnameSSL handshake failed: r_   hostname)r   _ssl_contextr   ri   r   asyncioget_running_looprun_in_executor	functoolspartialwrap_socketr   r   r,   r   rm   rc   verify_modecheck_hostnametls_allow_invalid_hostnamessslmatch_hostnamegetpeercert)	r\   rk   rA   ssl_contextr`   loopssl_sockexcrl   s	            r   _async_configured_socketr     s     *';;D&&K../1:Dc 7++-D!11!!+"9"94V H
 ++-D!11$8O8OQUVVH 	**33	x335E
 ../OY < W 

 	X c

 'w/!'0HZabc ! 	NN	s   GE5GAE EE G 5E EE 4G#F3 2GE E *F0 &F+&G+F00G3GGc                  ^	#    [        X5      I Sh  vN nUR                  nUR                  m	Uc8  [        [        R
                  " 5       R                  U	4S jUS9I Sh  vN 5      $ U S   n [        R
                  " 5       R                  U	4S jUUUS9I Sh  vN u  pVUR                  (       aG  UR                  (       d6  UR                  (       d%   [         R"                  " UR%                  S	5      US
9  [        UW45      $  N N No! [         a    WR                  5         e [        [        4 a0  nWR                  5         [        U5      n[        XSUS9   SnANSnAff = f! [         a    UR                  5         e f = f7f)zGiven (host, port) and PoolOptions, return a configured AsyncNetworkingInterface.

Can raise socket.error, ConnectionFailure, or _CertificateError.

Sets protocol's SSL and timeout options.
Nc                    > [        T S9$ NrZ   r   r   s   r   <lambda>0_configured_protocol_interface.<locals>.<lambda>N  s
    8r    rT   r   c                    > [        T S9$ r   r   r   s   r   r   r   W  s
    OG4r    )rA   r   r   r   r   peercertr   )r   r   ri   r   r   r   create_connectionr   abortr,   r   rm   rc   r   r   r   r   r   get_extra_info)
r\   rk   rA   r   r`   	transportprotocolr   rl   rZ   s
            @r   _configured_protocol_interfacer   >  sy     *';;D&&K$$G'**,>>8t ?  
 	
 1:Dc %,$<$<$>$P$P4 	 %Q %
 
	& 	**33	y77
CdS
 $Y$9::Y <
   	X c 'w/!'0HZabc ! 	OO	sv   F
DAF
!D
"F
0,D DD #3F
$E+ ;F

F
D *E(8&E#F
#E((F
+FF
c           
        U u  p#UR                  S5      (       aq  [        [        S5      (       d  [        S5      e[        R                  " [        R                  5      n[        UR                  5       5         UR                  U5        U$ [        R                  n[        R                  (       a  US:w  a  [        R                  nSn[        R                  " X#U[        R                  S9 GH  nUu  ppn [        R                  " X[        [        SS5      -  U
5      n[        UR                  5       5         UR!                  [        R"                  [        R$                  S	5        [&        R(                  " 5       nUc  UR*                  nOUS::  a  [        R,                  " S
5      eUR/                  U5        UR!                  [        R0                  [        R2                  S5        [5        U5        UR                  U5        Us  $    Ub  Ue[        S5      e! [         a    UR                  5         e f = f! [         a    [        R                  " XU
5      n GN?f = f! [         a  nUnUR                  5          SnAGM  SnAff = fr   )r   rF   r?   r   r   r   r   r   r,   r   r   r   r   getaddrinfor   rG   rJ   rI   r   r	   r   rj   rZ   r   r   r   rD   r   s                  r   _create_connectionr   v  s    JD }}Wvy))#$STT}}V^^,'6	LLK ^^F4;.!!
C!!$V&BTBTU),&eB	6==PQ0R%RTYZD 	(6	OOF..0B0BAFoo'G!11Ann[11OOG$OOF--v/B/BDI &LLK3 V< 	 *++c  	JJL	&  	6 ==u5D	6&  	CJJLL	s7   9H 8)H<;CI$H9<!I! I!$
J.JJc                   [        X5      nUR                  nUc  UR                  UR                  5        U$ U S   n [        (       a  UR                  X$S9nOUR                  U5      n UR                  (       aF  UR                  (       d5  UR                  (       d$   [        R                   " WR#                  5       US9  WR                  UR                  5        U$ ! [         a    UR                  5         e [        [        4 a0  nUR                  5         [        U5      n[        XSUS9   SnANSnAff = f! [         a    WR                  5         e f = fr   )r   r   r   ri   r   r   r   r   r,   r   rm   rc   r   r   r   r   r   r   r\   rk   rA   r   r`   r   r   rl   s           r   _configured_socketr     s4    g/D&&K../1:Dc 7"..t.JH"..t4H 	**33	x335E
 ../O1  

 	X c

 'w/!'0HZabc ! 	NN	s)   C C #D< *D9	&D44D9<Ec                   [        X5      nUR                  nUc&  UR                  UR                  5        [	        U5      $ U S   n [
        (       a  UR                  X$S9nOUR                  U5      n UR                  (       aF  UR                  (       d5  UR                  (       d$   [         R"                  " WR%                  5       US9  WR                  UR                  5        [	        U5      $ ! [         a    UR                  5         e [        [        4 a0  nUR                  5         [        U5      n[        XSUS9   SnANSnAff = f! [         a    WR                  5         e f = f)zGiven (host, port) and PoolOptions, return a NetworkingInterface wrapping a configured socket.

Can raise socket.error, ConnectionFailure, or _CertificateError.

Sets socket's SSL and timeout options.
Nr   r   r   r   r   )r   r   r   ri   r   r   r   r   r   r,   r   rm   rc   r   r   r   r   r   r   r   s           r   _configured_socket_interfacer     s@    g/D&&K../"4((1:Dc 7"..t.JH"..t4H 	**33	x335E
 ../x((1  

 	X c

 'w/!'0HZabc ! 	NN	s*   C1 "C1 (#E 1*E&EEE*)r   r+   r   r   )rA   socket.socketrK   r[   rL   r+   r   r   )rA   r   r   r   )NN)
r\   r   r]   	Exceptionr^   zOptional[str]r_   Optional[dict[str, float]]r   r   )rk   r   r   zdict[str, float])rl   r   r   r[   )r\   r   rk   r   r   r   )r\   r   rk   r   r   zUnion[socket.socket, _sslConn])r\   r   rk   r   r   r   )r\   r   rk   r   r   r   )C__doc__
__future__r   r   r   r?   r   systypingr   r   r   r   r   pymongor	   pymongo.asynchronous.helpersr
   pymongo.errorsr   r   r   r   pymongo.network_layerr   r   r   pymongo.pool_optionsr   pymongo.ssl_supportr   r   pymongo.pyopenssl_contextr   pymongo.typingsr   r   r   r   r   r   ImportErrorr;   r=   rS   platform_winregr)   r3   OpenKeyHKEY_LOCAL_MACHINEr.   r:   r<   r,   rD   rN   rc   rm   rX   ru   r   r   r   r   r   r   r"   r    r   <module>r      s   0 "    
 
   5  a ` , 12(E99/    <<7 
(^^%%'\
#)##H '-c3F'M$	
M? !%26	,,, , 0	,
 ,:	 D,N55 +5#5p5;5; +5;5;pD,N.b.)o  EE	E  
 

  (  '#' 	(sT   /D8 E	 E* <EE* 8EE	
EE
E'#E* 'E* *
E76E7