a
    zeYh                     @   sL  d dl Z d dlZd dlZd dlZd dlmZ zd dlZW n eyN   dZY n0 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 dlmZ d	d
 Zeedu dG dd dejZG dd dejZeedu dG dd deejZeedu deeeddG dd deejZedkrHe  dS )    N)mock)log)	protocols)sslproto)support)utils)
functionalc                   C   s   t d  d S N)asyncioZset_event_loop_policy r   r   5/usr/lib/python3.9/test/test_asyncio/test_sslproto.pytearDownModule   s    r   zNo ssl modulec                       s   e Zd Z fddZdddddZdddd	Zd
d Zdd Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Z  ZS )SslProtoHandshakeTestsc                    s$   t    t | _| | j d S r	   )supersetUpr
   Znew_event_looploopZset_event_loopself	__class__r   r   r      s    

zSslProtoHandshakeTests.setUpN)waiterprotoc                C   sR   t  }|d u rt }tj| j|||dd}| |j	 | | 
|jj |S )Ng?ssl_handshake_timeout)
test_utilsdummy_ssl_contextr
   Protocolr   SSLProtocolr   assertIs_app_transportget_protocolZ
addCleanupclose)r   r   r   
sslcontext	ssl_protor   r   r   ssl_protocol"   s    z#SslProtoHandshakeTests.ssl_protocol)do_handshakec                C   sr   t  }t  }d|j_|r&||j_ndd }||j_t jd|d || W d    n1 sd0    Y  |S )N    c                 S   s   g S r	   r   )callbackr   r   r   mock_handshake3   s    z>SslProtoHandshakeTests.connection_made.<locals>.mock_handshakezasyncio.sslproto._SSLPipe)return_value)r   Mockshutdownr)   r%   Zside_effectZpatchconnection_made)r   r#   r%   	transportZsslpiper(   r   r   r   r,   ,   s    
(z&SslProtoHandshakeTests.connection_madec                 C   s^   t  }t }t }| td& tj| j|||dd W d    n1 sP0    Y  d S )Na positive numberr   r   	r   r   r   r*   assertRaisesRegex
ValueErrorr   r   r   r   r"   Z	app_protor   r   r   r   test_handshake_timeout_zero:   s    z2SslProtoHandshakeTests.test_handshake_timeout_zeroc                 C   s^   t  }t }t }| td& tj| j|||dd W d    n1 sP0    Y  d S )Nr.   ir   r/   r2   r   r   r   test_handshake_timeout_negativeB   s    z6SslProtoHandshakeTests.test_handshake_timeout_negativec                 C   sH   | j  }| j|d}| | |  t| j  | | t	 d S Nr   )
r   create_futurer$   r,   eof_receivedr   run_brieflyassertIsInstance	exceptionConnectionResetErrorr   r   r#   r   r   r   test_eof_received_waiterJ   s    

z/SslProtoHandshakeTests.test_eof_received_waiterc              	   C   s\   | j  }| j|d}tj }tjtj z|	d  W tj| ntj| 0 d S r5   )
r   r7   r$   r   loggergetEffectiveLevelsetLevelloggingFATALZ_fatal_error)r   r   r#   Z	log_levelr   r   r   test_fatal_error_no_name_errorR   s    

z5SslProtoHandshakeTests.test_fatal_error_no_name_errorc                 C   sJ   | j  }| j|d}| | |t t| j  | |	 t d S r5   )
r   r7   r$   r,   connection_lostConnectionAbortedErrorr   r9   r:   r;   r=   r   r   r   test_connection_losta   s    


z+SslProtoHandshakeTests.test_connection_lostc                 C   sH   | j  }| j|d}| |}t| j  |j  | |j	j
 d S r5   )r   r7   r$   r,   r   r9   r   r!   
assertTrueabortZcalled)r   r   r#   r-   r   r   r   test_close_during_handshakek   s    


z2SslProtoHandshakeTests.test_close_during_handshakec                 C   sx   | j  }| j|d}| |d t }| |d|| | | | |d |	d  | |d d S )Nr6   socket)
r   r7   r$   assertIsNoneZ_get_extra_infoobjectr   r,   ZassertIsNotNonerE   )r   r   r#   defaultr   r   r   (test_get_extra_info_on_closed_connectionv   s    


z?SslProtoHandshakeTests.test_get_extra_info_on_closed_connectionc                 C   sN   | j  }| j|d}t }|j| | |j | | |j	| d S r5   )
r   r7   r$   r
   r   r   set_protocolr   r    Z_app_protocol)r   r   r#   Znew_app_protor   r   r   test_set_new_app_protocol   s    
z0SslProtoHandshakeTests.test_set_new_app_protocolc                 C   s4   |   }| | |j}|  | |d d S Ns   data)r$   r,   r   r!   rL   data_receivedr   r#   Ztranspr   r   r    test_data_received_after_closing   s
    
z7SslProtoHandshakeTests.test_data_received_after_closingc                 C   s4   |   }| | |j}|  | |d d S rR   )r$   r,   r   r!   rL   writerT   r   r   r   test_write_after_closing   s
    
z/SslProtoHandshakeTests.test_write_after_closing)__name__
__module____qualname__r   r$   r,   r3   r4   r>   rD   rG   rJ   rO   rQ   rU   rW   __classcell__r   r   r   r   r      s   


r   c                   @   sv   e Zd ZdZejZdd Zdd Zdd Z	dd	 Z
d
d Zdd Zdd Zdd Zdd Zdd Zdd Zdd ZdS )BaseStartTLSi  c                 C   s   t d S r	   )NotImplementedErrorr   r   r   r   new_loop   s    zBaseStartTLS.new_loopc              	   C   s  G dd dt j}dD ]}|d|}t|d | |jd |d|}t|d | |jd |d|}t|d | |jd |d|}t|d | |jd |d	|}t|d | |jd |d
|}| td t|d W d    q1 s0    Y  qd S )Nc                   @   s$   e Zd Zdd Zdd Zdd ZdS )z.BaseStartTLS.test_buf_feed_data.<locals>.Protoc                 S   s&   t || _t| j| _d| _|| _d S Nr&   )	bytearraybuf
memoryviewmvdatausemv)r   bufsizere   r   r   r   __init__   s    
z7BaseStartTLS.test_buf_feed_data.<locals>.Proto.__init__c                 S   s   | j r| jS | jS d S r	   )re   rc   ra   r   sizehintr   r   r   
get_buffer   s    z9BaseStartTLS.test_buf_feed_data.<locals>.Proto.get_bufferc                 S   s<   | j r |  j| jd | 7  _n|  j| jd | 7  _d S r	   )re   rd   rc   ra   r   Znsizer   r   r   buffer_updated   s    z=BaseStartTLS.test_buf_feed_data.<locals>.Proto.buffer_updatedN)rX   rY   rZ   rg   rj   rl   r   r   r   r   Proto   s   rm   )FT   s   12345   s   1234   d   r   zempty buffer)r
   BufferedProtocolr   Z_feed_data_to_buffered_protoassertEqualrd   r0   RuntimeError)r   rm   re   r   r   r   r   test_buf_feed_data   s(    





zBaseStartTLS.test_buf_feed_datac                    s   dj  t t fdd}G fdddtj  fdd}j|jd.}j	tj
||jtjd W d    n1 s0    Y  tt    d S )	N   1c                    s   |  j | t }t|t  | jdd | d | t }t|t  | tj	 | 
  d S NTserver_side   O
settimeoutTIMEOUTrecv_alllenrs   	start_tlssendallr+   rK   	SHUT_RDWRr!   sockrd   	HELLO_MSGr   server_contextr   r   serve   s    
z=BaseStartTLS.test_start_tls_client_reg_proto_1.<locals>.servec                       s0   e Zd Zdd Z fddZdd Zdd Zd	S )
zCBaseStartTLS.test_start_tls_client_reg_proto_1.<locals>.ClientProtoc                 S   s   || _ || _d| _d S Nr   on_dataon_eofcon_made_cntr   r   r   r   r   r   rg      s    zLBaseStartTLS.test_start_tls_client_reg_proto_1.<locals>.ClientProto.__init__c                    s    |  j d7  _  | j d d S Nrn   r   rs   r   trr   r   r   r,      s    zSBaseStartTLS.test_start_tls_client_reg_proto_1.<locals>.ClientProto.connection_madec                 S   s   | j | d S r	   r   
set_resultr   rd   r   r   r   rS      s    zQBaseStartTLS.test_start_tls_client_reg_proto_1.<locals>.ClientProto.data_receivedc                 S   s   | j d d S NTr   r   r   r   r   r   r8      s    zPBaseStartTLS.test_start_tls_client_reg_proto_1.<locals>.ClientProto.eof_receivedNrX   rY   rZ   rg   r,   rS   r8   r   r   r   r   ClientProto   s   r   c                    s   t dI d H  j  j jj fddg| R  I d H \}}| j||I d H } I d H d | I d H  |  d S )N      ?c                      s
    S r	   r   r   r   r   r   r   r   <lambda>  r&   zPBaseStartTLS.test_start_tls_client_reg_proto_1.<locals>.client.<locals>.<lambda>rz   )	r
   sleepr   r7   create_connectionrV   r   rs   r!   )addrr   r   new_trr   r   client_contextr   r   r   r   client   s    




z>BaseStartTLS.test_start_tls_client_reg_proto_1.<locals>.clienttimeoutPAYLOAD_SIZEr   simple_server_sslcontextsimple_client_sslcontextr
   r   
tcp_serverr}   r   run_until_completewait_forr   r   SHORT_TIMEOUTweakrefref
gc_collectrL   r   r   r   srvr   r   r   r   r   r   r   !test_start_tls_client_reg_proto_1   s    
"
z.BaseStartTLS.test_start_tls_client_reg_proto_1c                    s   dj  t t fdd}G fdddtj  fdd}j|jd.}j	tj
||jtjd W d    n1 s0    Y  tt    d S )	Nrv   c                    s^   |  j | jdd | d | t }t|t  | tj	 | 
  d S rw   )r|   r}   r   r   r~   r   rs   r+   rK   r   r!   r   r   r   r   r   !  s    
z>BaseStartTLS.test_create_connection_memory_leak.<locals>.servec                       s0   e Zd Zdd Z fddZdd Zdd Zd	S )
zDBaseStartTLS.test_create_connection_memory_leak.<locals>.ClientProtoc                 S   s   || _ || _d| _d S r   r   r   r   r   r   rg   .  s    zMBaseStartTLS.test_create_connection_memory_leak.<locals>.ClientProto.__init__c                    s&   || _ |  jd7  _ | jd d S r   )r   r   rs   r   r   r   r   r,   3  s    zTBaseStartTLS.test_create_connection_memory_leak.<locals>.ClientProto.connection_madec                 S   s   | j | d S r	   r   r   r   r   r   rS   :  s    zRBaseStartTLS.test_create_connection_memory_leak.<locals>.ClientProto.data_receivedc                 S   s   | j d d S r   r   r   r   r   r   r8   =  s    zQBaseStartTLS.test_create_connection_memory_leak.<locals>.ClientProto.eof_receivedNr   r   r   r   r   r   -  s   r   c                    s   t dI d H  j  j jj fddg| R diI d H \}} I d H d | I d H  |  d S )Nr   c                      s
    S r	   r   r   r   r   r   r   G  r&   zQBaseStartTLS.test_create_connection_memory_leak.<locals>.client.<locals>.<lambda>sslrz   )r
   r   r   r7   r   rs   rV   r!   r   r   r   r   r   r   r   @  s    



z?BaseStartTLS.test_create_connection_memory_leak.<locals>.clientr   r   r   r   r   r   "test_create_connection_memory_leak  s    
"
z/BaseStartTLS.test_create_connection_memory_leakc                    s   dj  t t dfdd}G fdddtj G fdddtj fd	d
}j|jd.}j	
tj||jjd W d    n1 s0    Y  d S )Nrv   r   c                    s   |  j | t }t|t  | jdd | d | t }t|t  | d | t }t|t  | tj	 | 
  d S )NTrx   rz      2r{   r   r   r   r   r   b  s    

z=BaseStartTLS.test_start_tls_client_buf_proto_1.<locals>.servec                       s0   e Zd Zdd Z fddZdd Zdd Zd	S )
zHBaseStartTLS.test_start_tls_client_buf_proto_1.<locals>.ClientProtoFirstc                 S   s   || _ td| _d S r   )r   r`   ra   )r   r   r   r   r   rg   v  s    zQBaseStartTLS.test_start_tls_client_buf_proto_1.<locals>.ClientProtoFirst.__init__c                    s    d7  d S r   r   r   r   client_con_made_callsr   r   r,   z  s    zXBaseStartTLS.test_start_tls_client_buf_proto_1.<locals>.ClientProtoFirst.connection_madec                 S   s   | j S r	   )ra   rh   r   r   r   rj   ~  s    zSBaseStartTLS.test_start_tls_client_buf_proto_1.<locals>.ClientProtoFirst.get_bufferc                 S   s   | j t| jd |  d S r	   )r   r   bytesra   rk   r   r   r   rl     s    zWBaseStartTLS.test_start_tls_client_buf_proto_1.<locals>.ClientProtoFirst.buffer_updatedN)rX   rY   rZ   rg   r,   rj   rl   r   r   r   r   ClientProtoFirstu  s   r   c                       s0   e Zd Zdd Z fddZdd Zdd Zd	S )
zIBaseStartTLS.test_start_tls_client_buf_proto_1.<locals>.ClientProtoSecondc                 S   s   || _ || _d| _d S r   r   r   r   r   r   rg     s    zRBaseStartTLS.test_start_tls_client_buf_proto_1.<locals>.ClientProtoSecond.__init__c                    s    d7  d S r   r   r   r   r   r   r,     s    zYBaseStartTLS.test_start_tls_client_buf_proto_1.<locals>.ClientProtoSecond.connection_madec                 S   s   | j | d S r	   r   r   r   r   r   rS     s    zWBaseStartTLS.test_start_tls_client_buf_proto_1.<locals>.ClientProtoSecond.data_receivedc                 S   s   | j d d S r   r   r   r   r   r   r8     s    zVBaseStartTLS.test_start_tls_client_buf_proto_1.<locals>.ClientProtoSecond.eof_receivedNr   r   r   r   r   ClientProtoSecond  s   r   c                    s   t dI d H  j  j }j }jj fddg| R  I d H \}}| j||I d H } I d H d | ||| |I d H d | |I d H  |	  d d S )Nr   c                      s    S r	   r   r   )r   on_data1r   r   r     r&   zPBaseStartTLS.test_start_tls_client_buf_proto_1.<locals>.client.<locals>.<lambda>rz   r   rn   )
r
   r   r   r7   r   rV   r   rs   rP   r!   )r   Zon_data2r   r   r   r   )r   r   r   r   r   r   )r   r   r     s&    






z>BaseStartTLS.test_start_tls_client_buf_proto_1.<locals>.clientr   )r   r   r   r   r
   rr   r   r   r}   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   !test_start_tls_client_buf_proto_1[  s    
z.BaseStartTLS.test_start_tls_client_buf_proto_1c                    s   dj  t j fdd}G fdddtj  fdd}j|jd.}j	tj
||jtjd W d    n1 s0    Y  d S )	Nrv   c                    s|   |  j | t }t|t  z>zjjd  | d}W n ty`   Y n0 W | 	  n
| 	  0 d S N   )
r|   r}   r~   r   rs   r   Zcall_soon_threadsafer   rF   r!   r   )r   r   server_waits_on_handshaker   r   r     s    z=BaseStartTLS.test_start_tls_slow_client_cancel.<locals>.servec                       s0   e Zd Zdd Z fddZdd Zdd Zd	S )
zCBaseStartTLS.test_start_tls_slow_client_cancel.<locals>.ClientProtoc                 S   s   || _ || _d| _d S r   r   r   r   r   r   rg     s    zLBaseStartTLS.test_start_tls_slow_client_cancel.<locals>.ClientProto.__init__c                    s    |  j d7  _  | j d d S r   r   r   r   r   r   r,     s    zSBaseStartTLS.test_start_tls_slow_client_cancel.<locals>.ClientProto.connection_madec                 S   s   | j | d S r	   r   r   r   r   r   rS     s    zQBaseStartTLS.test_start_tls_slow_client_cancel.<locals>.ClientProto.data_receivedc                 S   s   | j d d S r   r   r   r   r   r   r8     s    zPBaseStartTLS.test_start_tls_slow_client_cancel.<locals>.ClientProto.eof_receivedNr   r   r   r   r   r     s   r   c                    s   t dI d H  j  j jj fddg| R  I d H \}}| I d H  t j. t j	||dI d H  W d    n1 s0    Y  d S )Nr   c                      s
    S r	   r   r   r   r   r   r     r&   zPBaseStartTLS.test_start_tls_slow_client_cancel.<locals>.client.<locals>.<lambda>)
r
   r   r   r7   r   rV   assertRaisesTimeoutErrorr   r   r   r   r   r   r   r   r   r   r     s    



z>BaseStartTLS.test_start_tls_slow_client_cancel.<locals>.clientr   )r   r   r   r   r7   r
   r   r   r}   r   r   r   r   r   r   r   r   r   !test_start_tls_slow_client_cancel  s    

z.BaseStartTLS.test_start_tls_slow_client_cancelc                    s   dj  d t t d  fddG fdddtj fdd fd	d
}j|  d S )Nrv   s   answerc                    sf   |  j | | | t}t|t |  |  | t |   d S r	   )	r|   r}   connectr~   r   rs   r   r   r!   )r   r   rd   )ANSWERr   answerr   r   r   r   r     s    


z4BaseStartTLS.test_start_tls_server_1.<locals>.clientc                       s8   e Zd Zdd Zdd Zdd Z fddZd	d
 ZdS )z9BaseStartTLS.test_start_tls_server_1.<locals>.ServerProtoc                 S   s"   || _ || _|| _d| _d | _d S r_   )on_conon_con_loston_got_hellord   r-   )r   r   r   r   r   r   r   rg   	  s
    zBBaseStartTLS.test_start_tls_server_1.<locals>.ServerProto.__init__c                 S   s   || _ | j| d S r	   )r-   r   r   r   r   r   r   r,     s    zIBaseStartTLS.test_start_tls_server_1.<locals>.ServerProto.connection_madec                 S   s
   || _ d S r	   )r-   r   r   r   r   replace_transport  s    zKBaseStartTLS.test_start_tls_server_1.<locals>.ServerProto.replace_transportc                    s0   |  j |7  _ t| j t kr,| jd  d S r	   )rd   r   r   r   r   r   r   r   rS     s    zGBaseStartTLS.test_start_tls_server_1.<locals>.ServerProto.data_receivedc                 S   s,   d | _ |d u r| jd  n| j| d S r	   )r-   r   r   set_exception)r   excr   r   r   rE     s    zIBaseStartTLS.test_start_tls_server_1.<locals>.ServerProto.connection_lostN)rX   rY   rZ   rg   r,   r   rS   rE   r   r   r   r   ServerProto  s
   r   c                    s   |I d H }|  | jd jj|| djdI d H }| | |I d H  |   |I d H  | j |  d S )Nr&   T)ry   r   )rV   rs   rd   r   r   r}   r   r!   )r   r   r   r   r   r   )r   r   r   r   r   r   main#  s    





z2BaseStartTLS.test_start_tls_server_1.<locals>.mainc                     s   j  } j  }j  }| ||j fddddI d H }|jd   j fddjd0 tj| ||jdI d H  W d    n1 s0    Y  |	  |
 I d H   d S )Nc                      s    S r	   r   r   )r   r   r   r   =  r&   zHBaseStartTLS.test_start_tls_server_1.<locals>.run_main.<locals>.<lambda>z	127.0.0.1r   c                    s
   |  S r	   r   r   )r   r   r   r   r   @  r&   r   )r   r7   create_serverZsocketsgetsocknameZ
tcp_clientr}   r
   r   r!   Zwait_closedrs   )r   r   r   server)r   r   r   r   r   r   )r   r   r   run_main6  s$    



*z6BaseStartTLS.test_start_tls_server_1.<locals>.run_main)r   r   r   r   r
   r   r   r   )r   r   r   )	r   r   r   r   r   r   r   r   r   r   test_start_tls_server_1  s    
z$BaseStartTLS.test_start_tls_server_1c                    s    fdd} j |  d S )Nc                     s     td&  jd d d I d H  W d    n1 s80    Y  t }   td&  jd d | I d H  W d    n1 s0    Y  d S )NzSSLContext, gotzis not supported)r0   	TypeErrorr   r   r   r   sslctxr   r   r   r   M  s
    4z4BaseStartTLS.test_start_tls_wrong_args.<locals>.main)r   r   )r   r   r   r   r   test_start_tls_wrong_argsL  s    z&BaseStartTLS.test_start_tls_wrong_argsc              	      s   t   g jfdd dfdd} fdd}j|ddd	N}tj" j||j	 W d    n1 s0    Y  W d    n1 s0    Y  
 g  t  t     d S )
Nc                    s
     |S r	   appendr   ctxmessagesr   r   r   ]  r&   z5BaseStartTLS.test_handshake_timeout.<locals>.<lambda>Fc                    sB   z2z|  d W n ty&   d Y n0 W |   n
|   0 d S )Nr   Tr~   rF   r!   r   )server_side_abortedr   r   r   a  s
    z3BaseStartTLS.test_handshake_timeout.<locals>.serverc                    s4   t jjt jg| R  dtjddI d H  d S )N )r   server_hostnamer   r   )r
   r   r   r   r   r   r   )r   client_sslctxr   r   r   r   j  s    z3BaseStartTLS.test_handshake_timeout.<locals>.clientrn   Zmax_clientsbacklog)r   r   r   set_exception_handlerr   r   r
   r   r   r   rH   rs   r   r   r   r   rL   r   r   r   r   r   )r   r   r   r   r   test_handshake_timeoutW  s$    	
N

z#BaseStartTLS.test_handshake_timeoutc              	      s   t   g jfdd dd } fdd}j|dddN}td	" j||j W d    n1 s|0    Y  W d    n1 s0    Y  	g  d S )
Nc                    s
     |S r	   r   r   r   r   r   r     r&   zHBaseStartTLS.test_create_connection_ssl_slow_handshake.<locals>.<lambda>c                 S   s>   z.z|  d W n ty"   Y n0 W |   n
|   0 d S r   r   r   r   r   r   r     s
    zFBaseStartTLS.test_create_connection_ssl_slow_handshake.<locals>.serverc                    sP    t2 tj|  djddI d H \}}W d    n1 sB0    Y  d S )Nr   g      ?r   r   r   r   )assertWarnsDeprecationWarningr
   open_connectionr   r   readerwriterr   r   r   r     s    zFBaseStartTLS.test_create_connection_ssl_slow_handshake.<locals>.clientrn   r   zSSL handshake.*is taking longer)
r   r   r   r   r   r0   rF   r   r   rs   r   r   )r   r   r   r   )test_create_connection_ssl_slow_handshake  s     	Nz6BaseStartTLS.test_create_connection_ssl_slow_handshakec              	      s   j dd  t tjdd fdd} fdd}j|d	d	d
N}tj" j 	||j
 W d    n1 s0    Y  W d    n1 s0    Y  d S )Nc                 S   s   d S r	   r   r   r   r   r   r     r&   zLBaseStartTLS.test_create_connection_ssl_failed_certificate.<locals>.<lambda>F)Zdisable_verifyc                    sT   zDz| j  dd W n$ tjy(   Y n ty8   Y n0 W |   n
|   0 d S )NTrx   )r   r   SSLErrorOSErrorr!   r   r   r   r   r     s    
zJBaseStartTLS.test_create_connection_ssl_failed_certificate.<locals>.serverc                    sR    t4 tj|  djtjdI d H \}}W d    n1 sD0    Y  d S )Nr   r   )r   r   r
   r   r   r   ZLOOPBACK_TIMEOUTr   r   r   r   r     s    zJBaseStartTLS.test_create_connection_ssl_failed_certificate.<locals>.clientrn   r   )r   r   r   r   r   r   r   r   ZSSLCertVerificationErrorr   r   r   r   r   r   r   r   -test_create_connection_ssl_failed_certificate  s    	z:BaseStartTLS.test_create_connection_ssl_failed_certificatec                    s   j dd  t t  fdd} fdd}j|ddd"}j ||j}W d    n1 sr0    Y  |d	 d S )
Nc                 S   s   d S r	   r   r   r   r   r   r     r&   zBBaseStartTLS.test_start_tls_client_corrupted_ssl.<locals>.<lambda>c                    sz   |   }zZz0| j dd | d | d |d W n tjyN   Y n0 W |  |   n|  |   0 d S )NTrx      A
rn   s!   please corrupt the SSL connection)dupr   r   r~   sendr   r   r!   )r   Z	orig_sockr   r   r   r     s    


z@BaseStartTLS.test_start_tls_client_corrupted_ssl.<locals>.serverc                    s    t0 tj|  djdI d H \}}W d    n1 s@0    Y  | I d H d |d t	j
 | I d H  W d    n1 s0    Y  |  dS )Nr   )r   r   r   r      BOK)r   r   r
   r   r   rs   readlinerV   r   r   r   r!   r   r   r   r   r     s    0
,z@BaseStartTLS.test_start_tls_client_corrupted_ssl.<locals>.clientrn   r   r   )	r   r   r   r   r   r   r   r   rs   )r   r   r   r   resr   r   r   #test_start_tls_client_corrupted_ssl  s    0z0BaseStartTLS.test_start_tls_client_corrupted_sslN)rX   rY   rZ   r   r   ZLONG_TIMEOUTr}   r^   ru   r   r   r   r   r   r   r   r   r   r  r   r   r   r   r\      s   /B@[=Y0##r\   c                   @   s   e Zd Zdd ZdS )SelectorStartTLSTestsc                 C   s   t  S r	   )r
   ZSelectorEventLoopr   r   r   r   r^     s    zSelectorStartTLSTests.new_loopNrX   rY   rZ   r^   r   r   r   r   r    s   r  ProactorEventLoopzWindows onlyc                   @   s   e Zd Zdd ZdS )ProactorStartTLSTestsc                 C   s   t  S r	   )r
   r  r   r   r   r   r^     s    zProactorStartTLSTests.new_loopNr  r   r   r   r   r    s   r  __main__)rB   rK   Zunittestr   r   r   ImportErrorr
   r   r   r   testr   Ztest.test_asyncior   r   r   Z
func_testsr   ZskipIfZTestCaser   ZFunctionalTestCaseMixinr\   r  Z
skipUnlesshasattrr  rX   r   r   r   r   r   <module>   s>   
     ]
