
    dafj                     `   d Z ddlZddlZddlZddlZddlmZ ddlmZ ddlm	Z	 	 ddl
Z
ddlZddlmZ ddlmZ ddlmZ dd	lmZ dd
lmZ d Z ej,                  e
du d       G d dej.                               Z G d dej2                        Z ej,                  e
du d       G d deej.                               Z ej,                  e
du d       ej8                   eed      d       G d deej.                                      Zedk(  r ej@                          yy# e$ r dZ
Y w xY w)zTests for asyncio/sslproto.py.    N)support)socket_helper)mock)log)	protocols)sslproto)utils)
functionalc                  .    t        j                  d        y N)asyncioset_event_loop_policy     :/root/Python-3.12.4/Lib/test/test_asyncio/test_sslproto.pytearDownModuler      s    !!$'r   zNo ssl modulec                   z     e Zd Z fdZddddZdddZd Zd Zd	 Zd
 Z	d Z
d Zd Zd Zd Zd Zd Z xZS )SslProtoHandshakeTestsc                     t         |           t        j                         | _        | j                  | j                         y r   )supersetUpr   new_event_looploopset_event_loop)self	__class__s    r   r   zSslProtoHandshakeTests.setUp   s.    **,	DII&r   N)waiterprotoc                @   t        j                         }|t        j                         }t	        j
                  | j                  |||d      }| j                  |j                  j                         |       | j                  |j                  j                         |S )Ng?ssl_handshake_timeout)
test_utilsdummy_ssl_contextr   Protocolr   SSLProtocolr   assertIs_app_transportget_protocol
addCleanupclose)r   r   r   
sslcontext	ssl_protos        r   ssl_protocolz#SslProtoHandshakeTests.ssl_protocol#   s~    113
=$$&E((E:v?BD	i..;;=uE	00667r   do_handshakec                   t        j                         }t        j                         }t        j                  |j                  _        t        j                  |j                  _        |||_        ||_        |j                  |       |S r   )
r   MocksslSSLWantReadErrorreadside_effectwriter/   _sslobjconnection_made)r   r,   r/   	transportsslobjs        r   r8   z&SslProtoHandshakeTests.connection_made-   sf    IIK	"%"6"6#&#7#7 #".F"	!!),r   c                    t        j                         }t        j                         }t        j                         }| j	                  t
        d      5  t        j                  | j                  |||d       d d d        y # 1 sw Y   y xY w)Na positive numberr   r    	r"   r#   r   r1   assertRaisesRegex
ValueErrorr   r%   r   r   r+   	app_protor   s       r   test_handshake_timeout_zeroz2SslProtoHandshakeTests.test_handshake_timeout_zero9   si    113
IIK	##J0CD 	:  Iz678:	: 	: 	:   %BB
c                    t        j                         }t        j                         }t        j                         }| j	                  t
        d      5  t        j                  | j                  |||d       d d d        y # 1 sw Y   y xY w)Nr<   ir    r=   r@   s       r   test_handshake_timeout_negativez6SslProtoHandshakeTests.test_handshake_timeout_negativeA   si    113
IIK	##J0CD 	<  Iz67:<	< 	< 	<rC   c                 l   | j                   j                         }| j                  |      }| j                  |t	        j
                  t        j                               |j                          t        j                  | j                          | j                  |j                         t               y Nr   )r5   r.   )r   create_futurer-   r8   r   r1   r2   r3   eof_receivedr"   run_brieflyassertIsInstance	exceptionConnectionResetErrorr   r   r,   s      r   test_eof_received_waiterz/SslProtoHandshakeTests.test_eof_received_waiterI   s    ((*%%V%4	s/C/CD 	 	
 	 tyy)f..02FGr   c                    | j                   j                         }| j                  |      }t        j                  j                         }t        j                  j                  t        j                         	 |j                  d        t        j                  j                  |       y # t        j                  j                  |       w xY wNrH   )
r   rI   r-   r   loggergetEffectiveLevelsetLevelloggingFATAL_fatal_error)r   r   r,   	log_levels       r   test_fatal_error_no_name_errorz5SslProtoHandshakeTests.test_fatal_error_no_name_errorT   s     ((*%%V%4	JJ002	

GMM*	+""4( JJ	*CJJ	*s   9B* *!Cc                 v   | j                   j                         }| j                  |      }| j                  |t	        j
                  t        j                               |j                  t               t        j                  | j                          | j                  |j                         t               y rG   )r   rI   r-   r8   r   r1   r2   r3   connection_lostConnectionAbortedErrorr"   rK   rL   rM   rO   s      r   test_connection_lostz+SslProtoHandshakeTests.test_connection_lostc   s     ((*%%V%4	s/C/CD 	 	
 	!!"89tyy)f..02HIr   c                    | j                   j                         }| j                  |      }| j                  |t	        j
                  t        j                              }t        j                  | j                          |j                  j                          | j                  |j                  j                         y rG   )r   rI   r-   r8   r   r1   r2   r3   r"   rK   r'   r*   
assertTrue_force_closecalled)r   r   r,   r9   s       r   test_close_during_handshakez2SslProtoHandshakeTests.test_close_during_handshakep   s    ((*%%V%4	((s/C/CD ) 
	 	tyy)  &&(	..556r   c                     | j                  | j                               }| j                  |       g | j                  j                  fd       |j                  j                          | j                  g        y )Nr   c                 &    j                  |      S r   appendr   ctxmessagess     r   <lambda>zGSslProtoHandshakeTests.test_close_during_ssl_over_ssl.<locals>.<lambda>       (//#:N r   )r-   r8   r   set_exception_handlerr'   r*   assertEqual)r   outerrk   s     @r   test_close_during_ssl_over_sslz5SslProtoHandshakeTests.test_close_during_ssl_over_ssl~   si     !!(9(9(;!<U#		''(NO""$2&r   c                    | j                   j                         }| j                  |      }| j                  |j	                  d             t               }| j                  |j	                  d|      |       | j                  |       | j                  |j	                  d             |j                  d        | j                  |j	                  d             y )NrH   socket)
r   rI   r-   assertIsNone_get_extra_infoobjectr&   r8   assertIsNotNoner\   )r   r   r,   defaults       r   (test_get_extra_info_on_closed_connectionz?SslProtoHandshakeTests.test_get_extra_info_on_closed_connection   s    ((*%%V%4	)33H=>(i//'BGLY'Y66x@A!!$')33H=>r   c                 F   | j                   j                         }| j                  |      }t        j                         }|j
                  j                  |       | j                  |j
                  j                         |       | j                  |j                  |       y rR   )
r   rI   r-   r   r$   r'   set_protocolr&   r(   _app_protocol)r   r   r,   new_app_protos       r   test_set_new_app_protocolz0SslProtoHandshakeTests.test_set_new_app_protocol   sz    ((*%%V%4	((*  --m<i..;;=}Mi--}=r   c                     | j                         }| j                  |       |j                  }|j                          | j	                  |j                  d             y )N   )r-   r8   r'   r*   rt   buffer_updatedr   r,   transps      r    test_data_received_after_closingz7SslProtoHandshakeTests.test_data_received_after_closing   sM    %%'	Y')) 	)22156r   c                     | j                         }| j                  |       |j                  }|j                          | j	                  |j                  d             y )Ns   data)r-   r8   r'   r*   rt   r6   r   s      r   test_write_after_closingz/SslProtoHandshakeTests.test_write_after_closing   sK    %%'	Y')) 	&,,w/0r   )__name__
__module____qualname__r   r-   r8   rB   rE   rP   rZ   r^   rc   rq   ry   r~   r   r   __classcell__)r   s   @r   r   r      sW    '
 &*  :> 
:<	H+J7
'	?>71r   r   c                       e Zd ZdZej
                  Zd Zd Zd Z	d Z
ej                  d        Zd Zej                  d        Zd	 Zd
 Zd Zd Zd Zy)BaseStartTLSi  c                     t         r   )NotImplementedErrorr   s    r   new_loopzBaseStartTLS.new_loop   s    !!r   c                 ,    G d dt         j                        }dD ]h  } |d|      }t        j                  |d       | j	                  |j
                  d        |d|      }t        j                  |d       | j	                  |j
                  d        |d|      }t        j                  |d       | j	                  |j
                  d        |d|      }t        j                  |d       | j	                  |j
                  d        |d	|      }t        j                  |d       | j	                  |j
                  d        |d
|      }| j                  t        d      5  t        j                  |d       d d d        k y # 1 sw Y   wxY w)Nc                       e Zd Zd Zd Zd Zy).BaseStartTLS.test_buf_feed_data.<locals>.Protoc                 t    t        |      | _        t        | j                        | _        d| _        || _        y Nr   )	bytearraybuf
memoryviewmvdatausemv)r   bufsizer   s      r   __init__z7BaseStartTLS.test_buf_feed_data.<locals>.Proto.__init__   s,    $W-$TXX.	"
r   c                 J    | j                   r| j                  S | j                  S r   )r   r   r   r   sizehints     r   
get_bufferz9BaseStartTLS.test_buf_feed_data.<locals>.Proto.get_buffer   s    ::77N88Or   c                     | j                   r#| xj                  | j                  d | z  c_        y | xj                  | j                  d | z  c_        y r   )r   r   r   r   )r   nsizes     r   r   z=BaseStartTLS.test_buf_feed_data.<locals>.Proto.buffer_updated   s:    ::II%0III&5!11Ir   N)r   r   r   r   r   r   r   r   r   Protor      s    #$2r   r   )FT   s   12345   s   1234   d   r   zempty buffer)r   BufferedProtocolr   _feed_data_to_buffered_protoro   r   r>   RuntimeError)r   r   r   r   s       r   test_buf_feed_datazBaseStartTLS.test_buf_feed_data   s]   	2G,, 	2( # 	HE!UOE225(CUZZ2!UOE225(CUZZ2!UOE225'BUZZ1!UOE225'BUZZ1#u%E225(CUZZ2!UOE''nE H66uhGH H-	H,H Hs   &F		F	c                 N    d j                   z  t        j                         t        j                          fd} G  fddt        j
                         fd} j                  | j                        5 } j                  j                  t	        j                   ||j                        t        j                               d d d        t        j                        t        j                            j#                                 y # 1 sw Y   IxY w)N   1c                    | j                  j                         | j                  t                    }j	                  t        |      t                     | j                  d       | j                  d       | j                  t                    }j	                  t        |      t                     | j                  t        j                         | j                          y NTserver_side   O
settimeoutTIMEOUTrecv_alllenro   	start_tlssendallshutdownrs   	SHUT_RDWRr*   sockr   	HELLO_MSGr   server_contexts     r   servez=BaseStartTLS.test_start_tls_client_reg_proto_1.<locals>.serve   s    OODLL)==Y0DSYI7NN>tN<LL==Y0DSYI7MM&**+JJLr   c                   *    e Zd Zd Z fdZd Zd Zy)CBaseStartTLS.test_start_tls_client_reg_proto_1.<locals>.ClientProtoc                 .    || _         || _        d| _        y Nr   on_dataon_eofcon_made_cntr   r   r   s      r   r   zLBaseStartTLS.test_start_tls_client_reg_proto_1.<locals>.ClientProto.__init__      &$$%!r   c                 h    | xj                   dz  c_         j                  | j                   d       y Nr   r   ro   r   trr   s     r   r8   zSBaseStartTLS.test_start_tls_client_reg_proto_1.<locals>.ClientProto.connection_made  *    ""a'"  !3!3Q7r   c                 :    | j                   j                  |       y r   r   
set_resultr   r   s     r   data_receivedzQBaseStartTLS.test_start_tls_client_reg_proto_1.<locals>.ClientProto.data_received      ''-r   c                 :    | j                   j                  d       y NTr   r   r   s    r   rJ   zPBaseStartTLS.test_start_tls_client_reg_proto_1.<locals>.ClientProto.eof_received      &&t,r   Nr   r   r   r   r8   r   rJ   r   s   r   ClientProtor         &
8
.-r   r   c                   K   t        j                  d       d {    	j                  j                         	j                  j                          	j                  j                  fdg|   d {   \  }}|j                         	j                  j                  ||       d {   }	j                   d {   d       |j                          d {    |j                          y 7 7 7 N7 ;7 w)N      ?c                              S r   r   r   r   r   s   r   rl   zPBaseStartTLS.test_start_tls_client_reg_proto_1.<locals>.client.<locals>.<lambda>      GV4 r   r   )	r   sleepr   rI   create_connectionr6   r   ro   r*   )
addrr   r   new_trr   r   r   r   client_contextr   s
       @@r   clientz>BaseStartTLS.test_start_tls_client_reg_proto_1.<locals>.client  s     --$$$ii--/GYY,,.F9dii994=7;= =IB HHY99..r5.IIF7]D1LL#LLLLN %
= J*sX   D
D AD
<D=8D
5D6D

DD
*D+D
D
D
D
D
timeoutPAYLOAD_SIZEr"   simple_server_sslcontextsimple_client_sslcontextr   r$   
tcp_serverr   r   run_until_completewait_forr   r   SHORT_TIMEOUTweakrefref
gc_collectrt   r   r   r   srvr   r   r   r   s   `   @@@@r   !test_start_tls_client_reg_proto_1z.BaseStartTLS.test_start_tls_client_reg_proto_1   s    4,,,	#<<>#<<>		-'** 	-"	$ __UDLL_9 	ASII((  !1)0)>)>@A	A !^4.*+	A 	A   ADD$c                 N    d j                   z  t        j                         t        j                          fd} G  fddt        j
                         fd} j                  | j                        5 } j                  j                  t	        j                   ||j                        t        j                               d d d        t        j                        t        j                            j#                                 y # 1 sw Y   IxY w)Nr   c                 ^   | j                  j                         | j                  d       | j                  d       | j	                  t                    }j                  t        |      t                     | j                  t        j                         | j                          y r   )r   r   r   r   r   r   ro   r   rs   r   r*   r   s     r   r   z>BaseStartTLS.test_create_connection_memory_leak.<locals>.serve5  st    OODLL)NN>tN<LL==Y0DSYI7MM&**+JJLr   c                   *    e Zd Zd Z fdZd Zd Zy)DBaseStartTLS.test_create_connection_memory_leak.<locals>.ClientProtoc                 .    || _         || _        d| _        y r   r   r   s      r   r   zMBaseStartTLS.test_create_connection_memory_leak.<locals>.ClientProto.__init__B  r   r   c                 v    || _         | xj                  dz  c_        j                  | j                  d       y r   )r   r   ro   r   s     r   r8   zTBaseStartTLS.test_create_connection_memory_leak.<locals>.ClientProto.connection_madeG  s1    ""a'"  !3!3Q7r   c                 :    | j                   j                  |       y r   r   r   s     r   r   zRBaseStartTLS.test_create_connection_memory_leak.<locals>.ClientProto.data_receivedN  r   r   c                 :    | j                   j                  d       y r   r   r   s    r   rJ   zQBaseStartTLS.test_create_connection_memory_leak.<locals>.ClientProto.eof_receivedQ  r   r   Nr   r   s   r   r   r   A  s    &
8.-r   r   c                   K   t        j                  d       d {    j                  j                         j                  j                          j                  j                  fdg| di d {   \  }}j                   d {   d       |j                          d {    |j                          y 7 7 O7 97 w)Nr   c                              S r   r   r   s   r   rl   zQBaseStartTLS.test_create_connection_memory_leak.<locals>.client.<locals>.<lambda>[  r   r   r2   r   )r   r   r   rI   r   ro   r6   r*   )	r   r   r   r   r   r   r   r   r   s	      @@r   r   z?BaseStartTLS.test_create_connection_memory_leak.<locals>.clientT  s     --$$$ii--/GYY,,.F9dii994$7;$"$ $IB 7]D1HHYLLHHJ %
$ +sF   CCA C?C CCC7C8CCCCr   r   r   s   `   @@@@r   "test_create_connection_memory_leakz/BaseStartTLS.test_create_connection_memory_leak/  s    4,,,	#<<>#<<>
		-'** 	-&	  __UDLL_9 	ASII((  !1)0)>)>@A	A !^4.*+	A 	Ar   c                    	 d j                   z  t        j                         	t        j                         d 	fd} G  fddt        j
                         G fddt        j                         fd} j                  | j                  	      5 } j                  j                  t	        j                   ||j                         j                  	             d d d        y # 1 sw Y   y xY w)
Nr   r   c                 x   | j                  j                         | j                  t                    }j	                  t        |      t                     | j                  d       | j                  d       | j                  t                    }j	                  t        |      t                     | j                  d       | j                  t                    }j	                  t        |      t                     | j                  t        j                         | j                          y )NTr   r      2r   r   s     r   r   z=BaseStartTLS.test_start_tls_client_buf_proto_1.<locals>.servew  s    OODLL)==Y0DSYI7NN>tN<LL==Y0DSYI7LL==Y0DSYI7MM&**+JJLr   c                   .    e Zd Zd Z fdZd ZfdZy)HBaseStartTLS.test_start_tls_client_buf_proto_1.<locals>.ClientProtoFirstc                 2    || _         t        d      | _        y r   )r   r   r   )r   r   s     r   r   zQBaseStartTLS.test_start_tls_client_buf_proto_1.<locals>.ClientProtoFirst.__init__  s    &$Q<r   c                     dz  y r   r   r   r   client_con_made_callss     r   r8   zXBaseStartTLS.test_start_tls_client_buf_proto_1.<locals>.ClientProtoFirst.connection_made      %*%r   c                     | j                   S r   )r   r   s     r   r   zSBaseStartTLS.test_start_tls_client_buf_proto_1.<locals>.ClientProtoFirst.get_buffer  s    xxr   c                     j                  |d       | j                  j                  t        | j                  d |              y r   )ro   r   r   bytesr   )slfr   r   s     r   r   zWBaseStartTLS.test_start_tls_client_buf_proto_1.<locals>.ClientProtoFirst.buffer_updated  s4      *&&uSWWVe_'=>r   N)r   r   r   r   r8   r   r   )r  r   s   r   ClientProtoFirstr
    s    (+ ?r   r  c                   *    e Zd Zd Z fdZd Zd Zy)IBaseStartTLS.test_start_tls_client_buf_proto_1.<locals>.ClientProtoSecondc                 .    || _         || _        d| _        y r   r   r   s      r   r   zRBaseStartTLS.test_start_tls_client_buf_proto_1.<locals>.ClientProtoSecond.__init__  r   r   c                     dz  y r   r   r  s     r   r8   zYBaseStartTLS.test_start_tls_client_buf_proto_1.<locals>.ClientProtoSecond.connection_made  r  r   c                 :    | j                   j                  |       y r   r   r   s     r   r   zWBaseStartTLS.test_start_tls_client_buf_proto_1.<locals>.ClientProtoSecond.data_received  r   r   c                 :    | j                   j                  d       y r   r   r   s    r   rJ   zVBaseStartTLS.test_start_tls_client_buf_proto_1.<locals>.ClientProtoSecond.eof_received  r   r   Nr   )r  s   r   ClientProtoSecondr    s    &
+.-r   r  c                   K   t        j                  d       d {    j                  j                         j                  j                         }j                  j                         } j                  j                  fdg|   d {   \  }}|j                  	       j                  j                  ||       d {   }j                   d {   d       |j                  	       |j                   ||             j                  | d {   d       |j                  	       | d {    |j                          j                  
d       y 7 P7 7 7 7 P7 2w)Nr   c                              S r   r   )r  on_data1s   r   rl   zPBaseStartTLS.test_start_tls_client_buf_proto_1.<locals>.client.<locals>.<lambda>  s    (2 r   r   r  r   )
r   r   r   rI   r   r6   r   ro   r{   r*   )r   on_data2r   r   r   r   r  r  r  r   r  r   r   s         @r   r   z>BaseStartTLS.test_start_tls_client_buf_proto_1.<locals>.client  s7    --$$$yy..0Hyy..0HYY,,.F9dii992;59; ;IB HHY99..r5.IIF8^T2LL# 1(F CD8^T2LL#LLLLN
 2A63 %; J+ ,sk   E:E-A6E:E08E:E2E:"E4#AE:%E6&E:E8(E:0E:2E:4E:6E:8E:r   )r   r"   r   r   r   r   r$   r   r   r   r   r   r   )
r   r   r   r   r  r  r   r  r   r   s
   `   @@@@@@r   !test_start_tls_client_buf_proto_1z.BaseStartTLS.test_start_tls_client_buf_proto_1o  s    4,,,	#<<>#<<> !	&	?w77 	? 	- 0 0 	- 	7 	78 __UDLL_9 	8SII((  !1)-78	8 	8 	8s   &AC::Dc                     d j                   z  t        j                          j                  j	                          fd} G  fddt
        j                         fd} j                  | j                        5 } j                  j                  t        j                   ||j                        t        j                               d d d        y # 1 sw Y   y xY w)Nr   c                    | j                  j                         | j                  t                    }j	                  t        |      t                     	 j
                  j                  j                  d        | j                  d      }| j                          y # t        $ r Y w xY w# | j                          w xY wN   )
r   r   r   r   ro   r   call_soon_threadsafer   r]   r*   )r   r   r   r   server_waits_on_handshakes     r   r   z=BaseStartTLS.test_start_tls_slow_client_cancel.<locals>.serve  s    OODLL)==Y0DSYI7		..-88$@}}[1 

 *  

s$   7B$ $	B0-B3 /B00B3 3Cc                   *    e Zd Zd Z fdZd Zd Zy)CBaseStartTLS.test_start_tls_slow_client_cancel.<locals>.ClientProtoc                 .    || _         || _        d| _        y r   r   r   s      r   r   zLBaseStartTLS.test_start_tls_slow_client_cancel.<locals>.ClientProto.__init__  r   r   c                 h    | xj                   dz  c_         j                  | j                   d       y r   r   r   s     r   r8   zSBaseStartTLS.test_start_tls_slow_client_cancel.<locals>.ClientProto.connection_made  r   r   c                 :    | j                   j                  |       y r   r   r   s     r   r   zQBaseStartTLS.test_start_tls_slow_client_cancel.<locals>.ClientProto.data_received  r   r   c                 :    | j                   j                  d       y r   r   r   s    r   rJ   zPBaseStartTLS.test_start_tls_slow_client_cancel.<locals>.ClientProto.eof_received  r   r   Nr   r   s   r   r   r(    r   r   r   c                 .  K   t        j                  d       d {    j                  j                         j                  j                          j                  j                  fdg|   d {   \  }}|j                         	 d {    j                  t         j                        5  t        j                  j                  j                  ||      d       d {    d d d        y 7 7 7 j7 # 1 sw Y   y xY ww)Nr   c                              S r   r   r   s   r   rl   zPBaseStartTLS.test_start_tls_slow_client_cancel.<locals>.client.<locals>.<lambda>  r   r   )
r   r   r   rI   r   r6   assertRaisesTimeoutErrorr   r   )
r   r   r   r   r   r   r   r   r   r&  s
      @@r   r   z>BaseStartTLS.test_start_tls_slow_client_cancel.<locals>.client  s     --$$$ii--/GYY,,.F9dii994=7;= =IB HHY+++""7#7#78 &&II''E>B    %
=
 , s^   DDAD<D=DD#D>5D	3D4D	8
DDDD		DDr   )r   r"   r   r   rI   r   r$   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r&  s   `   @@@@r   !test_start_tls_slow_client_cancelz.BaseStartTLS.test_start_tls_slow_client_cancel  s    4,,,	#<<>$(II$;$;$=!		-'** 	-"	 	$ __UDLL_9 	ASII((  !1)0)>)>@A	A 	A 	As   AC##C,c                 8   	 d j                   z  dt        j                         	t        j                         d  fd G fddt        j
                         	fd fd} j                  j                   |              y )Nr   s   answerc                 r   | j                  j                         | j                  |       | j                  t	                    }j                  t	        |      t	                     | j                         | j                         | j                  t	                    | j                          y r   )	r   r   connectr   r   ro   r   r   r*   )r   r   r   ANSWERr   answerr   r   s      r   r   z4BaseStartTLS.test_start_tls_server_1.<locals>.client  s|    OODLL)LL==Y0DSYI7NN>*LL#]]3v;/FJJLr   c                   0    e Zd Zd Zd Zd Z fdZd Zy)9BaseStartTLS.test_start_tls_server_1.<locals>.ServerProtoc                 J    || _         || _        || _        d| _        d | _        y r   )on_conon_con_loston_got_hellor   r9   )r   r:  r;  r<  s       r   r   zBBaseStartTLS.test_start_tls_server_1.<locals>.ServerProto.__init__  s'    $#. $0!	!%r   c                 H    || _         | j                  j                  |       y r   )r9   r:  r   r   r   s     r   r8   zIBaseStartTLS.test_start_tls_server_1.<locals>.ServerProto.connection_made&  s    !#&&r*r   c                     || _         y r   )r9   r>  s     r   replace_transportzKBaseStartTLS.test_start_tls_server_1.<locals>.ServerProto.replace_transport*  s	    !#r   c                     | xj                   |z  c_         t        | j                         t              k\  r| j                  j                  d        y y r   )r   r   r<  r   )r   r   r   s     r   r   zGBaseStartTLS.test_start_tls_server_1.<locals>.ServerProto.data_received-  s>    		T!	tyy>S^3%%006 4r   c                     d | _         || j                  j                  d        y | j                  j                  |       y r   )r9   r;  r   set_exception)r   excs     r   r\   zIBaseStartTLS.test_start_tls_server_1.<locals>.ServerProto.connection_lost2  s6    !%;$$//5$$2237r   N)r   r   r   r   r8   r@  r   r\   )r   s   r   ServerProtor8    s    &+$7
8r   rE  c                   K   | d {   }|j                         j                  | j                  d       j                  j	                  || 	dj
                         d {   }| j                  |       | d {    |j                         | d {    j                  | j                         |j                          y 7 7 i7 P7 7w)Nr   T)r   r!   )r6   ro   r   r   r   r   r@  r*   )
r   r:  r;  r<  r   r   r5  r   r   r   s
         r   mainz2BaseStartTLS.test_start_tls_server_1.<locals>.main9  s     BHHYUZZ-99..E> &*ll / 4 4F ##F+LL UZZ3LLN! 
4  sF   CCAC(C)CCCC2CCCCc            	        K   j                   j                         } j                   j                         }j                   j                         } | ||      j                   j                  fddd       d {   }|j                  d   j	                         j                  	fdj                        5  t        j                   
| ||      j                         d {    d d d        |j                          |j                          d {    j                         y 7 7 I# 1 sw Y   HxY w7 'w)Nc                       S r   r   re   s   r   rl   zHBaseStartTLS.test_start_tls_server_1.<locals>.run_main.<locals>.<lambda>S  s     r   z	127.0.0.1r   c                      |       S r   r   )r   r   r   s    r   rl   zHBaseStartTLS.test_start_tls_server_1.<locals>.run_main.<locals>.<lambda>V  s    fT4.@ r   r   )r   rI   create_serversocketsgetsockname
tcp_clientr   r   r   r*   wait_closedro   )r:  r;  r<  serverr   r   r5  rE  r6  r   rG  r   s       @@r   run_mainz6BaseStartTLS.test_start_tls_server_1.<locals>.run_mainL  s    YY,,.F))113K99224L\BE9922{A/ /F>>!$002D!@)- ! 7 *&&\B LL* * ** LLN$$&&&VV,/** * 'sI   A<ED:AE.D>2D<3D>7+E"E
#E<D>>EE)r   r"   r   r   r   r$   r   r   )
r   rQ  r5  r   rE  r6  r   r   rG  r   s
   ` @@@@@@@@r   test_start_tls_server_1z$BaseStartTLS.test_start_tls_server_1  s{    4,,,	#<<>#<<>	 		8'** 	86	&	- 	-( 			$$XZ0r   c                 P      fd} j                   j                   |              y )Nc                  ~  K   j                  t        d      5  j                  j                  d d d        d {    d d d        t	        j
                         } j                  t        d      5  j                  j                  d d |        d {    d d d        y 7 e# 1 sw Y   dxY w7 # 1 sw Y   y xY ww)NzSSLContext, gotzis not supported)r>   	TypeErrorr   r   r"   r   )sslctxr   s    r   rG  z4BaseStartTLS.test_start_tls_wrong_args.<locals>.mainc  s     ''	3DE <ii))$d;;;<  88:F''	3EF >ii))$f===> > << <
 >> >sV   B=!B#B!B# 2B=2!B1B/B1	B=!B##B,(B=/B11B:6B=)r   r   )r   rG  s   ` r   test_start_tls_wrong_argsz&BaseStartTLS.test_start_tls_wrong_argsb  s    	> 			$$TV,r   c                 b    t        j                         g  j                  j                  fd       dfd} fd} j	                  |dd      5 } j                  t        j                        5   j                  j                   ||j                               d d d        d d d         j                          j                  g        t        j                        t        j                           j!                                 y # 1 sw Y   txY w# 1 sw Y   xxY w)Nc                 &    j                  |      S r   rg   ri   s     r   rl   z5BaseStartTLS.test_handshake_timeout.<locals>.<lambda>s  rm   r   Fc                     	 | j                  d       | j                          y # t        $ r dY w xY w# | j                          w xY w)Nr$  Tr   r]   r*   )r   server_side_aborteds    r   rP  z3BaseStartTLS.test_handshake_timeout.<locals>.serverw  sB    k* 

 * +&*#+ 

s   % 36 36 Ac           	         K   t        j                   j                  j                  t         j                  g| dt
        j                  dd       d {    y 7 w)N r2   server_hostnamer!   r   )r   r   r   r   r$   r   r   )r   client_sslctxr   s    r   r   z3BaseStartTLS.test_handshake_timeout.<locals>.client  sb     ""+		++$$AA &$&*1*?*?A   s   AA!AA!r   max_clientsbacklog)r"   r   r   rn   r   r/  r   r0  r   r   r`   ro   r   r   r   r   rt   )r   rP  r   r   ra  rk   r\  s   `   @@@r   test_handshake_timeoutz#BaseStartTLS.test_handshake_timeoutm  s     #;;=		''(NO#		 __V)*%&  ( 	?+.""7#7#78 ?		,,VCHH-=>?		? 	+, 	2&  M2-/*? ?		? 	?s$    D%:,D&D%D"	D%%D.c                    t        j                         g | j                  j                  fd       d }fd}| j	                  |dd      5 }| j                  t        d      5  | j                  j                   ||j                               d d d        d d d        | j                  g        y # 1 sw Y   $xY w# 1 sw Y   (xY w)Nc                 &    j                  |      S r   rg   ri   s     r   rl   zHBaseStartTLS.test_create_connection_ssl_slow_handshake.<locals>.<lambda>  rm   r   c                     	 | j                  d       | j                          y # t        $ r Y w xY w# | j                          w xY wr#  r[  )r   s    r   rP  zFBaseStartTLS.test_create_connection_ssl_slow_handshake.<locals>.server  s>    k* 

 *  

s   $ 	03 03 Ac                 V   K   t        j                  | ddd d {   \  }}y 7 w)Nr^  g      ?r_  )r   open_connectionr   readerwriterra  s      r   r   zFBaseStartTLS.test_create_connection_ssl_slow_handshake.<locals>.client  s1     #*#:#:! "&)	$+ +NFF +s   )'	)r   rb  zSSL handshake.*is taking longer)
r"   r   r   rn   r   r>   r]   r   r   ro   )r   rP  r   r   ra  rk   s       @@r   )test_create_connection_ssl_slow_handshakez6BaseStartTLS.test_create_connection_ssl_slow_handshake  s    ";;=		''(NO		+ __V)*%&  ( 	?+.''*68 ? 		,,VCHH-=>	?		? 	2&? ?		? 	?s$   C*,B9C9C	>CCc                    | j                   j                  d        t        j                         t        j                  d      fd}fd}| j                  |dd      5 }| j                  t        j                        5  | j                   j                   ||j                               d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)Nc                      y r   r   r   rj   s     r   rl   zLBaseStartTLS.test_create_connection_ssl_failed_certificate.<locals>.<lambda>      r   F)disable_verifyc                     	 | j                  d       | j	                          y # t        j                  $ r Y &t        $ r Y 0w xY w# | j	                          w xY w)NTr   )r   r2   SSLErrorOSErrorr*   )r   rV  s    r   rP  zJBaseStartTLS.test_create_connection_ssl_failed_certificate.<locals>.server  sY    	 $  & 

 <<   

s+   ' AA
 AA
 AA
 
Ac                 r   K   t        j                  | dt        j                  d d {   \  }}y 7 w)Nr^  r_  )r   rj  r   LOOPBACK_TIMEOUTrk  s      r   r   zJBaseStartTLS.test_create_connection_ssl_failed_certificate.<locals>.client  s:     #*#:#:! "&-&>&>	$@ @NFF @s   )75	7r   rb  )r   rn   r"   r   r   r   r/  r2   SSLCertVerificationErrorr   r   )r   rP  r   r   ra  rV  s       @@r   -test_create_connection_ssl_failed_certificatez:BaseStartTLS.test_create_connection_ssl_failed_certificate  s    		''(>?446";; "
		@ __V)*%&  ( 	?+.""3#?#?@ ?		,,VCHH-=>?		? 	?? ?		? 	?s$   ' C,C3CC		CCc                 t     j                   j                  d        t        j                         t        j                         fd} fd} j                  |dd      5 } j                   j                   ||j                              }d d d         j                  d       y # 1 sw Y   xY w)Nc                      y r   r   rq  s     r   rl   zBBaseStartTLS.test_start_tls_client_corrupted_ssl.<locals>.<lambda>  rr  r   c                 p   | j                         }	 | j                  d       | j                  d       | j                  d       |j	                  d       |j                          | j                          y # t
        j                  $ r Y 6w xY w# |j                          | j                          w xY w)NTr      A
r   s!   please corrupt the SSL connection)dupr   r   r   sendr2   ru  r*   )r   	orig_sockrV  s     r   rP  z@BaseStartTLS.test_start_tls_client_corrupted_ssl.<locals>.server  s    
I $  & V$a CD !

	 <<  !

s$   AA: :BB BB "B5c                   K   t        j                  | dd d {   \  }}j                  |j                          d {   d       |j	                  d       j                  t        j                        5  |j                          d {    d d d        |j                          y7 7 m7 !# 1 sw Y    xY ww)Nr^  )r2   r`  r~     BOK)	r   rj  ro   readliner6   r/  r2   ru  r*   )r   rl  rm  ra  r   s      r   r   z@BaseStartTLS.test_start_tls_client_corrupted_ssl.<locals>.client  s     #*#:#:! "$$ $NFF
 6??#44f=LL""3<<0 (oo'''( LLN$
 5 (( (sK   CB/%CB19C=B5B3B5C1C3B55B>:Cr   rb  r  )	r   rn   r"   r   r   r   r   r   ro   )r   rP  r   r   resra  rV  s   `    @@r   #test_start_tls_client_corrupted_sslz0BaseStartTLS.test_start_tls_client_corrupted_ssl  s    		''(>?446";;=		 __V)*%&  ( 	A+.))..vchh/?@C		A 	d#	A 	As   ',B..B7N)r   r   r   r   r   LONG_TIMEOUTr   r   r   r   r  r   skip_if_tcp_blackholer   r1  rR  rW  re  rn  rz  r  r   r   r   r   r      s    L""G"-H^@,D>,@ ((Y8 )Y8v;Az ((W1 )W1r	-.+`'B?B)$r   r   c                       e Zd Zd Zy)SelectorStartTLSTestsc                 *    t        j                         S r   )r   SelectorEventLoopr   s    r   r   zSelectorStartTLSTests.new_loop      ((**r   Nr   r   r   r   r   r   r   r  r    s    +r   r  ProactorEventLoopzWindows onlyc                       e Zd Zd Zy)ProactorStartTLSTestsc                 *    t        j                         S r   )r   r  r   s    r   r   zProactorStartTLSTests.new_loop  r  r   Nr  r   r   r   r  r    s    +r   r  __main__)!__doc__rV   rs   unittestr   testr   test.supportr   r   r2   ImportErrorr   r   r   r   test.test_asyncior	   r"   r
   
func_testsr   skipIfTestCaser   FunctionalTestCaseMixinr   r  
skipUnlesshasattrr  r   rG  r   r   r   <module>r     sB   $      &      1 6( o.R1Z00 R1 /R1tR	$:55 R	$j o.+L(*;*; + /+ o.WW&9:NK+L(*;*; + L /+ zHMMO ]  
Cs   D" "D-,D-