Your IP : 216.73.216.213


Current Path : /opt/alt/python36/lib64/python3.6/test/test_asyncio/__pycache__/
Upload File :
Current File : //opt/alt/python36/lib64/python3.6/test/test_asyncio/__pycache__/test_events.cpython-36.opt-1.pyc

3

� f
��@shdZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZyddl
Z
Wnek
rxdZ
YnXddlZddlZddlZddlZddlZddlZddlmZddlZej	dkr�ddlZddlZddlmZddlmZddlmZddlmZdd	lmZdd
lmZm Z m!Z!yddl"m#Z#Wn"ek
�rZddlm$Z#YnXd
d�Z%dd�Z&ej!d�Z'ej!d�Z(dTdUdVd]ddddfdhd$d%�
Z)Gd&d'�d'ej*�Z+Gd(d)�d)e+�Z,Gd*d+�d+ej-�Z.Gd,d-�d-ej*�Z/Gd.d/�d/ej0�Z1Gd0d1�d1ej2�Z3Gd2d3�d3�Z4Gd4d5�d5�Z5ej	dk�rXGd6d7�d7e4ej6�Z7Gd8d9�d9e4e5ej6�Z8n�dd:lm9Z9Gd;d<�d<e4�Z:e;e9d=��r�Gd>d?�d?e:e5ej6�Z<e;e9d@��r�GdAdB�dBe:e5ej6�Z=e;e9dC��r�GdDdE�dEe:e5ej6�Z>GdFd7�d7e:e5ej6�Z7dGdH�Z?GdIdJ�dJej6�Z@GdKdL�dLej6�ZAGdMdN�dNej6�ZBGdOdP�dPej6�ZCGdQdR�dRej6�ZDeEdSk�rdejF�dS)izTests for events.py.�N)�mock�win32)�
coroutines)�proactor_events)�selector_events)�sslproto)�
test_utils)�ONLYKEY�ONLYCERT�	data_file)�support)�test_supportcCs6tjdkrdStj�d}ttt|jd���}|dkS)z4Return True if the platform is Mac OS 10.4 or older.�darwinFr�.�
�)rr)�sys�platformZmac_ver�tuple�map�int�split)�version�r�B/opt/alt/python36/lib64/python3.6/test/test_asyncio/test_events.py�	osx_tiger*s

rcCs&dd�}tj�}tj|�|j|��S)Nc�sdS)N�hellorrrrr�doit4sz8_test_get_event_loop_new_process__sub_proc.<locals>.doit)�asyncio�new_event_loop�set_event_loop�run_until_complete)r�looprrr�*_test_get_event_loop_new_process__sub_proc3s
r#zkeycert3.pemzpycacert.pem�)http://testca.pythontest.net/testca/ocsp/�0http://testca.pythontest.net/testca/pycacert.cer�2http://testca.pythontest.net/testca/revocation.crl�countryName�XY�organizationName�Python Software Foundation CA�
commonName�
our-ca-serverzJul  7 14:23:16 2028 GMTzAug 29 14:23:16 2018 GMTZCB2D80995A69525C�localityName�Castle Anthrax�Python Software Foundation�	localhost�DNS�)
ZOCSPZ	caIssuersZcrlDistributionPointsZissuerZnotAfterZ	notBeforeZserialNumberZsubjectZsubjectAltNamerc@s>eZdZdZdZddd�Zdd�Zdd�Zdd	�Zd
d�Z	dS)
�MyBaseProtoNcCs:d|_d|_d|_|dk	r6tj|d�|_tj|d�|_dS)N�INITIALr)r")�	transport�state�nbytesr�Future�	connected�done)�selfr"rrr�__init__UszMyBaseProto.__init__cCs"||_d|_|jr|jjd�dS)N�	CONNECTED)r5r6r9�
set_result)r;r5rrr�connection_made]szMyBaseProto.connection_madecCs|jt|�7_dS)N)r7�len)r;�datarrr�
data_receiveddszMyBaseProto.data_receivedcCs
d|_dS)N�EOF)r6)r;rrr�eof_receivedhszMyBaseProto.eof_receivedcCsd|_|jr|jjd�dS)N�CLOSED)r6r:r>)r;�excrrr�connection_lostlszMyBaseProto.connection_lost)N)
�__name__�
__module__�__qualname__r9r:r<r?rBrDrGrrrrr3Qs
r3cseZdZ�fdd�Z�ZS)�MyProtocst�j|�|jd�dS)Ns%GET / HTTP/1.0
Host: example.com

)�superr?�write)r;r5)�	__class__rrr?tszMyProto.connection_made)rHrIrJr?�
__classcell__rr)rNrrKssrKc@s:eZdZdZddd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�MyDatagramProtoNcCs&d|_d|_|dk	r"tj|d�|_dS)Nr4r)r")r6r7rr8r:)r;r"rrrr<|szMyDatagramProto.__init__cCs||_d|_dS)N�INITIALIZED)r5r6)r;r5rrrr?�szMyDatagramProto.connection_madecCs|jt|�7_dS)N)r7r@)r;rA�addrrrr�datagram_received�sz!MyDatagramProto.datagram_receivedcCsdS)Nr)r;rFrrr�error_received�szMyDatagramProto.error_receivedcCsd|_|jr|jjd�dS)NrE)r6r:r>)r;rFrrrrG�szMyDatagramProto.connection_lost)N)	rHrIrJr:r<r?rSrTrGrrrrrPys
rPc@s:eZdZdZddd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�MyReadPipeProtoNcCs.dg|_d|_d|_|dk	r*tj|d�|_dS)Nr4r)r")r6r7r5rr8r:)r;r"rrrr<�s
zMyReadPipeProto.__init__cCs||_|jjd�dS)Nr=)r5r6�append)r;r5rrrr?�szMyReadPipeProto.connection_madecCs|jt|�7_dS)N)r7r@)r;rArrrrB�szMyReadPipeProto.data_receivedcCs|jjd�dS)NrC)r6rV)r;rrrrD�szMyReadPipeProto.eof_receivedcCs8d|jkr|jjd�|jjd�|jr4|jjd�dS)NrCrE)r6rVr:r>)r;rFrrrrG�s

zMyReadPipeProto.connection_lost)N)	rHrIrJr:r<r?rBrDrGrrrrrU�s
rUc@s*eZdZdZddd�Zdd�Zdd�ZdS)	�MyWritePipeProtoNcCs&d|_d|_|dk	r"tj|d�|_dS)Nr4)r")r6r5rr8r:)r;r"rrrr<�szMyWritePipeProto.__init__cCs||_d|_dS)Nr=)r5r6)r;r5rrrr?�sz MyWritePipeProto.connection_madecCsd|_|jr|jjd�dS)NrE)r6r:r>)r;rFrrrrG�sz MyWritePipeProto.connection_lost)N)rHrIrJr:r<r?rGrrrrrW�s
rWc@s<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�MySubprocessProtocolcsrd|_d|_tj�d�|_tj�d�|_�fdd�td�D�|_ddd�|_d|_	tj
�d�tj
�d�d�|_dS)Nr4)r"csi|]}tj�d�|�qS))r")rr8)�.0�fd)r"rr�
<dictcomp>�sz1MySubprocessProtocol.__init__.<locals>.<dictcomp>r2�)��)r6r5rr8r9�	completed�range�disconnectsrA�
returncodeZEvent�got_data)r;r"r)r"rr<�s
zMySubprocessProtocol.__init__cCs||_d|_|jjd�dS)Nr=)r5r6r9r>)r;r5rrrr?�sz$MySubprocessProtocol.connection_madecCsd|_|jjd�dS)NrE)r6r_r>)r;rFrrrrG�sz$MySubprocessProtocol.connection_lostcCs$|j||7<|j|j�dS)N)rArc�set)r;rZrArrr�pipe_data_received�sz'MySubprocessProtocol.pipe_data_receivedcCs*|r|j|j|�n|j|j|�dS)N)raZ
set_exceptionr>)r;rZrFrrr�pipe_connection_lost�sz)MySubprocessProtocol.pipe_connection_lostcCs|jj�|_dS)N)r5Zget_returncoderb)r;rrr�process_exited�sz#MySubprocessProtocol.process_exitedN)	rHrIrJr<r?rGrerfrgrrrrrX�srXcs�eZdZ�fdd�Z�fdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zejeed�d �d!d"��Zd#d$�Zd%d&�Zejeed'�d(�d)d*��Zejeed+�d,�d-d.��Zejeed+�d,�d/d0��Zd�d2d3�Zd4d5�Zejeed�d �d6d7��Zd8d9�Z d1d:ifd;d<�Z!d�d=d>�Z"d�d?d@�Z#ej$e%d:kdA�dBdC��Z&dDdE�Z'ej$e%d:kdA�ejeed�d �dFdG���Z(dHdI�Z)dJdK�Z*dLdM�Z+d�dNdO�Z,ej$e%d:kdA�dPdQ��Z-e.j/dR�dSdT��Z0dUdV�Z1dWdX�Z2dYdZ�Z3ejeed[�d\�d]d^��Z4d_d`�Z5ejeed�d �dadb��Z6ejeed�d �dcdd��Z7d�dedf�Z8d�dgdh�Z9d�didj�Z:ej$e%d:kdA�dkdl��Z;dmdn�Z<ej$e%d:kdA�ejeed�d �dodp���Z=dqdr�Z>ej$e%d:kdA�dsdt��Z?dudv�Z@ej$e%d:kdA�ejeed�d �dwdx���ZAdydz�ZBej$e%d:kdA�d{d|��ZCd}d~�ZDej$e%d:kdA�ejeed�d �dd����ZEd�d��ZFej$e%d:kdA�d�d���ZGd�d��ZHd�d��ZId�d��ZJejeKjLd��d�d���ZMd�d��ZNd�d��ZOd�d��ZPd�d��ZQejeRjSd�kd��d�d���ZTejeRjSd�kd��d�d���ZUejeRjSd�kd��eKjVd�d��eKjWd��d�d�����ZXejeRjSd�kd��d�d���ZYejeRjSd�kd��d�d���ZZejeRjSd�kd��eKjVd�d��d�d����Z[ejeRjSd�kd��eKjVd�d��d�d����Z\d�d��Z]d�d��Z^d�d��Z_d�d��Z`d�d��Zad�d��Zb�ZcS)��EventLoopTestsMixincs$t�j�|j�|_|j|j�dS)N)rL�setUp�create_event_loopr"r )r;)rNrrri�s

zEventLoopTestsMixin.setUpcs4|jj�stj|j�|j�tj�t�j�dS)N)	r"�	is_closedr�run_brieflyZ
doCleanupsrZ
gc_collectrL�tearDown)r;)rNrrrm�s

zEventLoopTestsMixin.tearDowncs:tjdd���tj��fdd��}�jt�jj|��dS)Ncss
dVdS)Nrrrrr�coro1szBEventLoopTestsMixin.test_run_until_complete_nesting.<locals>.coro1cs"�j�jj���jj���dS)N)�
assertTruer"�
is_runningr!r)rnr;rr�coro2szBEventLoopTestsMixin.test_run_until_complete_nesting.<locals>.coro2)r�	coroutine�assertRaises�RuntimeErrorr"r!)r;rqr)rnr;r�test_run_until_complete_nestingsz3EventLoopTestsMixin.test_run_until_complete_nestingcCsX|jj�}|jjtjd|jd��|jj�}|jd||koFdkn||�dS)Ng�������?)r"g{�G�z�?g�������?)r"�timer!r�sleepro)r;�t0�t1rrr�test_run_until_completes

z+EventLoopTestsMixin.test_run_until_completecs.tj�fdd��}|�}�jt�jj|�dS)Nc3s$�jj�tjd�jd�EdHdS)Ng�������?)r")r"�stoprrwr)r;rr�cbs
z?EventLoopTestsMixin.test_run_until_complete_stopped.<locals>.cb)rrrrsrtr"r!)r;r|Ztaskr)r;r�test_run_until_complete_stoppedsz3EventLoopTestsMixin.test_run_until_complete_stoppedcsvg���fdd�}�jjd|d�tj�}�jj�tj�}�j�dg��jd||koddkn||�dS)Ncs�j|��jj�dS)N)rVr"r{)�arg)�resultsr;rr�callback%s
z5EventLoopTestsMixin.test_call_later.<locals>.callbackg�������?zhello worldg{�G�z�?g�������?)r"�
call_laterrv�	monotonic�run_forever�assertEqualro)r;r�rxryr)rr;r�test_call_later"s
z#EventLoopTestsMixin.test_call_latercs>g���fdd�}�jj|dd��jj��j�dg�dS)Ncs�j||f��jj�dS)N)rVr"r{)Zarg1Zarg2)rr;rrr�3sz4EventLoopTestsMixin.test_call_soon.<locals>.callbackr�world)rr�)r"�	call_soonr�r�)r;r�r)rr;r�test_call_soon0s

z"EventLoopTestsMixin.test_call_sooncs�g�tj����fdd�����fdd�}�j�tj|d�}|j����jj�d��jj�WdQRX|j��j	�ddg�dS)Ncs$�j|�t��dkr �jj�dS)Nr^)rVr@r"r{)r~)rr;rrr�?s
z?EventLoopTestsMixin.test_call_soon_threadsafe.<locals>.callbackcs�jj�d��j�dS)Nr)r"�call_soon_threadsafe�releaser)r��lockr;rr�
run_in_threadDszDEventLoopTestsMixin.test_call_soon_threadsafe.<locals>.run_in_thread)�targetr�r)
�	threadingZLock�acquire�Thread�startr"r�r��joinr�)r;r��tr)r�r�rr;r�test_call_soon_threadsafe;sz-EventLoopTestsMixin.test_call_soon_threadsafecsLg���fdd�}�jj|d��jj|d��jj��j�ddg�dS)Ncs$�j|�t��dkr �jj�dS)Nr^)rVr@r"r{)r~)rr;rrr�Us
zKEventLoopTestsMixin.test_call_soon_threadsafe_same_thread.<locals>.callbackrr�)r"r�r�r�r�)r;r�r)rr;r�%test_call_soon_threadsafe_same_threadRs
z9EventLoopTestsMixin.test_call_soon_threadsafe_same_threadcCsHdd�}|jjd|d�}|jj|�\}}|j|d�|j|tj��dS)NcSs|tj�fS)N)r��	get_ident)r~rrr�run`sz5EventLoopTestsMixin.test_run_in_executor.<locals>.runZyo)r"�run_in_executorr!r�ZassertNotEqualr�r�)r;r��f2�resZ	thread_idrrr�test_run_in_executor_s
z(EventLoopTestsMixin.test_run_in_executorcs`d��fdd�}dd�}|jjd|�}|j�|jj�||j_||j_tjd�|j��dS)NFcsd�dS)NTr)�args)�calledrr�patched_call_soonjszJEventLoopTestsMixin.test_run_in_executor_cancel.<locals>.patched_call_sooncSstjd�dS)Ng�������?)rvrwrrrrr�nsz<EventLoopTestsMixin.test_run_in_executor_cancel.<locals>.rung�������?)	r"r��cancel�closer�r�rvrw�assertFalse)r;r�r�r�r)r�r�test_run_in_executor_cancelgs

z/EventLoopTestsMixin.test_run_in_executor_cancelcs�tj�\�}�jd�t�����fdd�}�jj�j�|��jj|jd�tj	�j�fdd���jj|jd�tj	�j�fdd���jj|j
��jj�jj��jj��j
�d	�dS)
NFcsVy�jd�}Wntk
r"dSX|r4�j|�n�j�jj�j����j�dS)Ni)�recv�BlockingIOError�extendror"�
remove_reader�filenor�)rA)�
bytes_read�rr;rr�reader~sz8EventLoopTestsMixin.test_reader_callback.<locals>.readersabccst��dkS)Nr2)r@r)r�rr�<lambda>�sz:EventLoopTestsMixin.test_reader_callback.<locals>.<lambda>sdefcst��dkS)N�)r@r)r�rrr��ssabcdef)r�
socketpair�setblocking�	bytearrayr"�
add_readerr�r��send�	run_untilr�r{r�r�)r;�wr�r)r�r�r;r�test_reader_callbackys


z(EventLoopTestsMixin.test_reader_callbackcs�tj�\}��jd���fdd�}dd}�jj�j�||��jj��j�jj�j����j	�jj�j����j
�|jt|�d�}|j
��j
||�dS)NFcs�j|��jj�dS)N)r�r"r{)rA)r;r�rr�writer�s
z8EventLoopTestsMixin.test_writer_callback.<locals>.writer�xir^)rr�r�r"�
add_writerr�r�ro�
remove_writerr�r�r�r@r�)r;r�r�rA�readr)r;r�r�test_writer_callback�s

z(EventLoopTestsMixin.test_writer_callbackc CsTt|jtj�s�|jjd�|jd�|jt��|jj|jj	||j
��WdQRX|jt��|jj|jj|d��WdQRX|jt��|jj|jj|d��WdQRX|jt��|jj|jj
|��WdQRX|jd�|jj|jj	||j
��|jj|jj|d��|jj|jj|d��}|jj|jj|d��|j�|j|jd��dS)NTsGET / HTTP/1.0

iFsHTTP/1.0 200 OK)�
isinstancer"r�BaseProactorEventLoop�	set_debugr�rs�
ValueErrorr!�sock_connect�address�sock_sendall�	sock_recv�sock_acceptr�ro�
startswith)r;�httpd�sockrArrr�_basetest_sock_client_ops�s4

z-EventLoopTestsMixin._basetest_sock_client_opsc
Cs,tj��}tj�}|j||�WdQRXdS)N)r�run_test_server�socketr�)r;r�r�rrr�test_sock_client_ops�s
z(EventLoopTestsMixin.test_sock_client_ops�AF_UNIXzNo UNIX Socketsc
Cs0tj��}tjtj�}|j||�WdQRXdS)N)r�run_test_unix_serverr�r�r�)r;r�r�rrr�test_unix_sock_client_ops�s
z-EventLoopTestsMixin.test_unix_sock_client_opscCsxd}ztj�}|jd�|j�}Wd|j�Xtj�}|jd�|jt��|jj|jj	||��WdQRX|j�dS)N�	127.0.0.1rF)r�r)
r��bind�getsocknamer�r�rs�ConnectionRefusedErrorr"r!r�)r;r��sr�rrr�test_sock_client_fail�s


z)EventLoopTestsMixin.test_sock_client_failcCs�tj�}|jd�|jd�|jd�tj�}|j|j��|jj|�}|jj|�\}}|j	|j
�d�|j	||j��|j	|j�|j��|j�|j�|j�dS)NF�	127.0.0.1rr])r�r)
r�r�r��listen�connectr�r"r�r!r�Z
gettimeoutZgetpeernamer�)r;Zlistener�client�f�connrRrrr�test_sock_accept�s


z$EventLoopTestsMixin.test_sock_accept�SIGKILLz
No SIGKILLcsXd��fdd�}|jt|jjd|�|jt|jjd�|jt|jjtjd|�|jt|jjtjd�|jt|jjd|�|jt|jjd�|jt|jjd|�|jt|jjd	�|jt|jjtj	|�|j
|jjtj	��|jjtj|�tj
tj�tj�tj|j�fdd��|j|jjtj��|jtjtj�tj�|j
|jjtj��dS)
Nrcs�d7�dS)Nr]rr)�caughtrr�
my_handler�sz?EventLoopTestsMixin.test_add_signal_handler.<locals>.my_handlerZboomr]cs�S)Nrr)r�rrr�sz=EventLoopTestsMixin.test_add_signal_handler.<locals>.<lambda>���r�)rs�	TypeErrorr"�add_signal_handler�remove_signal_handlerr��signal�NSIGrtr�r��SIGINT�os�kill�getpidrr�ror��	getsignal�default_int_handler)r;r�r)r�r�test_add_signal_handler�s<z+EventLoopTestsMixin.test_add_signal_handler�SIGALRMz
No SIGALRMcs^d���fdd�}�jjtj|�tjtjdd��jjd�jj��jj��j	�d�dS)Nrcs�d7��jj�dS)Nr])r"r{r)r�r;rrr�(szLEventLoopTestsMixin.test_signal_handling_while_selecting.<locals>.my_handlerg{�G�z�?�<r])
r"r�r�r��	setitimer�ITIMER_REALr�r{r�r�)r;r�r)r�r;r�$test_signal_handling_while_selecting#s
z8EventLoopTestsMixin.test_signal_handling_while_selectingcsjd�d����fdd�}�jjtj|f���tjtjdd��jjd�jj��jj��j	�d�dS)	N�*rcs"�d7��j|���jj�dS)Nr])r�r"r{)r�)r�r;�	some_argsrrr�9szAEventLoopTestsMixin.test_signal_handling_args.<locals>.my_handlerg�������?r�r])r�)
r"r�r�r�r�r�r�r{r�r�)r;r�r)r�r;r�r�test_signal_handling_args4s
z-EventLoopTestsMixin.test_signal_handling_argsTcCsv|jj|�\}}|j|tj�|j|tj�|j|j|�|rN|j|j	d��|jj|j
�|j|jd�|j
�dS)N�socknamer)r"r!�assertIsInstancer�	Transport�Protocol�assertIsr5�assertIsNotNone�get_extra_infor:�
assertGreaterr7r�)r;�connection_fut�check_sockname�tr�prrrr�_basetest_create_connectionFsz/EventLoopTestsMixin._basetest_create_connectioncs>tj��,}�jj�fdd�f|j��}�j|�WdQRXdS)Ncst�jd�S)N)r")rKr"r)r;rrr�Tsz<EventLoopTestsMixin.test_create_connection.<locals>.<lambda>)rr�r"�create_connectionr�r�)r;r��conn_futr)r;r�test_create_connectionQs
z*EventLoopTestsMixin.test_create_connectioncsDt�}tj��*}�jj�fdd�|j�}�j||�WdQRXdS)Ncst�jd�S)N)r")rKr"r)r;rrr�_szAEventLoopTestsMixin.test_create_unix_connection.<locals>.<lambda>)rrr�r"�create_unix_connectionr�r�)r;r�r�rr)r;r�test_create_unix_connectionWs

z/EventLoopTestsMixin.test_create_unix_connectioncs�tj���}d}�jj�jj|jdtji��}xZ|D]R\}}}}}y4tj|||d�}|jd��jj�jj	||��WnYq2XPq2W�jj
�fdd�|d�}	�jj|	�\}
}�j|
tj
��j|tj��jj|j��j|jd�|
j�WdQRXdS)N�type)�familyr�protoFcst�jd�S)N)r")rKr"r)r;rrr�vszAEventLoopTestsMixin.test_create_connection_sock.<locals>.<lambda>)r�r)rr�r"r!�getaddrinfor�r��SOCK_STREAMr�r�rr�rr�r�r:r�r7r�)r;r�r��infosrrr�cnamer�r�r�r�r)r;r�test_create_connection_sockbs,

z/EventLoopTestsMixin.test_create_connection_sockNcCs|r|j|jd��|r,|j||jd��n|j|jd��|j||jd��|jd�}|j|t�|jt|�d|�|j|dt�|j|dt�|j|dt�|jd	�}|j|�|j|j�|jd
��|j|j	�|jd��|j|j
�|jd��|j|j�|jd
��dS)Nr��peername�peercert�cipherr2rr]r^Z
ssl_object�compression)r�r�r�r�rr@�strrrrZgetpeercert)r;r�r�r
rrZsslobjrrr�check_ssl_extra_info~s0






z(EventLoopTestsMixin.check_ssl_extra_infocCsx|jj|�\}}|j|tj�|j|tj�|jd|jjj	�k�|j
|||�|jj|j�|j|j
d�|j�dS)N�sslr)r"r!r�rr�r�rorNrH�lowerrr:r�r7r�)r;r�r�r
r�r�rrr�_basetest_create_ssl_connection�sz3EventLoopTestsMixin._basetest_create_ssl_connectionc	s�|tj�d�}�j|||�ttd�r�tjjfdddd��fdd�}tjd|d��,}|dd�}�j|||��j	|j
d	�WdQRX�jtj��2}|dd�}tj
���j|||�WdQRXWdQRX�j	|jjd
�dS)N)r�Purpose)�cafile�capath�cadatacs�j|tjj�tj�S)z�
                A ssl.create_default_context() replacement that doesn't enable
                cert validation.
                )r�rr�SERVER_AUTHr�dummy_ssl_context)Zpurposerrr)r;rr�_dummy_ssl_create_context�szREventLoopTestsMixin._test_create_ssl_connection.<locals>._dummy_ssl_create_contextzssl.create_default_context)�side_effectTr]ZCERTIFICATE_VERIFY_FAILED)rrr�hasattrrrrr�patchr�Z
call_countrs�SSLError�disable_logger�	exception�reason)	r;r�rr�r
rr�m�cmr)r;r�_test_create_ssl_connection�s&
	



z/EventLoopTestsMixin._test_create_ssl_connectionz
No ssl modulecsNtjdd��8}tj�jj�fdd�f|j��}�j|||jd�WdQRXdS)NT)�use_sslcst�jd�S)N)r")rKr"r)r;rrr��sz@EventLoopTestsMixin.test_create_ssl_connection.<locals>.<lambda>)r
)rr��	functools�partialr"rr�r&)r;r�rr)r;r�test_create_ssl_connection�s
z.EventLoopTestsMixin.test_create_ssl_connectionc	Cs tj��|j�WdQRXdS)N)r�force_legacy_ssl_supportr*)r;rrr�!test_legacy_create_ssl_connection�s
z5EventLoopTestsMixin.test_legacy_create_ssl_connectionc
sXt�}tjdd��:}tj�jj�fdd�|jdd�}�j||||jd�WdQRXdS)NT)r'cst�jd�S)N)r")rKr"r)r;rrr��szEEventLoopTestsMixin.test_create_ssl_unix_connection.<locals>.<lambda>z	127.0.0.1)�server_hostname)r
)	rrr�r(r)r"rr�r&)r;r�r�rr)r;r�test_create_ssl_unix_connection�sz3EventLoopTestsMixin.test_create_ssl_unix_connectionc	Cs tj��|j�WdQRXdS)N)rr+r.)r;rrr�&test_legacy_create_ssl_unix_connection�s
z:EventLoopTestsMixin.test_legacy_create_ssl_unix_connectioncs�tj��n}tj�}�jj�fdd�f|j�d|jd|fi�}�jj|�\}}|jj	d�d}�j
||�|j�WdQRXdS)Ncst�jd�S)N)r")rKr"r)r;rrr��szGEventLoopTestsMixin.test_create_connection_local_addr.<locals>.<lambda>�
local_addrrr�r])rr�r�find_unused_portr"rr�r!r5r�r�r�)r;r��portr�r�r�Zexpectedr)r;r�!test_create_connection_local_addr�s
z5EventLoopTestsMixin.test_create_connection_local_addrcs�tj��t}�jj�fdd�f|j�d|ji�}�jt��}�jj|�WdQRX�j|j	j
t
j��jt
|j�|j	j�WdQRXdS)Ncst�jd�S)N)r")rKr"r)r;rrr�szNEventLoopTestsMixin.test_create_connection_local_addr_in_use.<locals>.<lambda>r0)rr�r"rr�rs�OSErrorr!r�r"�errno�
EADDRINUSE�assertInr�strerror)r;r�r�r%r)r;r�(test_create_connection_local_addr_in_use�s
z<EventLoopTestsMixin.test_create_connection_local_addr_in_usec	s|j�G��fdd�dt�}tj�}|jd�|jd�|j��d�d�d�����fdd	�}tj|d
d�}|j�|j	�\}}|�d����_�j
�j�fd
d�||d���j��j
j�|j�|jd�|j|j��|j�jd�|j�jt���|j���dS)Ncs,eZdZ��fdd�Z��fdd�Z�ZS)zAEventLoopTestsMixin.test_connect_accepted_socket.<locals>.MyProtocst�j|��j�j�dS)N)rLrGr�r{)r;rF)rNr"rrrGszQEventLoopTestsMixin.test_connect_accepted_socket.<locals>.MyProto.connection_lostcst�j|�|jj��dS)N)rLrBr5rM)r;rA)rN�expected_responserrrBszOEventLoopTestsMixin.test_connect_accepted_socket.<locals>.MyProto.data_received)rHrIrJrGrBrOr)r:r")rNrrK
srK�	127.0.0.1rr]s	test datasrogercsvyDtj�}�dk	r�j|�}|j��|j��|jd��|j�Wn,tk
rp}ztd|�WYdd}~XnXdS)N�cz8Failure in client thread in test_connect_accepted_socket)r�Zwrap_socketr��sendallr�r��	Exception�print)ZcsockrF)rR�
client_ssl�message�responserrr�s



z@EventLoopTestsMixin.test_connect_accepted_socket.<locals>.clientT)r�Zdaemon)r"cs�S)Nrr)rrrr�4szBEventLoopTestsMixin.test_connect_accepted_socket.<locals>.<lambda>)rrE)r;r)r"r3r�r�r�r�r�r�r�Zacceptr!Zconnect_accepted_socketr�r5r�r�r�Zis_aliver�r6r7r@)	r;Z
server_sslr@rKZlsockr�Zthreadr��_r)rRr@r:r"rArrBr�test_connect_accepted_sockets4





z0EventLoopTestsMixin.test_connect_accepted_socketcCs�tjdkr,tjdkr,t|jtj�r,tjd��t	j
t	j�}|jt
t�t|d�rTd|_t	j|_t	j
t	j�}t|d�rxd|_t	j|_|j||�dS)Nrr2rz=SSL not supported with proactor event loops before Python 3.5�check_hostnameF)r2r)rr�version_infor�r"rr��unittest�SkipTestr�
SSLContext�PROTOCOL_SSLv23�load_cert_chainr
r	rrEZ	CERT_NONE�verify_moderD)r;Zserver_contextZclient_contextrrr� test_ssl_connect_accepted_socket?s



z4EventLoopTestsMixin.test_ssl_connect_accepted_socketzasyncio.base_events.socketc	s�tj�fdd�����fdd�}t|�}�tjkrJdd�|D�|j�j_ndd�|D�|j�j_|�j_t	j
��j_t	j
��j_�jj
�fdd	�|d
�}�jj|�}�j|j�dd�|jD�}�j||�dS)
Ncs>�tjkr �tjdd||ffgS�tjdd||ddffgSdS)Nr��r)r��AF_INETr	)�hostr2r��kw)rrrrXs
zEEventLoopTestsMixin.create_server_multiple_hosts.<locals>.getaddrinfocstj�||��jd�S)N)r")r�Taskr")r��kwds)rr;rr�getaddrinfo_task_szJEventLoopTestsMixin.create_server_multiple_hosts.<locals>.getaddrinfo_taskcSsg|]}|df�qS)�Pr)rYrPrrr�
<listcomp>fszDEventLoopTestsMixin.create_server_multiple_hosts.<locals>.<listcomp>cSsg|]}|dddf�qS)rUrr)rYrPrrrrViscs
t�j�S)N)rKr"r)r;rrr�mszBEventLoopTestsMixin.create_server_multiple_hosts.<locals>.<lambda>rUcSsh|]}|j�d�qS)r)�
getsockbyname)rYr�rrr�	<setcomp>pszCEventLoopTestsMixin.create_server_multiple_hosts.<locals>.<setcomp>)rrrrdr�rOrWrr"rr�MockZ_start_serving�
_stop_serving�
create_serverr!�
addCleanupr��socketsr�)	r;rZhostsZ	mock_sockrTZunique_hostsr��serverZserver_hostsr)rrr;r�create_server_multiple_hostsVs
z0EventLoopTestsMixin.create_server_multiple_hostscCs|jtjdddg�dS)Nz1.2.3.4z5.6.7.8)r_r�rO)r;rrr�&test_create_server_multiple_hosts_ipv4ssz:EventLoopTestsMixin.test_create_server_multiple_hosts_ipv4cCs|jtjdddg�dS)Nz::1z::2)r_r��AF_INET6)r;rrr�&test_create_server_multiple_hosts_ipv6wsz:EventLoopTestsMixin.test_create_server_multiple_hosts_ipv6cs&t|j��|jj�fdd�dd�}|jj|�}|jt|j�d�|jd}|j�\}}|j|d�tj�}|j	d|f�|j
d�|jj�j�|jd�j�t
j|j�fd	d��|jd
�j�|j�jjd��|jd�jjd�d��jj�|jj�j�|jd
�j�|j�|j�dS)Ncs�S)Nrr)rrrr�}sz8EventLoopTestsMixin.test_create_server.<locals>.<lambda>z0.0.0.0rr]z	127.0.0.1sxxxr=cs
�jdkS)Nr)r7r)rrrr��sr2r�r
rE)rKr"r[r!r�r@r]r�r�r�r=r9r6rr�r7r�r5r�r�r:)r;r�r^r�rPr2r�r)rr�test_create_server{s,



z&EventLoopTestsMixin.test_create_server�SO_REUSEPORTzNo SO_REUSEPORTcs�t|j��|jj�fdd�dd�}|jj|�}|jt|j�d�|jd}|j|jt	j
t	j��|j�t
j|j�t|j��|jj�fdd�dddd�}|jj|�}|jt|j�d�|jd}|j|jt	j
t	j��|j�dS)	Ncs�S)Nrr)rrrr��szCEventLoopTestsMixin.test_create_server_reuse_port.<locals>.<lambda>z0.0.0.0rr]cs�S)Nrr)rrrr��sT)Z
reuse_port)rKr"r[r!r�r@r]r�Z
getsockoptr��
SOL_SOCKETrdr�rrlro)r;r�r^r�r)rr�test_create_server_reuse_port�s*



z1EventLoopTestsMixin.test_create_server_reuse_portcs@tj��|j�fdd��|jj|�f|�}|jj|�}|�fS)Ncstjj��otj��S)N)r��path�exists�unlinkr)rgrrr��sz7EventLoopTestsMixin._make_unix_server.<locals>.<lambda>)rZgen_unix_socket_pathr\r"�create_unix_serverr!)r;�factory�kwargsr�r^r)rgr�_make_unix_server�s
z%EventLoopTestsMixin._make_unix_servercs�t|jd��|j�fdd��\}}|jt|j�d�tjtj�}|j|�|j	d�|jj
�j�|jd�j�t
j|j�fdd��|jd�j��jj�|jj
�j�|jd	�j�|j�|j�dS)
N)r"cs�S)Nrr)rrrr��sz=EventLoopTestsMixin.test_create_unix_server.<locals>.<lambda>r]sxxxr=cs
�jdkS)Nr)r7r)rrrr��sr2rE)rKr"rmr�r@r]r�r�r�r=r!r9r6rr�r7r5r�r:)r;r^rgr�r)rr�test_create_unix_server�s


z+EventLoopTestsMixin.test_create_unix_servercsft|jd��tj�}|�D|jj�fdd�d|d�}|jtd��|jj|�WdQRXWdQRXdS)N)r"cs�S)Nrr)rrrr��szOEventLoopTestsMixin.test_create_unix_server_path_socket_error.<locals>.<lambda>z/test)r�z3path and sock can not be specified at the same time)rKr"r�rj�assertRaisesRegexr�r!)r;r�r�r)rr�)test_create_unix_server_path_socket_error�sz=EventLoopTestsMixin.test_create_unix_server_path_socket_errorcCs,tjtj�}|jtjO_|j||�|S)N)rrIrJ�options�OP_NO_SSLv2rK)r;�certfile�keyfile�
sslcontextrrr�_create_ssl_context�sz'EventLoopTestsMixin._create_ssl_contextc
CsX|j||�}|jj|dd|d�}|jj|�}|jd}|j�\}}	|j|d�|||	fS)Nz	127.0.0.1r)r)rvr"r[r!r]r�r�)
r;rkrsrtrur�r^r�rPr2rrr�_make_ssl_server�s
z$EventLoopTestsMixin._make_ssl_servercCs|j||�}|j||d�S)N)r)rvrm)r;rkrsrtrurrr�_make_ssl_unix_server�sz)EventLoopTestsMixin._make_ssl_unix_servercs�t|jd��|j�fdd�tt�\}}}|jjt||tj�d�}|jj	|�\}}|j
d�|jj	�j�|jd�j
�tj|j�fdd��|jd�j�|j|||fd	��jj�|jj	�j�|jd
�j
�|j�|j�dS)N)r"cs�S)Nrr)rrrr�sz<EventLoopTestsMixin.test_create_server_ssl.<locals>.<lambda>)rsxxxr=cs
�jdkS)Nr)r7r)rrrr�sr2)r
rE)rKr"rwr
r	rr3rrr!rMr9r�r6r�r7rr5r�r:)r;r^rPr2�f_cr�r�r)rr�test_create_server_ssl�s"

z*EventLoopTestsMixin.test_create_server_sslc	Cs tj��|j�WdQRXdS)N)rr+rz)r;rrr�test_legacy_create_server_ssls
z1EventLoopTestsMixin.test_legacy_create_server_sslcs�t|jd��|j�fdd�tt�\}}|jjt|tj�dd�}|jj	|�\}}|j
d�|jj	�j�|jd�j
�tj|j�fdd��|jd	�j��jj�|jj	�j�|jd
�j
�|j�|j�dS)N)r"cs�S)Nrr)rrrr�'szAEventLoopTestsMixin.test_create_unix_server_ssl.<locals>.<lambda>rN)rr-sxxxr=cs
�jdkS)Nr)r7r)rrrr�2sr2rE)rKr"rxr
r	rr3rrr!rMr9r�r6r�r7r5r�r:)r;r^rgryr�r�r)rr�test_create_unix_server_ssl"s"


z/EventLoopTestsMixin.test_create_unix_server_sslc	Cs tj��|j�WdQRXdS)N)rr+r|)r;rrr�"test_legacy_create_unix_server_sslAs
z6EventLoopTestsMixin.test_legacy_create_unix_server_sslcs�t|jd��|j�fdd�t�\}}}tjtj�}|jtjO_tj	|_
t|d�rZd|_|jj
t|||d�}tjj|jd��Ltj��,|jtjd��|jj|�WdQRXWdQRXtj|j�WdQRX|j�j�|j�dS)	N)r"cs�S)Nrr)rrrr�IszJEventLoopTestsMixin.test_create_server_ssl_verify_failed.<locals>.<lambda>rET)r�call_exception_handlerz(?i)certificate.verify.failed)rKr"rw�SIGNED_CERTFILErrIrJrqrr�
CERT_REQUIREDrLrrErrr�objectrr!ror r!rl�assertIsNoner5r�)r;r^rPr2�sslcontext_clientryr)rr�$test_create_server_ssl_verify_failedEs$

 z8EventLoopTestsMixin.test_create_server_ssl_verify_failedc	Cs tj��|j�WdQRXdS)N)rr+r�)r;rrr�+test_legacy_create_server_ssl_verify_failedbs
z?EventLoopTestsMixin.test_legacy_create_server_ssl_verify_failedcs�t|jd��|j�fdd�t�\}}tjtj�}|jtjO_tj	|_
t|d�rXd|_|jj
t||dd�}tjj|jd��Ltj��,|jtjd	��|jj|�WdQRXWdQRXtj|j�WdQRX|j�j�|j�dS)
N)r"cs�S)Nrr)rrrr�kszOEventLoopTestsMixin.test_create_unix_server_ssl_verify_failed.<locals>.<lambda>rETZinvalid)rr-r~z(?i)certificate.verify.failed)rKr"rxrrrIrJrqrrr�rLrrErrrr�rr!ror r!rlr�r5r�)r;r^rgr�ryr)rr�)test_create_unix_server_ssl_verify_failedfs&


 z=EventLoopTestsMixin.test_create_unix_server_ssl_verify_failedc	Cs tj��|j�WdQRXdS)N)rr+r�)r;rrr�0test_legacy_create_unix_server_ssl_verify_failed�s
zDEventLoopTestsMixin.test_legacy_create_unix_server_ssl_verify_failedcs�t|jd��|j�fdd�t�\}}}tjtj�}|jtjO_tj	|_
|jtd�t
|d�rfd|_|jjt|||d�}tjj|jd��@tj��,|jtjd	��|jj|�WdQRXWdQRXWdQRX�jdk	r�jj�|j�dS)
N)r"cs�S)Nrr)rrrr��szIEventLoopTestsMixin.test_create_server_ssl_match_failed.<locals>.<lambda>)rrET)rr~z.hostname '127.0.0.1' doesn't match 'localhost')rKr"rwrrrIrJrqrrr�rL�load_verify_locations�
SIGNING_CArrErrrr�rr!roZCertificateErrorr!r5r�)r;r^rPr2r�ryr)rr�#test_create_server_ssl_match_failed�s*

*

z7EventLoopTestsMixin.test_create_server_ssl_match_failedc	Cs tj��|j�WdQRXdS)N)rr+r�)r;rrr�*test_legacy_create_server_ssl_match_failed�s
z>EventLoopTestsMixin.test_legacy_create_server_ssl_match_failedcs�t|jd��|j�fdd�t�\}}tjtj�}|jtjO_tj	|_
|jtd�t
|d�rdd|_|jjt||dd�}|jj|�\}}�jj�|j�|j�|jj�j�dS)	N)r"cs�S)Nrr)rrrr��szJEventLoopTestsMixin.test_create_unix_server_ssl_verified.<locals>.<lambda>)rrETr0)rr-)rKr"rxrrrIrJrqrrr�rLr�r�rrErr!r5r�r:)r;r^rgr�ryr�r�r)rr�$test_create_unix_server_ssl_verified�s"


z8EventLoopTestsMixin.test_create_unix_server_ssl_verifiedc	Cs tj��|j�WdQRXdS)N)rr+r�)r;rrr�+test_legacy_create_unix_server_ssl_verified�s
z?EventLoopTestsMixin.test_legacy_create_unix_server_ssl_verifiedcs�t|jd��|j�fdd�t�\}}}tjtj�}|jtjO_tj	|_
|jtd�t
|d�rfd|_|jjt|||dd�}|jj|�\}}|j|||ftd	��jj�|j�|j�|jj�j�dS)
N)r"cs�S)Nrr)rrrr��szEEventLoopTestsMixin.test_create_server_ssl_verified.<locals>.<lambda>)rrETr0)rr-)r
r)rKr"rwrrrIrJrqrrr�rLr�r�rrErr!r�PEERCERTr5r�r:)r;r^rPr2r�ryr�r�r)rr�test_create_server_ssl_verified�s&

z3EventLoopTestsMixin.test_create_server_ssl_verifiedc	Cs tj��|j�WdQRXdS)N)rr+r�)r;rrr�&test_legacy_create_server_ssl_verified�s
z:EventLoopTestsMixin.test_legacy_create_server_ssl_verifiedc	s�tj|jd��G�fdd�dt�}tjtjd�}|jtjtjd�|j	d�|jj
||d�}|jj|�}|jd}|j
||�|j�\}}|j|d�tj�}|jd	|f�|jd
�|j�|j�dS)N)r"cseZdZ��fdd�Z�ZS)z@EventLoopTestsMixin.test_create_server_sock.<locals>.TestMyProtocst�j|��j|�dS)N)rLr?r>)r;r5)rNrrrr?�szPEventLoopTestsMixin.test_create_server_sock.<locals>.TestMyProto.connection_made)rHrIrJr?rOr)r)rNr�TestMyProto�sr�)rr]�0.0.0.0r)r�z	127.0.0.1sxxx)r�r)rr8r"rKr�r	�
setsockoptre�SO_REUSEADDRr�r[r!r]r�r�r�r�r�r�)	r;r��sock_obr�r^r�rPr2r�r)rr�test_create_server_sock�s 


z+EventLoopTestsMixin.test_create_server_sockc
Cs�tjtjd�}|jtjtjd�|jd�|jjt|d�}|jj	|�}|j
d}|j�\}}|jjt||d�}|jt
��}|jj	|�WdQRX|j|jjtj�|j�dS)N)rr]�0.0.0.0r)r�)rPr2)r�r)r�r	r�rer�r�r"r[rKr!r]r�rsr4r�r"r5r6r�)r;r�r�r^r�rPr2r%rrr�test_create_server_addr_in_uses

z2EventLoopTestsMixin.test_create_server_addr_in_usezIPv6 not supported or enabledc	s<tj|jd��G�fdd�dt�}d}xzy*tj�}|jj|d|d�}|jj|�}WnHtk
r�}z,|j	t	j
kr�|d7}|jd|�w(n�WYdd}~Xq(XPq(Wtj�}|j
d|f�|jd	�|jj��}|jj�|j�tj|jd��tjtj�}|j
d
|f�|jd	�|jj��}|jj�|j�|j�dS)N)r"cseZdZ��fdd�Z�ZS)zFEventLoopTestsMixin.test_create_server_dual_stack.<locals>.TestMyProtocst�j|��j|�dS)N)rLr?r>)r;r5)rN�f_protorrr?szVEventLoopTestsMixin.test_create_server_dual_stack.<locals>.TestMyProto.connection_made)rHrIrJr?rOr)r�)rNrr�sr�r)rPr2r]rz	127.0.0.1sxxxz::1)rr8r"rKrr1r[r!r4r5r6ZassertGreaterEqualr�r�r�r5r�ra)	r;r�Z	try_countr2r�r^Zexr�rr)r�r�test_create_server_dual_stacks:



z1EventLoopTestsMixin.test_create_server_dual_stackcCs�|jjtdd�}|jj|�}|jd}|j�\}}tj�}|jd|f�|jd�|j	�|j	�tj�}|j
t|jd|f�|j	�dS)Nz0.0.0.0rz	127.0.0.1sxxx)r"r[rKr!r]r�r�r�r�r�rsr�)r;r�r^r�rPr2r�rrr�test_server_close?s

z%EventLoopTestsMixin.test_server_closecsnG�fdd�dt�}�jj|dd�}�jj|�\}�|jd�\}}�j|tj��j�|��jd�j	��j
�j|��jj�fdd	�||fd
�}�jj|�\}��j|tj��j�t��jd�j	��j
�j|�|jd�t
j�j�fdd	���jd
�j�t
j�j�fdd	���jd�j��j|jd��|j��jj�j��jd�j	��jj�dS)Ncs*eZdZ��fdd�Z�fdd�Z�ZS)zNEventLoopTestsMixin.test_create_datagram_endpoint.<locals>.TestMyDatagramProtocst�j�jd�dS)N)r")rLr<r")Z
inner_self)rNr;rrr<SszWEventLoopTestsMixin.test_create_datagram_endpoint.<locals>.TestMyDatagramProto.__init__cs$t�j||�|jjd||�dS)Nsresp:)rLrSr5�sendto)r;rArR)rNrrrSVsz`EventLoopTestsMixin.test_create_datagram_endpoint.<locals>.TestMyDatagramProto.datagram_received)rHrIrJr<rSrOr)r;)rNr�TestMyDatagramProtoRsr��	127.0.0.1r)r0r�rQcst�jd�S)N)r")rPr"r)r;rrr�eszCEventLoopTestsMixin.test_create_datagram_endpoint.<locals>.<lambda>)Zremote_addrsxxxcs�jS)N)r7r)r^rrr�osr2cs�jS)N)r7r)r�rrr�qs�rE)r�r)rPr"�create_datagram_endpointr!r�r�rr�r�r6r�r5r�rr�r7r�r�r:)r;r��coroZs_transportrPr2r5r)r�r;r^r�test_create_datagram_endpointQs6


z1EventLoopTestsMixin.test_create_datagram_endpointcs�tjdkr"t�jtj�r"tjd��d}d}�jj�jj	|dt
ji��}xN|D]F\}}}}}y(t
j
|||d�}|jd�|j
|�WnYqLXPqLW�jj�fdd	�|d
�}	�jj|	�\}
}�j|
tj��j|t�|
j��jj|j�dS)Nrz.UDP is not supported with proactor event loops�	127.0.0.1rr)rrrFcst�jd�S)N)r")rPr"r)r;rrr��szHEventLoopTestsMixin.test_create_datagram_endpoint_sock.<locals>.<lambda>)r�)r�r)rrr�r"rr�rGrHr!rr�Z
SOCK_DGRAMr�r�r�r�rr�rPr�r:)r;r�Z
local_addressr
rrrrr�r�r�r�r)r;r�"test_create_datagram_endpoint_socks0

z6EventLoopTestsMixin.test_create_datagram_endpoint_sockcCsf|j�}t|tj�s&|j�|jd�|jd|j�|j�|jd|j�|j|j	�|j|j
�dS)Nz#loop is not a BaseSelectorEventLoopr]r)rjr�rZBaseSelectorEventLoopr�ZskipTestr�Z
_internal_fdsr�Z_csockZ_ssock)r;r"rrr�test_internal_fds�s
z%EventLoopTestsMixin.test_internal_fdsrzDon't support pipes for Windowscst�jd��tj�\}}tj|dd��tj���fdd��}�jj|��tj	|d�t
j�j�fdd���jd	�j
�tj	|d
�t
j�j�fdd���jdd
g�j��jd�j
�tj|��jj�j��jdd
ddg�j��j�jjd��dS)N)r"�rbic3s^�jj�fdd���EdH\}}�j|���j|�j��jddg�j��jd�j�dS)Ncs�S)Nrr)rrrr��szEEventLoopTestsMixin.test_read_pipe.<locals>.connect.<locals>.<lambda>r4r=r)r"�connect_read_piper�r5r�r6r7)r��p)�pipeobjrr;rrr��sz3EventLoopTestsMixin.test_read_pipe.<locals>.connect�1cs
�jdkS)Nr])r7r)rrrr��sz4EventLoopTestsMixin.test_read_pipe.<locals>.<lambda>r]s2345cs
�jdkS)Nr)r7r)rrrr��sr4r=rrCrE�pipe)rUr"r�r��io�openrrrr!rMrr�r�r7r6r�r:r�r5r�)r;�rpipe�wpiper�r)r�rr;r�test_read_pipe�s"	
z"EventLoopTestsMixin.test_read_pipecs�|j��t�d��t�d��tj�\}}tj|dd��tj|dd��tj�����fdd��}�j	|��\}}�j
�|jdt|��|jdt|���j
��j
�d|_
d|_
dS)N)r"r�ir�c3sD�j�fdd���EdH\}}�j�fdd���EdH\}}||fS)Ncs�S)Nrr)�
read_protorrr��szSEventLoopTestsMixin.test_unclosed_pipe_transport.<locals>.connect.<locals>.<lambda>cs�S)Nrr)�write_protorrr��s)r��connect_write_pipe)�read_transportrC�write_transport)r"r��rpipeobj�wpipeobjr�rrr��s
zAEventLoopTestsMixin.test_unclosed_pipe_transport.<locals>.connectr�)rjrUrWr�r�r�r�rrrr!r�r7�reprZ_pipe)r;r�r�r�r�r�r)r"r�r�r�r�r�test_unclosed_pipe_transport�s

	z0EventLoopTestsMixin.test_unclosed_pipe_transportrr�r�cs
t�jd��tj�\}}tj|dd��tj���fdd��}�jj|��tj	|d�t
j�j�fdd���jd	�j
�tj	|d
�t
j�j�fdd���jdd
g�j��jd�j
�tj|��jj��jj�j��jdd
ddg�j��j�jjd��dS)N)r"r�rc3s^�jj�fdd���EdH\}}�j|���j|�j��jddg�j��jd�j�dS)Ncs�S)Nrr)rrrr��szKEventLoopTestsMixin.test_read_pty_output.<locals>.connect.<locals>.<lambda>r4r=r)r"r�r�r5r�r6r7)r�r�)�master_read_objrr;rrr��sz9EventLoopTestsMixin.test_read_pty_output.<locals>.connectr�cs�jS)N)r7r)rrrr�	sz:EventLoopTestsMixin.test_read_pty_output.<locals>.<lambda>r]s2345cs
�jdkS)Nr)r7r)rrrr�
sr4r=rrCrEr�)rUr"r��openptyr�r�rrrr!rMrr�r�r7r6r�r5r:r�r�)r;�master�slaver�r)r�rr;r�test_read_pty_output�s$	

z(EventLoopTestsMixin.test_read_pty_outputcs6tj�\�}tj|dd�}t|jd��|jj�fdd�|�}|jj|�\}}|j|��|j|�j	�|j
d�j�|jd�t
���fdd	��tj|j��fd
d��|j
d��|jd�tj|j��fdd��|j
d
��|j
d�j�tj��|j�j	jd���j	j�|jj�j�|j
d�j�dS)N�wbi)r"cs�S)Nrr)rrrr� sz5EventLoopTestsMixin.test_write_pipe.<locals>.<lambda>r=r�cstj�d�}||7}t|�S)Ni)r�r�r@)rA�chunk)r�rrr�)sz3EventLoopTestsMixin.test_write_pipe.<locals>.readercs���dkS)Nr]rr)rAr�rrr�.ss2345cs���dkS)Nrrr)rAr�rrr�2ss12345r�rE)r�r�r�r�rWr"r�r!r�r5r�r6rMr�rr�r�r�r�r:)r;r�r�r�r5r�r)rArr�r�r�test_write_pipes,



z#EventLoopTestsMixin.test_write_pipecs�tj�\}}|jd�tj|j�dd�}t|jd��|jj�fdd�|�}|jj	|�\}}|j
|��|j
|�j�|jd�j
�|jd�|jj	|jj|d��}|jd|�|j�|jj	�j�|jd	�j
�dS)
NFr�i)r"cs�S)Nrr)rrrr�HszIEventLoopTestsMixin.test_write_pipe_disconnect_on_close.<locals>.<lambda>r=r�rE)rr�r�r�r��detachrWr"r�r!r�r5r�r6rMr�r�r:)r;ZrsockZwsockr�r�r5r�rAr)rr�#test_write_pipe_disconnect_on_close@s

z7EventLoopTestsMixin.test_write_pipe_disconnect_on_closecs>tj�\�}tj|dd�}t|jd��|jj�fdd�|�}|jj|�\}}|j|��|j|�j	�|j
d�j�|jd�t
���fdd	��tj|j��fd
d�dd�|j
d��|jd
�tj|j��fdd�dd�|j
d��|j
d�j�tj��|j�j	jd���j	j�|jj�j�|j
d�j�dS)Nr�r)r"cs�S)Nrr)rrrr�asz4EventLoopTestsMixin.test_write_pty.<locals>.<lambda>r=r�cstj�d�}||7}t|�S)Ni)r�r�r@)rAr�)r�rrr�jsz2EventLoopTestsMixin.test_write_pty.<locals>.readercs���dkS)Nr]rr)rAr�rrr�osr)�timeouts2345cs���dkS)Nrrr)rAr�rrr�tss12345r�rE)r�r�r�r�rWr"r�r!r�r5r�r6rMr�rr�r�r�r�r:)r;r��slave_write_objr�r5r�r)rAr�rr�r�test_write_ptyWs0



z"EventLoopTestsMixin.test_write_ptyc
s�tj�\�}tj|�}tj|�tj|dd�}t|jd��|jj	�fdd�|�}|jj
|�\}}|j|��|j|�j�|j
ddg�j�|j
d�j�tj|dd�}t|jd��|jj�fd	d�|�}|jj
|�\}	}|j|��|j|	�j�|j
d�j�t���fd
d��|	jd�tj|j��fd
d�dd�|j
d��|j
ddg�j�|j
d�j�tj�d�tj|j�fdd�dd�|j
ddg�j�|j
d�j�|j
d�j�|	jd�tj|j��fdd�dd�|j
d��|j
ddg�j�|j
d�j�tj�d�tj|j�fdd�dd�|j
ddg�j�|j
d�j�|j
d�j�tj��|j�|jj
�j�|j
ddddg�j�|	j�|jj
�j�|j
d�j�dS)Nr�r)r"cs�S)Nrr)r�rrr��sz<EventLoopTestsMixin.test_bidirectional_pty.<locals>.<lambda>r4r=r�cs�S)Nrr)r�rrr��scstj�d�}||7}t|�S)Ni)r�r�r@)rAr�)r�rrr��sz:EventLoopTestsMixin.test_bidirectional_pty.<locals>.readerr�cs���dkS)Nr]rr)rAr�rrr��sr)r��acs
�jdkS)Nr])r7r)r�rrr��sr]s2345cs���dkS)Nrrr)rAr�rrr��ss12345sbcdecs
�jdkS)Nr)r7r)r�rrr��srrCrE)r�r��dup�ttyZsetrawr�r�rUr"r�r!r�r5r�r6r7rWr�r�rMrr�r�r:)
r;Z
read_slaveZwrite_slaveZslave_read_objZread_connectr�r�r�Z
write_connectr�r)rAr�r�r�r�r�test_bidirectional_pty�sh




z*EventLoopTestsMixin.test_bidirectional_ptycs�tj�\}}|jd��jj|d��t�dd�}|dk	rD�j|j�tj	��fdd��}t
j�}tj|��jd�}�jj
�t
j�|}�j|d��j|j�d��jtj�j�|dk	rȈj|j��jj|�|j�|j�dS)	NFr]�ovc3sRz@y�jj�j��EdHWntjk
r8d}YnXd}Wd�jj�X|S)N�	cancelled)r"r�r�r�CancelledErrorr{)r�)r�r;rr�main�s
z:EventLoopTestsMixin.test_prompt_cancellation.<locals>.main)r"g�������?r�)rr�r�r"r��getattrro�pendingrrrrvr�rRr�Z
assertLessr��resultrsr�r�rZr�)r;r�r�r�r�r�r��elapsedr)r�r;r�test_prompt_cancellation�s&


z,EventLoopTestsMixin.test_prompt_cancellationcsn��fdd�}�jj�d�j_|�j_tj�fdd��}�jj|���j�jjd�jj�jjj	j
d��dS)Ncs�jjd7_��dS)Nr])r"�_run_once_counterr)�
orig_run_oncer;rr�	_run_once�sz<EventLoopTestsMixin.test_timeout_rounding.<locals>._run_oncerc3sn�j}tjd|d�EdHtjd|d�EdHtjd|d�EdHtjd|d�EdHtjd|d�EdHdS)Ng{�G�z�?)r"g-C��6?g���ư>g:�0�yE>g�����|�=)r"rrw)r")r;rr�wait�sz7EventLoopTestsMixin.test_timeout_rounding.<locals>.wait�)Zclock_resolutionZselector)r"r�r�rrrr!ZassertLessEqualZ_clock_resolutionZ	_selectorrNrH)r;r�r�r)r�r;r�test_timeout_rounding�s	z)EventLoopTestsMixin.test_timeout_roundingcCsx|j�}dd�}tj�\}}|j|j�|j|j�|j||�|j||�|j�|j|j|��|j|j	|��dS)NcSsdS)Nrrrrrr�
szCEventLoopTestsMixin.test_remove_fds_after_closing.<locals>.<lambda>)
rjrr�r\r�r�r�r�r�r�)r;r"r�r�r�rrr�test_remove_fds_after_closingsz1EventLoopTestsMixin.test_remove_fds_after_closingcCs�|j�}dd�}tj�\}}|j|j�|j|j�|j�|jt��|j||�WdQRX|jt��|j||�WdQRXdS)NcSsdS)Nrrrrrr�sz@EventLoopTestsMixin.test_add_fds_after_closing.<locals>.<lambda>)	rjrr�r\r�rsrtr�r�)r;r"r�r�r�rrr�test_add_fds_after_closingsz.EventLoopTestsMixin.test_add_fds_after_closingc	sBtj�fdd��}|�j�}�jt���jj|�WdQRXdS)Ncs�jj�dS)N)r"r�)r")r;rr�
close_loop$szEEventLoopTestsMixin.test_close_running_event_loop.<locals>.close_loop)rrrr"rsrtr!)r;r�r�r)r;r�test_close_running_event_loop#s
z1EventLoopTestsMixin.test_close_running_event_loopcBCs�|jj�tjdd��}dd�}|�}|j|j�|jt��|jj�WdQRX|jt�� tj|jd�}|jj	|�WdQRX|jt��|jj
|�WdQRX|jt��|jj|�WdQRX|jt��|jjd|�WdQRX|jt��|jj
|jj�d|�WdQRX|jt��|jjd|�WdQRX|jt��|jj|�WdQRX|jt��|jjtj|�WdQRXdS)NcSsdS)Nrrrrr�test/sz,EventLoopTestsMixin.test_close.<locals>.testcSsdS)NFrrrrrr�3sz0EventLoopTestsMixin.test_close.<locals>.<lambda>)r"g�?g)r"r�rrrr\rsrtr�r8r!r�r�r��call_atrvr��create_taskr�r��SIGTERM)r;r��funcr�Zfutrrr�
test_close,s0
"zEventLoopTestsMixin.test_close)T)TN)TN)NN)N)N)N)drHrIrJrirmrurzr}r�r�r�r�r�r�r�r�r�r�rG�
skipUnlessrr�r�r�r�r�r�r�r�r�rrrrrr&�skipIfrr*r,r.r/r3r9rDrMrrr_r`rbrcrfrmrnrprvrwrxrzr{r|r}r�r�r�r�r�r�r�r�r�r�r�r�rZIPV6_ENABLEDr�r�r�r�r�rrr�r��requires_mac_verZrequires_freebsd_versionr�r�r�r�r�r�r�r�r�r�r�rOrr)rNrrh�s�		
!,
 

$


8$	


  ).""
#&(E$	rhc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zej
dd�dd��Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#S)$�SubprocessTestsMixincCs,tjdkr|j|t�n|jtj|�dS)Nr)rrr�rr�r�r�)r;rbrrr�check_terminatedOs
z%SubprocessTestsMixin.check_terminatedcCs,tjdkr|j|t�n|jtj|�dS)Nr)rrr�rr�r�r�)r;rbrrr�check_killedVs
z!SubprocessTestsMixin.check_killedcCs�tjjtjjt�d�}|jjtjt	|j�t
j|�}|jj|�\}}|j
|t	�|jj|j�|jd|j�|jd�}|jd�|jj|jdj��tj��|j�WdQRX|jj|j�|j|j�|jd|jd�dS)Nzecho.pyr=rsPython The Winnerr])r�rgr��dirname�__file__r"�subprocess_execr(r)rXr�
executabler!r�r9r�r6�get_pipe_transportrMrcr�rr!r�r_r�rbrA)r;�progr��transpr�stdinrrr�test_subprocess_exec]s 



z)SubprocessTestsMixin.test_subprocess_execc	Cs tjjtjjt�d�}|jjtjt	|j�t
j|�}|jj|�\}}|j
|t	�|jj|j�|jd|j�|jd�}|jd�|jj|jdj��|jdj�|jd|jd�|jd�|jj|jdj��|jd|jd�tj��|j�WdQRX|jj|j�|j|j�dS)Nzecho.pyr=rsPython r]s
The WinnersPython The Winner)r�rgr�r�r�r"r�r(r)rXrr�r!r�r9r�r6r�rMrcr��clearrArr!r�r_r�rb)r;r�r�r�rr�rrr�test_subprocess_interactiveqs(




z0SubprocessTestsMixin.test_subprocess_interactivecCs�|jjtjt|j�d�}|jj|�\}}|j|t�|jj|j�|jd�j	�|jj|j
�|jd|j�|j
tdd�|jj�D���|j|jdjd�d�|j|jdd	�|j	�dS)
Nzecho Pythonrcss|]}|j�VqdS)N)r:)rYr�rrr�	<genexpr>�sz=SubprocessTestsMixin.test_subprocess_shell.<locals>.<genexpr>r]s
sPythonr^r\)r"�subprocess_shellr(r)rXr!r�r9r�r�r_r�rbro�allra�valuesrA�rstrip)r;r�r�rrrr�test_subprocess_shell�sz*SubprocessTestsMixin.test_subprocess_shellcCsd|jjtjt|j�ddddd�}|jj|�\}}|j|t�|jj|j�|jd|j	�|j
�dS)Nzexit 7)r��stdout�stderr�)r"r�r(r)rXr!r�r_r�rbr�)r;r�r�rrrr�test_subprocess_exitcode�sz-SubprocessTestsMixin.test_subprocess_exitcodecCs�|jjtjt|j�ddddd�}|jj|�\}}|j|t�|j|jd��|j|jd��|j|jd��|jj|j	�|j
d|j�|j|j��dS)Nzexit 7)r�r�r�rr]r^r�)
r"r�r(r)rXr!r�r�r�r_r�rbr�)r;r�r�rrrr�"test_subprocess_close_after_finish�sz7SubprocessTestsMixin.test_subprocess_close_after_finishcCs�tjjtjjt�d�}|jjtjt	|j�t
j|�}|jj|�\}}|j
|t	�|jj|j�|j�|jj|j�|j|j�|j�dS)Nzecho.py)r�rgr�r�r�r"r�r(r)rXrr�r!r�r9r�r_r�rbr�)r;r�r�r�rrrr�test_subprocess_kill�s
z)SubprocessTestsMixin.test_subprocess_killcCs�tjjtjjt�d�}|jjtjt	|j�t
j|�}|jj|�\}}|j
|t	�|jj|j�|j�|jj|j�|j|j�|j�dS)Nzecho.py)r�rgr�r�r�r"r�r(r)rXrr�r!r�r9Z	terminater_r�rbr�)r;r�r�r�rrrr�test_subprocess_terminate�s
z.SubprocessTestsMixin.test_subprocess_terminateTz"Temporarily skipped (rhbz#1088233)cCs�tjtjtj�}z�tjjtjjt�d�}|jj	t
jt|j�t
j|�}|jj|�\}}|j|t�|jj|j�|jtj�|jj|j�|jtj|j�|j�Wdtjtj|�XdS)Nzecho.py)r��SIGHUP�SIG_DFLr�rgr�r�r�r"r�r(r)rXrr�r!r�r9Zsend_signalr_r�rbr�)r;Zold_handlerr�r�r�rrrr�test_subprocess_send_signal�s
z0SubprocessTestsMixin.test_subprocess_send_signalcCs�tjjtjjt�d�}|jjtjt	|j�t
j|�}|jj|�\}}|j
|t	�|jj|j�|jd�}|jd�|jj|j�|j�|jd|jd�|j|jdjd�|jd�|jd|j�dS)Nzecho2.pyrstestsOUT:testr]r^sERR:test)r�rgr�r�r�r"r�r(r)rXrr�r!r�r9r�rMr_r�r�rAror�rb)r;r�r�r�rr�rrr�test_subprocess_stderr�s


z+SubprocessTestsMixin.test_subprocess_stderrcCs�tjjtjjt�d�}|jjtjt	|j�t
j|tj
d�}|jj|�\}}|j|t	�|jj|j�|jd�}|j|jd��|j|jd��|jd�|jj|j�|j|jdjd�|jd�|jd|jd�|j�|jd|j�dS)	Nzecho2.py)r�rr]r^stestsOUT:testERR:testr\)r�rgr�r�r�r"r�r(r)rXrr��
subprocessZSTDOUTr!r�r9r�r�r�rMr_rorAr�r�r�rb)r;r�r�r�rr�rrr�)test_subprocess_stderr_redirect_to_stdout�s"

z>SubprocessTestsMixin.test_subprocess_stderr_redirect_to_stdoutc	CsFtjjtjjt�d�}|jjtjt	|j�t
j|�}|jj|�\}}|j
|t	�|jj|j�|jd�}|jd�}|jd�|jj|jdj��|jd|jd�|j�|jj|jd�|jd�|jj|jdj��t
jdkr�|jd	|jd�n|jd
|jd�tj��|j�WdQRX|jj|j�|j|j�dS)Nzecho3.pyrr]stestsOUT:testsxxxr^rsERR:BrokenPipeErrorsERR:OSError)r�rgr�r�r�r"r�r(r)rXrr�r!r�r9r�rMrcr�r�rAr�rarrr!r_r�rb)r;r�r�r�rr�r�rrr�#test_subprocess_close_client_streams.






z8SubprocessTestsMixin.test_subprocess_close_client_streamccs`|jjtjt|j�dddddd�}|jj|�V\}}|j|t�|jj|j�|jd|j	�dS)Nzexit 7T)r�r�r�Zstart_new_sessionr�)
r"r�r(r)rXr!r�r_r�rb)r;r�rCrrrr�"test_subprocess_wait_no_same_group3sz7SubprocessTestsMixin.test_subprocess_wait_no_same_groupcs�tj�fdd��}�jt���jj|dd��WdQRX�jt���jj|dd��WdQRX�jt���jj|dd��WdQRXdS)Nc;s�jjtjdf|�EdHdS)N�pwd)r"r�r�SubprocessProtocol)rS)r;rrr�?szGSubprocessTestsMixin.test_subprocess_exec_invalid_args.<locals>.connectT)�universal_newlinesi)�bufsize)�shell)rrrrsr�r"r!)r;r�r)r;r�!test_subprocess_exec_invalid_args>sz6SubprocessTestsMixin.test_subprocess_exec_invalid_argsc s�tjd�fdd�	�}�jt���jj|ddg��WdQRX�jt���jj|dd��WdQRX�jt���jj|dd��WdQRX�jt���jj|d	d
��WdQRXdS)Nc;s&|sd}�jjtj|f|�EdHdS)Nr
)r"r�rr)�cmdrS)r;rrr�Ms
zHSubprocessTestsMixin.test_subprocess_shell_invalid_args.<locals>.connectZlsz-lT)ri)r
F)r)N)rrrrsr�r"r!)r;r�r)r;r�"test_subprocess_shell_invalid_argsLsz7SubprocessTestsMixin.test_subprocess_shell_invalid_argsN)rHrIrJr�r�r�r�r�r�r�rrrGr�rrrrr	rrrrrrr�Ms 

!r�c@seZdZdd�ZdS)�SelectEventLoopTestscCstj�S)N)r�SelectorEventLoop)r;rrrrjcsz&SelectEventLoopTests.create_event_loopN)rHrIrJrjrrrrrasrc@s�eZdZdd�Zej�s@dd�Zdd�Zdd�Zd	d
�Z	dd�Z
d
d�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#S)$�ProactorEventLoopTestscCstj�S)N)rZProactorEventLoop)r;rrrrjjsz(ProactorEventLoopTests.create_event_loopcCstjd��dS)Nzneed python 3.5 (ssl.MemoryBIO))rGrH)r;rrrr*nsz1ProactorEventLoopTests.test_create_ssl_connectioncCstjd��dS)Nzneed python 3.5 (ssl.MemoryBIO))rGrH)r;rrrrzqsz-ProactorEventLoopTests.test_create_server_sslcCstjd��dS)Nzneed python 3.5 (ssl.MemoryBIO))rGrH)r;rrrr�tsz;ProactorEventLoopTests.test_create_server_ssl_verify_failedcCstjd��dS)Nzneed python 3.5 (ssl.MemoryBIO))rGrH)r;rrrr�wsz:ProactorEventLoopTests.test_create_server_ssl_match_failedcCstjd��dS)Nzneed python 3.5 (ssl.MemoryBIO))rGrH)r;rrrr�zsz6ProactorEventLoopTests.test_create_server_ssl_verifiedcCstjd��dS)Nz*IocpEventLoop incompatible with legacy SSL)rGrH)r;rrrr,}sz8ProactorEventLoopTests.test_legacy_create_ssl_connectioncCstjd��dS)Nz*IocpEventLoop incompatible with legacy SSL)rGrH)r;rrrr{�sz4ProactorEventLoopTests.test_legacy_create_server_sslcCstjd��dS)Nz*IocpEventLoop incompatible with legacy SSL)rGrH)r;rrrr��szBProactorEventLoopTests.test_legacy_create_server_ssl_verify_failedcCstjd��dS)Nz*IocpEventLoop incompatible with legacy SSL)rGrH)r;rrrr��szAProactorEventLoopTests.test_legacy_create_server_ssl_match_failedcCstjd��dS)Nz*IocpEventLoop incompatible with legacy SSL)rGrH)r;rrrr��sz=ProactorEventLoopTests.test_legacy_create_server_ssl_verifiedcCstjd��dS)Nz(IocpEventLoop does not have add_reader())rGrH)r;rrrr��sz+ProactorEventLoopTests.test_reader_callbackcCstjd��dS)Nz(IocpEventLoop does not have add_reader())rGrH)r;rrr�test_reader_callback_cancel�sz2ProactorEventLoopTests.test_reader_callback_cancelcCstjd��dS)Nz(IocpEventLoop does not have add_writer())rGrH)r;rrrr��sz+ProactorEventLoopTests.test_writer_callbackcCstjd��dS)Nz(IocpEventLoop does not have add_writer())rGrH)r;rrr�test_writer_callback_cancel�sz2ProactorEventLoopTests.test_writer_callback_cancelcCstjd��dS)Nz6IocpEventLoop does not have create_datagram_endpoint())rGrH)r;rrrr��sz4ProactorEventLoopTests.test_create_datagram_endpointcCstjd��dS)Nz(IocpEventLoop does not have add_reader())rGrH)r;rrrr��sz4ProactorEventLoopTests.test_remove_fds_after_closingN)rHrIrJrjrZ_is_sslproto_availabler*rzr�r�r�r,r{r�r�r�r�rr�rr�r�rrrrrfs$r)�	selectorscs0eZdZ�fdd�Z�fdd�Zdd�Z�ZS)�UnixEventLoopTestsMixincs,t�j�tj�}|j|j�tj|�dS)N)rLrirZSafeChildWatcherZattach_loopr"�set_child_watcher)r;Zwatcher)rNrrri�s
zUnixEventLoopTestsMixin.setUpcstjd�t�j�dS)N)rrrLrm)r;)rNrrrm�s
z UnixEventLoopTestsMixin.tearDowncs.�fdd�}�j��j�jj|��d�dS)Nc�s*tjj�}�jj|t�IdH}|j�|S)N)�
concurrentZfuturesZProcessPoolExecutorr"r�r#Zshutdown)Zpoolr�)r;rrr��s

zEUnixEventLoopTestsMixin.test_get_event_loop_new_process.<locals>.mainr)Zunpatch_get_running_loopr�r"r!)r;r�r)r;r�test_get_event_loop_new_process�s
z7UnixEventLoopTestsMixin.test_get_event_loop_new_process)rHrIrJrirmrrOrr)rNrr�sr�KqueueSelectorcs\eZdZdd�Zejdd�ejej	j
d�d��fdd���Zejdd��fd	d
��Z�Z
S)�KqueueEventLoopTestscCstjtj��S)N)rrrr)r;rrrrj�sz&KqueueEventLoopTests.create_event_loopr�	Zopenbsdztest hangs on OpenBSDcst�j�dS)N)rLr�)r;)rNrrr��sz)KqueueEventLoopTests.test_read_pty_outputcst�j�dS)N)rLr�)r;)rNrrr��sz#KqueueEventLoopTests.test_write_pty)rHrIrJrjrr�rGr�rrr�r�r�rOrr)rNrr�s

r�
EpollSelectorc@seZdZdd�ZdS)�EPollEventLoopTestscCstjtj��S)N)rrrr)r;rrrrj�sz%EPollEventLoopTests.create_event_loopN)rHrIrJrjrrrrr �sr �PollSelectorc@seZdZdd�ZdS)�PollEventLoopTestscCstjtj��S)N)rrrr!)r;rrrrj�sz$PollEventLoopTests.create_event_loopN)rHrIrJrjrrrrr"�sr"c@seZdZdd�ZdS)rcCstjtj��S)N)rrrZSelectSelector)r;rrrrj�sz&SelectEventLoopTests.create_event_loopN)rHrIrJrjrrrrr�scOsdS)Nr)r�rlrrr�noop�sr#csheZdZ�fdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	e
jee
jd�d�dd��Z�ZS)�HandleTestscs"t�j�tj�|_d|jj_dS)NT)rLrirrYr"�	get_debug�return_value)r;)rNrrri�s

zHandleTests.setUpcCs\dd�}f}tj|||j�}|j|j|�|j|j|�|j|j�|j�|j	|j�dS)NcWs|S)Nr)r�rrrr��sz)HandleTests.test_handle.<locals>.callback)
r�Handler"r��	_callback�_argsr��
_cancelledr�ro)r;r�r��hrrr�test_handle�szHandleTests.test_handlecCs\dd�}tj�|_tj�|j_tj|f|j�}|j�|jjjtj	d�tj
||jd��dS)NcSs
t��dS)N)r�rrrrr�	sz:HandleTests.test_callback_with_exception.<locals>.callbackzException in callback.*)rAr"ZhandleZsource_traceback)rrYr"r~rr'Z_run�assert_called_withrZMockPattern�ANY�_source_traceback)r;r�r+rrr�test_callback_with_exception	s
z(HandleTests.test_callback_with_exceptioncCs(tj�}tjdd�f|j�}||d<dS)NcSsdS)Nrrrrrr�	sz1HandleTests.test_handle_weakref.<locals>.<lambda>r+)�weakref�WeakValueDictionaryrr'r")r;Zwdr+rrr�test_handle_weakref	szHandleTests.test_handle_weakrefcCsxd|jj_tjtd|j�}tjt�\}}|jt	|�d||f�|j
�|jt	|�d�tjt�}tj|f|j�}|jt	|�d||f�tj
tdd�}tj|d|j�}dtj|�|f}|jt	|�|�tj
tdd	�}tj|d|j�}d
tj|�|f}|jt	|�|�tjdk�rttj}tj|�}tj|�\}}tj|f|j�}d}d
|}d|tj|�|f}|jt	|�|�dS)NFr]r^z<Handle noop(1, 2) at %s:%s>z<Handle cancelled>z<Handle noop() at %s:%s>r2z%^<Handle noop\(1, 2\)\(3\) at %s:%s>$)�xz'^<Handle noop\(x=1\)\(2, 3\) at %s:%s>$�z*<function HandleTests.test_handle_repr .*>z%functools.partialmethod\(%s, , \)\(\)z^<Handle %s at %s:%s>$)r]r^)r2)r^r2)r2r5)r"r%r&rr'r#r�get_function_sourcer�r�r�rrr(r)�re�escapeZassertRegexrrFr$�test_handle_repr�
partialmethod)r;r+�filename�linenor|Zregex�methodZcb_regexrrrr9	sD





zHandleTests.test_handle_reprcCs�d|jj_t}tj�jd}tjt	d|j�}t
jt	�\}}|jt
|�d||||f�|j�|jt
|�d||||f�|j�|jt
|�d||||f�dS)NTr]r^z-<Handle noop(1, 2) at %s:%s created at %s:%s>z7<Handle cancelled noop(1, 2) at %s:%s created at %s:%s>)r]r^)r"r%r&r�r�	_getframe�f_linenorr'r#rr6r�r�r�)r;�create_filename�
create_linenor+r;r<rrr�test_handle_repr_debugK	s$

z"HandleTests.test_handle_repr_debugcs|tj�j�}|jd��j|��fdd�}|jt�}||�|jt�}||�|jdt�}||�|jdt�}||�dS)NTcsBtjd�jd}�j|jt��j|jddd�t|df�dS)Nr]r2�test_handle_source_tracebackr�)rr>r?r�r/�listr�r�)r+r<)r;rr�check_source_tracebackj	szHHandleTests.test_handle_source_traceback.<locals>.check_source_tracebackr)	r�get_event_loop_policyrr�r r�r#r�r�)r;r"rEr+r)r;rrCe	s

	

z(HandleTests.test_handle_source_traceback�	CoroutinezNo collections.abc.CoroutinecCs8Gdd�d�}|�}d|_|jtj|��|jtj|�d�d|_|jtj|�d�d|_|jtj|�d�|�}|jtj|�d	�|�}d|_d|_	|jtj|�d�|�}d|_d|_	d|_
|jtj|�d�|�}d|_d|_	d|_
|jtj|�t|��d
��|�}d|_	d|_
|jtj|�t|��d
��dS)Nc@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
zEHandleTests.test_coroutine_like_object_debug_formatting.<locals>.CorocSsdS)Nr)r;�vrrrr��	szJHandleTests.test_coroutine_like_object_debug_formatting.<locals>.Coro.sendcWsdS)Nr)r;rFrrr�throw�	szKHandleTests.test_coroutine_like_object_debug_formatting.<locals>.Coro.throwcSsdS)Nr)r;rrrr��	szKHandleTests.test_coroutine_like_object_debug_formatting.<locals>.Coro.closecSsdS)Nr)r;rrr�	__await__�	szOHandleTests.test_coroutine_like_object_debug_formatting.<locals>.Coro.__await__N)rHrIrJr�rIr�rJrrrr�Coro�	srKZAAAzAAA()ZBBBzBBB()Tz
BBB() runningzCoro()z())rHrorZiscoroutiner�rZ_format_coroutinerJ�
cr_running�cr_code�cr_framer�)r;rKr�rrr�+test_coroutine_like_object_debug_formatting�	s:
z7HandleTests.test_coroutine_like_object_debug_formatting)rHrIrJrir,r0r3r9rBrCrGr�r�collections�abcrOrOrr)rNrr$�s
1r$csDeZdZ�fdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Z�Z	S)
�
TimerTestscst�j�tj�|_dS)N)rLrirrYr")r;)rNrrri�	s
zTimerTests.setUpcCs8tj�}tj|dd�ftj��}|jt|�t|��dS)NcSsdS)NFrrrrrr��	sz&TimerTests.test_hash.<locals>.<lambda>)rvr�r�TimerHandlerrYr��hash)r;�whenr+rrr�	test_hash�	s
zTimerTests.test_hashcCs�dd�}d}tj�}tj|||tj��}|j|j|�|j|j|�|j	|j
�|j�|j|j
�|j
|j�|j
|j�|jttjd|||j�dS)NcWs|S)Nr)r�rrrr��	sz'TimerTests.test_timer.<locals>.callbackr]r^r2)r]r^r2)rvr�rrSrrYr�r(r)r�r*r�ror�rs�AssertionErrorr")r;r�r�rUr+rrr�
test_timer�	s
zTimerTests.test_timercCsVd|jj_tjdtf|j�}tjt�}|jt	|�d|�|j
�|jt	|�d�dS)NF�{z&<TimerHandle when=123 noop() at %s:%s>z <TimerHandle cancelled when=123>)r"r%r&rrSr#rr6r�r�r�)r;r+�srcrrr�test_timer_repr�	s




zTimerTests.test_timer_reprcCs�d|jj_t}tj�jd}tjdt	f|j�}t
jt	�\}}|jt
|�d||||f�|j�|jt
|�d||||f�dS)NTr]rYz7<TimerHandle when=123 noop() at %s:%s created at %s:%s>zA<TimerHandle cancelled when=123 noop() at %s:%s created at %s:%s>)r"r%r&r�rr>r?rrSr#rr6r�r�r�)r;r@rAr+r;r<rrr�test_timer_repr_debug�	s


z TimerTests.test_timer_repr_debugcCs�dd�}tj�}tj||f|j�}tj||f|j�}|j||k�|j||k�|j||k�|j||k�|j||k�|j||k�|j||k�|j||k�|j||k�|j||k�|j�|j||k�tj||f|j�}tj|d|f|j�}|j||k�|j||k�|j||k�|j||k�|j||k�|j||k�|j||k�|j||k�|j||k�|j||k�tj|f|j�}|j	t
|j|��|j	t
|j|��dS)NcWs|S)Nr)r�rrrr�
sz2TimerTests.test_timer_comparison.<locals>.callbackg$@)
rvr�rrSr"r�ror�r'r��NotImplemented�__eq__�__ne__)r;r�rUZh1Zh2Zh3rrr�test_timer_comparison
s>z TimerTests.test_timer_comparison)
rHrIrJrirVrXr[r\r`rOrr)rNrrR�	srRc@seZdZdd�ZdS)�AbstractEventLoopTestscCs�tj�}tj�}|jt|j�|jt|jd�|jt|j�|jt|j	�|jt|j
�|jt|j�|jt|jd�|jt|j
dd�|jt|j||�|jt|jd�|jt|j�|jt|jd�|jt|j||�|jt|j|�|jt|jdd�|jt|jd�|jt|j|�|jt|j|�|jt|j|�|jt|jd|�|jt|jd�|jt|jd|�|jt|jd�|jt|j|d�|jt|j|d�|jt|j||�|jt|j |�|jt|j!d|�|jt|j"d�|jt|j"d�|jt|j#|tj$j%�|jt|j&|tj$j%�|jt|j'|tj$�|jt|j(|�|jt|j)|�|jt|j*|�|jt|j+|�|jt|j,�|jt|j-|�dS)Nr0�r]r)r0rb).rrYr�AbstractEventLooprs�NotImplementedErrorr�r!r{rprkr�r�r�r�r�rvr�r�Zset_default_executorrZgetnameinforr[r�r�r�r�r�r�r�r�r�r�r�r��sentinelr�r�r�r�Zset_exception_handlerZdefault_exception_handlerr~r%r�)r;r�r"rrr�test_not_implemented-
s�








z+AbstractEventLoopTests.test_not_implementedN)rHrIrJrfrrrrra+
srac@seZdZdd�ZdS)�ProtocolsAbsTestscCs�tj�}tj�}|j|j|��|j|j|��|j|j|��|j|j��tj	�}|j|j|��|j|j|��|j|j
|��|j|j||��tj�}|j|j|��|j|j|��|j|j
d|��|j|jd|��|j|j��dS)Nr])rrYrr�r�r?rGrBrD�DatagramProtocolrTrSrrerfrg)r;r�r�ZdpZsprrr�
test_empty�
s"zProtocolsAbsTests.test_emptyN)rHrIrJrirrrrrg�
srgc@sfeZdZdd�Zdd�Zdd�Zdd�Zejd	�d
d��Z	dd
�Z
dd�Zdd�Zdd�Z
dd�ZdS)�PolicyTestscCsZtj�}|jt|j�|jt|jt��|jt|j�|jt|j�|jt|j	t��dS)N)
r�AbstractEventLoopPolicyrsrd�get_event_loopr r�rZget_child_watcherr)r;�policyrrr�test_event_loop_policy�
s
z"PolicyTests.test_event_loop_policycCsXtj�}|j|jj�|j�}|j|tj�|j|jj|�|j||j��|j	�dS)N)
r�DefaultEventLoopPolicyr��_localZ_looprlr�rcr�r�)r;rmr"rrr�test_get_event_loop�
szPolicyTests.test_get_event_loopc	CsFtj�}tjj|d|jd��}|j�}|j|�WdQRX|j�dS)Nr )�wraps)	rrorrr�r rlr-r�)r;rmZm_set_event_loopr"rrr�(test_get_event_loop_calls_set_event_loop�
sz4PolicyTests.test_get_event_loop_calls_set_event_loopcCs$tj�}|jd�|jt|j�dS)N)rror rsrtrl)r;rmrrr�"test_get_event_loop_after_set_none�
s
z.PolicyTests.test_get_event_loop_after_set_nonez'asyncio.events.threading.current_threadcs,�fdd�}tj|d�}|j�|j�dS)Ncstj�}�jt|j�dS)N)rrorsrtrl)rm)r;rrr��
sz1PolicyTests.test_get_event_loop_thread.<locals>.f)r�)r�r�r�r�)r;Zm_current_threadr�Zthr)r;r�test_get_event_loop_thread�
sz&PolicyTests.test_get_event_loop_threadcCs*tj�}|j�}|j|tj�|j�dS)N)rrorr�rcr�)r;rmr"rrr�test_new_event_loop�
szPolicyTests.test_new_event_loopcCshtj�}|j�}|jt|jt��|j�}|j|�|j||j��|j	||j��|j
�|j
�dS)N)rrorlrsrWr r�rr��assertIsNotr�)r;rmZold_loopr"rrr�test_set_event_loop�
s
zPolicyTests.test_set_event_loopcCs*tj�}|j|tj�|j|tj��dS)N)rrFr�rkr�)r;rmrrr�test_get_event_loop_policy�
sz&PolicyTests.test_get_event_loop_policycCsL|jttjt��tj�}tj�}tj|�|j|tj��|j||�dS)N)	rsrWr�set_event_loop_policyr�rFror�rw)r;�
old_policyrmrrr�test_set_event_loop_policy�
s
z&PolicyTests.test_set_event_loop_policycs�Gdd�dtj�}d�tj�}zBtj|��tj���jtj�d���fdd�}�j|��Wdtj|��dk	r|�j�X�jtj�d�dS)Nc@seZdZdd�ZdS)zDPolicyTests.test_get_event_loop_returns_running_loop.<locals>.PolicycSst�dS)N)rd)r;rrrrl�
szSPolicyTests.test_get_event_loop_returns_running_loop.<locals>.Policy.get_event_loopN)rHrIrJrlrrrr�Policy�
sr}c�s$�jtj����jtj���dS)N)r�rrl�_get_running_loopr)r"r;rrr�szBPolicyTests.test_get_event_loop_returns_running_loop.<locals>.func)	rrorFrzrr�r~r!r�)r;r}r{r�r)r"r;r�(test_get_event_loop_returns_running_loop�
s

z4PolicyTests.test_get_event_loop_returns_running_loopN)rHrIrJrnrqrsrtrrrurvrxryr|rrrrrrj�
s	
rj�__main__)r$)r%)r&�r'r(�r��r)r*�r��r+r,�r�)r�r�r��r'r(�r��r-r.�r��r)r/�r��r+r0�r�)r�r�r�r��r1r0)r�)G�__doc__�collections.abcrPZconcurrent.futuresrr(�gcr�r�rr7r�r�r�ImportErrorrrr�rvr5rGrr1r�rrrrrrZasyncio.test_utilsr	r
rr�rr
rr#rr�r�r�r3rKrhrPrUZBaseProtocolrWrrXrhr�ZTestCaserrrrrrr r"r#r$rRrargrjrHr�rrrr�<module>s�

		

" )f
7NnXt