
    phM                       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  SS	KJrJrJr  SS
KJr  SSK J!r!J"r"J#r#  \!\"4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r0Sr1\Rd                  S:X  aG   SSK3r4S r5 \4Rl                  " \4Rn                  S5       r8\5" \8SS5      r9\5" \8SS5      r:SSS5        S r<O
S(S jr=S)S jr<  S*         S+S jjr> " S S 5      r?S,S! jr@      S-S" jrA      S.S# jrBS,S$ jrCS-S% jrDS/S& jrEg! \. a    S'S jr- Nf = f! \. a    SSK4r4 Nf = f! , (       d  f       N= f! \; a    Sr9Sr: Nf = f)0z)Pool utilities and shared helper methods.    )annotationsN)TYPE_CHECKINGAnyNoReturnOptionalUnion)_csot)_getaddrinfo)AutoReconnectConnectionFailureNetworkTimeout_CertificateError)_get_timeout_detailsformat_timeout_details)AsyncNetworkingInterfaceNetworkingInterfacePyMongoProtocol)PoolOptions)
PYSSLErrorSSLError_has_sni)_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     M/home/james-whalen/.local/lib/python3.13/site-packages/pymongo/pool_shared.py_set_non_inheritable_non_atomicr"   4   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!   _queryr6   K   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 )Nr9      )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_timesrG   a   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+   )hasattrrB   getattr
getsockoptIPPROTO_TCP
setsockoptr/   )rD   
tcp_option	max_valuesockoptr3   s        r!   _set_tcp_optionrQ   i   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)rQ   r>   r@   _MAX_TCP_KEEPCNTrD   s    r!   rG   rG   v   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: %sz: zconfigured timeouts	timed out)r   
isinstancerB   timeoutr   	SSLErrorsstrr   )addresserror
msg_prefixtimeout_detailshostportmsgs          r!   _raise_connection_failurere   |   s     JDT//b C'%o66%((S!u,	E9	%	%+U*C
 S!u,C e+r#   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.TNrj   rl   s    r!   cancel_CancellationContext.cancel   s	    r#   c                    U R                   $ )zWas cancel called?rj   rl   s    r!   	cancelled_CancellationContext.cancelled   s     r#   rj   N)returnNone)rv   bool)	__name__
__module____qualname____firstlineno__rn   rq   propertyrt   __static_attributes__r%   r#   r!   rg   rg      s        r#   rg   c           
       #    U u  p#UR                  S5      (       a  [        [        S5      (       d  [        S5      e[        R                  " [        R                  5      n[        UR                  5       5         UR                  S5        [        R                  " 5       R                  XB5      I Sh  vN   U$ [        R                  n[        R                  (       a  US:w  a  [        R                  nSn[!        X#U[        R"                  S9I Sh  vN  GHZ  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R0                  nOUS	::  a  [        R2                  " S5      eUR'                  [        R4                  [        R6                  S5        [9        U5        UR                  S5        [        R:                  " [        R                  " 5       R                  XL5      US9I Sh  vN   UR=                  U5        Us  $    Ub  Ue[        S5      e GN! [         a    UR                  5         e f = f GN! [         a    [        R                  " XU
5      n GNf = f Nx! [        R>                   a8  nUR                  5         [        R2                  " S5      nXl          SnAGM  SnAf[         a  nUR                  5         Un SnAGM+  SnAff = f7f)Given (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.
.sockAF_UNIX-UNIX-sockets are not supported on this systemFN	localhostfamilytypeSOCK_CLOEXECr   r;   rY   Tr[   getaddrinfo failed)!endswithrI   rB   r   r   r"   filenosetblockingasyncioget_running_loopsock_connectr/   closeAF_INEThas_ipv6	AF_UNSPECr
   SOCK_STREAMrJ   rM   rL   TCP_NODELAYr	   	remainingconnect_timeoutr[   
SOL_SOCKETSO_KEEPALIVErG   wait_for
settimeoutTimeoutError	__cause__r^   optionsrb   rc   rD   r   errresafsocktypeprotodummysar[   es                  r!   _async_create_connectionr      s     JD }}Wvy))#$STT}}V^^,'6	U#**,99$EEE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OOF--v/B/BDI &U#""((*77A7   OOG$K; VL 	 *++w F 	JJL	 V  	6 ==u5D	6$
 ## 	JJL..-CMM 	JJLC	s   A8M;8J
 3J4J
 9AMJ)M#)J,M&C5KKK2MJ
 
J&&M,!KMKMKM*,LMM*M<MMMc           	       #    [        X5      I Sh  vN nUR                  nUc  UR                  UR                  5        U$ U S   n [	        S5      (       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NC N N~! [         a    UR                  5         e [        /[        Q7 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)Given (host, port) and PoolOptions, return a raw configured socket.

Can raise socket.error, ConnectionFailure, or _CertificateError.

Sets socket's SSL and timeout options.
Nr   Fserver_hostnameSSL handshake failed: ra   hostname)r   _ssl_contextr   socket_timeoutr   r   r   run_in_executor	functoolspartialwrap_socketr   r   r/   r\   r   re   verify_modecheck_hostnametls_allow_invalid_hostnamessslmatch_hostnamegetpeercert)	r^   r   rD   ssl_contextrb   loopssl_sockexcdetailss	            r!   _async_configured_socketr      s     *';;D&&K../1:Dc E??++-D!11!!+"9"94V H
 ++-D!11$8O8OQUVVH 	**33	x335E
 ../OY < W 

 	 i  c

 'w/!'0HZabc ! 	NN	s   GE5GAE E E $G%5E EE 4G#F: 7GE E ,F7&F2-G2F77G: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                   " WR#                  S	5      US
9  [        WW45      $  N N No! [         a    e [        /[        Q7 a   n[        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 configured AsyncNetworkingInterface.

Can raise socket.error, ConnectionFailure, or _CertificateError.

Sets protocol's SSL and timeout options.
Nc                    > [        T S9$ Nr   r   r   s   r!   <lambda>0_configured_protocol_interface.<locals>.<lambda>?  s
    8r#   rW   r   c                    > [        T S9$ r   r   r   s   r!   r   r   H  s
    OG4r#   )rD   r   r   r   r   peercertr   )r   r   r   r   r   r   create_connectionr   r/   r\   r   re   r   r   r   r   r   get_extra_infoabort)
r^   r   rD   r   rb   	transportprotocolr   r   r[   s
            @r!   _configured_protocol_interfacer   /  sh     *';;D&&K$$G'**,>>8t ?  
 	
 1:Dc %,$<$<$>$P$P4 	 %Q %
 
	" 	**33	y77
CdS
 $Y$9::U <
   	 i  c 'w/!'0HZabc ! 	OO	sv   E,DAE,!D
"E,0,D DD #3E,$E ;E,
E,D E
*E E,E

E,E))E,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   r   r   r   Nr   r   r   r;   rY   Tr   )r   rI   rB   r   r   r"   r   connectr/   r   r   r   r   getaddrinfor   rJ   rM   rL   r   r	   r   r   r[   r   r   r   rG   r   s                  r!   _create_connectionr   e  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 [	        S5      (       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 [        /[        Q7 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   Nr   Tr   r   r   r   )r   r   r   r   r   r   r   r   r/   r\   r   re   r   r   r   r   r   r   r^   r   rD   r   rb   r   r   r   s           r!   _configured_socketr     s;    g/D&&K../1:Dc D>>"..t.JH"..t4H 	**33	x335E
 ../O1  

 	 i  c

 'w/!'0HZabc ! 	NN	s)   C$ C$ $#E $,E &D;;E Ec                   [        X5      nUR                  nUc&  UR                  UR                  5        [	        U5      $ U S   n [        S5      (       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 [        /[        Q7 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   Tr   r   r   r   )r   r   r   r   r   r   r   r   r   r/   r\   r   re   r   r   r   r   r   r   r   s           r!   _configured_socket_interfacer     sG    g/D&&K../"4((1:Dc D>>"..t.JH"..t4H 	**33	x335E
 ../x((1  

 	 i  c

 'w/!'0HZabc ! 	NN	s*   C6 'C6 -#E 6,E"&EEE1)r   r.   rv   rw   )rD   socket.socketrN   r]   rO   r.   rv   rw   )rD   r   rv   rw   )NN)
r^   r   r_   	Exceptionr`   zOptional[str]ra   zOptional[dict[str, float]]rv   r   )r^   r   r   r   rv   r   )r^   r   r   r   rv   zUnion[socket.socket, _sslConn])r^   r   r   r   rv   r   )r^   r   r   r   rv   r   )F__doc__
__future__r   r   r   rB   r   systypingr   r   r   r   r   pymongor	   pymongo.asynchronous.helpersr
   pymongo.errorsr   r   r   r   pymongo.helpers_sharedr   r   pymongo.network_layerr   r   r   pymongo.pool_optionsr   pymongo.ssl_supportr   r   r   r\   pymongo.pyopenssl_contextr   pymongo.typingsr   r   r   r   r   r"   ImportErrorr>   r@   rV   platform_winregr,   r6   OpenKeyHKEY_LOCAL_MACHINEr1   r=   r?   r/   rG   rQ   re   rg   r   r   r   r   r   r   r%   r#   r!   <module>r      s   0 "    
 
   5  P ` ` , > >"	2(E99/    <<7 
(^^%%'\
#)##H '-c3F'M$	
M? !%26	,,, , 0	,
 ,: M,`55 +5#5p3;3; +3;3;lD,N.b.)I  EE	E  
 

  (  '#' 	(sT   =D< %E -E. 
EE. <E
	E

EE
E+'E. +E. .
E;:E;