Your IP : 216.73.216.213


Current Path : /opt/alt/python39/lib64/python3.9/test/test_asyncio/__pycache__/
Upload File :
Current File : //opt/alt/python39/lib64/python3.9/test/test_asyncio/__pycache__/test_events.cpython-39.pyc

a

XC?hQ��@s�dZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZzddlZWne
yndZYn0ddlZddlZddlZddlZddlZddlZddlmZddlZejdkr�ddlZddlZddlmZddlmZddlmZddlmZdd	lmZdd
lm Z ddl!m"Z"ddl!m#Z#m$Z$m%Z%d
d�Z&dd�Z'dd�Z(Gdd�d�Z)Gdd�dej*�Z+Gdd�de+�Z,Gdd�dej-�Z.Gdd�dej*�Z/Gdd�dej0�Z1Gdd �d ej2�Z3Gd!d"�d"�Z4Gd#d$�d$�Z5ejdk�rGd%d&�d&e4ej6�Z7Gd'd(�d(e4e5ej6�Z8n�ddl9Z9Gd)d*�d*e4�Z:e;e9d+��rTGd,d-�d-e:e5ej6�Z<e;e9d.��rvGd/d0�d0e:e5ej6�Z=e;e9d1��r�Gd2d3�d3e:e5ej6�Z>Gd4d&�d&e:e5ej6�Z7d5d6�Z?Gd7d8�d8ej6�Z@Gd9d:�d:ej6�ZAGd;d<�d<ej6�ZBGd=d>�d>ej6�ZCGd?d@�d@�ZDGdAdB�dBeDej6�ZEzddlFZFWne
�y@Yn0GdCdD�dDeDej6�ZGGdEdF�dFej6�ZHGdGdH�dHej6�ZIeJdIk�r�e�K�dS)JzTests for events.py.�N)�mock�win32)�
coroutines)�events)�proactor_events)�selector_events)�utils)�support)�
socket_helper)�	ALWAYS_EQ�LARGEST�SMALLESTcCst�d�dS�N)�asyncio�set_event_loop_policy�rr�B/opt/alt/python39/lib64/python3.9/test/test_asyncio/test_events.py�tearDownModule'srcCsFtj�d�rdStjdkrdSt��d}ttt|�d���}|dkS)z4Return True if the platform is Mac OS 10.4 or older.ZaixT�darwinFr�.)�
�)�sys�platform�
startswithZmac_ver�tuple�map�int�split)�versionrrr�broken_unix_getsockname+s
r cCs&dd�}t��}t�|�|�|��S)Nc�sdS�N�hellorrrrr�doit7sz8_test_get_event_loop_new_process__sub_proc.<locals>.doit)r�new_event_loop�set_event_loop�run_until_complete)r#�looprrr�*_test_get_event_loop_new_process__sub_proc6s
r(c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�CoroLikecCsdSrr)�self�vrrr�send@sz
CoroLike.sendcGsdSrr�r*�excrrr�throwCszCoroLike.throwcCsdSrr�r*rrr�closeFszCoroLike.closecCsdSrrr0rrr�	__await__IszCoroLike.__await__N)�__name__�
__module__�__qualname__r,r/r1r2rrrrr)?sr)c@s>eZdZdZdZddd�Zdd�Zdd�Zdd	�Zd
d�Z	dS)
�MyBaseProtoNcCs2d|_d|_d|_|dur.|��|_|��|_dS�N�INITIALr)�	transport�state�nbytes�
create_future�	connected�done�r*r'rrr�__init__Qs
zMyBaseProto.__init__cCs6||_|jdksJ|j��d|_|jr2|j�d�dS�Nr8�	CONNECTED�r9r:r=�
set_result�r*r9rrr�connection_madeYs
zMyBaseProto.connection_madecCs*|jdksJ|j��|jt|�7_dS�NrB�r:r;�len�r*�datarrr�
data_received`szMyBaseProto.data_receivedcCs|jdksJ|j��d|_dS)NrB�EOF�r:r0rrr�eof_receiveddszMyBaseProto.eof_receivedcCs0|jdvsJ|j��d|_|jr,|j�d�dS)N)rBrM�CLOSED�r:r>rDr-rrr�connection_losthszMyBaseProto.connection_lost)N)
r3r4r5r=r>r@rFrLrOrRrrrrr6Ms
r6cseZdZ�fdd�Z�ZS)�MyProtocst��|�|�d�dS)Ns%GET / HTTP/1.0
Host: example.com

)�superrF�writerE��	__class__rrrFpszMyProto.connection_made�r3r4r5rF�
__classcell__rrrVrrSosrSc@s:eZdZdZddd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�MyDatagramProtoNcCs"d|_d|_|dur|��|_dSr7)r:r;r<r>r?rrrr@xszMyDatagramProto.__init__cCs$||_|jdksJ|j��d|_dS)Nr8�INITIALIZED�r9r:rErrrrF~szMyDatagramProto.connection_madecCs*|jdksJ|j��|jt|�7_dS�Nr[rH�r*rK�addrrrr�datagram_received�sz!MyDatagramProto.datagram_receivedcCs|jdksJ|j��dSr]rNr-rrr�error_received�szMyDatagramProto.error_receivedcCs0|jdksJ|j��d|_|jr,|j�d�dS)Nr[rPrQr-rrrrR�szMyDatagramProto.connection_lost)N)	r3r4r5r>r@rFr`rarRrrrrrZus
rZc@s:eZdZdZddd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�MyReadPipeProtoNcCs*dg|_d|_d|_|dur&|��|_dSr7)r:r;r9r<r>r?rrrr@�s
zMyReadPipeProto.__init__cCs,||_|jdgksJ|j��|j�d�dSrA)r9r:�appendrErrrrF�szMyReadPipeProto.connection_madecCs.|jddgksJ|j��|jt|�7_dSrArHrJrrrrL�szMyReadPipeProto.data_receivedcCs(|jddgksJ|j��|j�d�dS)Nr8rBrM)r:rcr0rrrrO�szMyReadPipeProto.eof_receivedcCsPd|jvr|j�d�|jgd�ks.J|j��|j�d�|jrL|j�d�dS)NrM)r8rBrMrP)r:rcr>rDr-rrrrR�s
zMyReadPipeProto.connection_lost)N)	r3r4r5r>r@rFrLrOrRrrrrrb�s
rbc@s*eZdZdZddd�Zdd�Zdd�ZdS)	�MyWritePipeProtoNcCs"d|_d|_|dur|��|_dS)Nr8)r:r9r<r>r?rrrr@�szMyWritePipeProto.__init__cCs$||_|jdksJ|j��d|_dSrAr\rErrrrF�sz MyWritePipeProto.connection_madecCs0|jdksJ|j��d|_|jr,|j�d�dS�NrBrPrQr-rrrrR�sz MyWritePipeProto.connection_lost)N)r3r4r5r>r@rFrRrrrrrd�s
rdc@s<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�MySubprocessProtocolcsbd|_d|_���|_���|_�fdd�td�D�|_ddd�|_d|_t	�
�t	�
�d�|_dS)Nr8csi|]}|����qSr)r<)�.0�fd�r'rr�
<dictcomp>��z1MySubprocessProtocol.__init__.<locals>.<dictcomp>�rk���)r:r9r<r=�	completed�range�disconnectsrK�
returncoderZEvent�got_datar?rrirr@�s

�zMySubprocessProtocol.__init__cCs0||_|jdksJ|j��d|_|j�d�dSrArCrErrrrF�sz$MySubprocessProtocol.connection_madecCs*|jdksJ|j��d|_|j�d�dSre)r:rprDr-rrrrR�sz$MySubprocessProtocol.connection_lostcCs8|jdksJ|j��|j||7<|j|��dSrG)r:rKrt�set)r*rhrKrrr�pipe_data_received�sz'MySubprocessProtocol.pipe_data_receivedcCs>|jdksJ|j��|r*|j|�|�n|j|�|�dSrG)r:rrZ
set_exceptionrD)r*rhr.rrr�pipe_connection_lost�sz)MySubprocessProtocol.pipe_connection_lostcCs$|jdksJ|j��|j��|_dSrG)r:r9Zget_returncodersr0rrr�process_exited�sz#MySubprocessProtocol.process_exitedN)	r3r4r5r@rFrRrvrwrxrrrrrf�srfcs0eZdZ�fdd�Z�fdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Ze�eed�d�dd��Ze�eed�d �d!d"��Ze�eed�d �d#d$��Zd�d&d'�Zd(d)�Zejd*d+��Zd%d,ifd-d.�Zd�d/d0�Zd�d1d2�Ze�e d,ud3�d4d5��Z!eje�e d,ud3�d6d7���Z"d8d9�Z#d:d;�Z$d�d<d=�Z%e�e d,ud3�d>d?��Z&d@dA�Z'e(�)dB�dCdD��Z*dEdF�Z+dGdH�Z,dIdJ�Z-e�ee.dK�dL�dMdN��Z/dOdP�Z0ejdQdR��Z1e�ee.dS�dT�dUdV��Z2d�dWdX�Z3d�dYdZ�Z4d�d[d\�Z5e�e d,ud3�d]d^��Z6eje�e d,ud3�d_d`���Z7e�e d,ud3�dadb��Z8eje�e d,ud3�dcdd���Z9e�e d,ud3�dedf��Z:eje�e d,ud3�dgdh���Z;e�e d,ud3�didj��Z<dkdl�Z=dmdn�Z>e�ej?do�dpdq��Z@drds�ZAdtdu�ZBdvdw�ZCe�ej?do�dxdy��ZDdzd{�ZEd|d}�ZFe�eGjHd~kd�d�d���ZIe�eGjHd~kd�d�d���ZJe�eGjHd~kd�d�d���ZKe�eGjHd~kd�d�d���ZLe�eGjHd~kd�d�d���ZMe�eGjHd~kd�eN�Od�d��d�d����ZPe�eGjHd~kd�eN�Od�d��d�d����ZQd�d��ZRd�d��ZSd�d��ZTd�d��ZUd�d��ZVd�d��ZW�ZXS)��EventLoopTestsMixincs$t���|��|_|�|j�dSr)rT�setUp�create_event_loopr'r%r0rVrrrz�s

zEventLoopTestsMixin.setUpcs4|j��st�|j�|��t��t���dSr)	r'�	is_closed�
test_utils�run_brieflyZ
doCleanupsr	Z
gc_collectrT�tearDownr0rVrrr�s

zEventLoopTestsMixin.tearDowncsZdd����fdd�}��td��$��t�jj|��Wd�n1sL0YdS)Nc�st�d�IdHdS�Nr)r�sleeprrrr�coro1szBEventLoopTestsMixin.test_run_until_complete_nesting.<locals>.coro1c�s"���j����j����dSr)�
assertTruer'�
is_runningr&r�r�r*rr�coro2szBEventLoopTestsMixin.test_run_until_complete_nesting.<locals>.coro2zcoroutine \S+ was never awaited)ZassertWarnsRegex�RuntimeWarning�assertRaises�RuntimeErrorr'r&)r*r�rr�r�test_run_until_complete_nesting�s��z3EventLoopTestsMixin.test_run_until_complete_nestingcCsR|j��}|j�t�d��|j��}|�d||ko@dkn||�dS)N皙�����?g{�G�z�?g�������?)r'�timer&rr�r�)r*Zt0�t1rrr�test_run_until_completes

z+EventLoopTestsMixin.test_run_until_completecs(�fdd�}|�}��t�jj|�dS)Nc�s�j��t�d�IdHdS)Nr�)r'�stoprr�rr0rr�cbs
z?EventLoopTestsMixin.test_run_until_complete_stopped.<locals>.cb)r�r�r'r&)r*r�Ztaskrr0r�test_run_until_complete_stoppeds
�z3EventLoopTestsMixin.test_run_until_complete_stoppedcs>g���fdd�}�j�d|d��j�����dg�dS)Ncs��|��j��dSr�rcr'r���arg��resultsr*rr�callback#s
z5EventLoopTestsMixin.test_call_later.<locals>.callbackr�zhello world)r'�
call_later�run_forever�assertEqual�r*r�rr�r�test_call_later s

z#EventLoopTestsMixin.test_call_latercs>g���fdd�}�j�|dd��j�����dg�dS)Ncs��||f��j��dSrr�)Zarg1Zarg2r�rrr�.sz4EventLoopTestsMixin.test_call_soon.<locals>.callbackr"�world)r"r�)r'�	call_soonr�r�r�rr�r�test_call_soon+s

z"EventLoopTestsMixin.test_call_sooncs�g�t�����fdd�����fdd�}���tj|d�}|����(�j��d��j��Wd�n1sx0Y|����	�ddg�dS)Ncs$��|�t��dkr �j��dS�Nro�rcrIr'r�r�r�rrr�:s
z?EventLoopTestsMixin.test_call_soon_threadsafe.<locals>.callbackcs�j��d����dSr!)r'�call_soon_threadsafe�releaser)r��lockr*rr�
run_in_thread?szDEventLoopTestsMixin.test_call_soon_threadsafe.<locals>.run_in_thread��targetr�r")
�	threadingZLock�acquire�Thread�startr'r�r��joinr�)r*r��tr)r�r�r�r*r�test_call_soon_threadsafe6s(z-EventLoopTestsMixin.test_call_soon_threadsafecsLg���fdd�}�j�|d��j�|d��j�����ddg�dS)Ncs$��|�t��dkr �j��dSr�r�r�r�rrr�Ps
zKEventLoopTestsMixin.test_call_soon_threadsafe_same_thread.<locals>.callbackr"r�)r'r�r�r�r�r�rr�r�%test_call_soon_threadsafe_same_threadMs
z9EventLoopTestsMixin.test_call_soon_threadsafe_same_threadcCsHdd�}|j�d|d�}|j�|�\}}|�|d�|�|t���dS)NcSs|t��fSr)r��	get_identr�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_executorZs
z(EventLoopTestsMixin.test_run_in_executorcsrd��fdd�}dd�}|j�d|�}|��|j�|j���|j��||j_||j_t�	d�|�
��dS)NFcsd�dS�NTr��args�Zcalledrr�patched_call_sooneszJEventLoopTestsMixin.test_run_in_executor_cancel.<locals>.patched_call_sooncSst�d�dS)Ng�������?)r�r�rrrrr�isz<EventLoopTestsMixin.test_run_in_executor_cancel.<locals>.rung�������?)r'r��cancelr&Zshutdown_default_executorr1r�r�r�r��assertFalse)r*r�r�r�rr�r�test_run_in_executor_cancelbs�

z/EventLoopTestsMixin.test_run_in_executor_cancelcs�t��\�}��d�t�����fdd�}�j����|��j�|jd�t	�
�j�fdd���j�|jd�t	�
�j�fdd���j�|j��j��jj��j�
����d	�dS)
NFcsVz��d�}Wnty"YdS0|r4��|�n���j���������dS�N�)�recv�BlockingIOError�extendr�r'�
remove_reader�filenor1�rK��
bytes_read�rr*rr�reader{sz8EventLoopTestsMixin.test_reader_callback.<locals>.readersabccst��dkS)Nrl�rIr�r�rr�<lambda>�rkz:EventLoopTestsMixin.test_reader_callback.<locals>.<lambda>sdefcst��dkS)N�r�rr�rrr��rksabcdef)�socket�
socketpair�setblocking�	bytearrayr'�
add_readerr�r�r,r}�	run_untilr1r�r�r�)r*�wr�rr�r�test_reader_callbackvs


z(EventLoopTestsMixin.test_reader_callbackcs�t��\}���d���fdd�}d}�j����||��j�����j��������	�j��������
�|�t|�d�}|�
���
||�dS)NFcs��|��j��dSr)r,r'r�r��r*r�rr�writer�s
z8EventLoopTestsMixin.test_writer_callback.<locals>.writersxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxro)r�r�r�r'�
add_writerr�r�r��
remove_writerr�r1r�rIr�)r*r�r�rK�readrr�r�test_writer_callback�s

z(EventLoopTestsMixin.test_writer_callback�SIGKILLz
No SIGKILLcsXd��fdd�}|�t|jjd|�|�t|jjd�|�t|jjtjd|�|�t|jjtjd�|�t|jjd|�|�t|jjd�|�t|jjd|�|�t|jjd�|�t|jjtj	|�|�
|j�tj	��|j�tj|�t�
t��tj�t�|j�fdd��|�|j�tj��|�t�tj�tj�|�
|j�tj��dS)	Nrcs�d7�dS�Nrnrr��caughtrr�
my_handler�sz?EventLoopTestsMixin.test_add_signal_handler.<locals>.my_handlerZboomrn���cs�Srrrr�rrr��rkz=EventLoopTestsMixin.test_add_signal_handler.<locals>.<lambda>)r��	TypeErrorr'�add_signal_handler�remove_signal_handler�
ValueError�signal�NSIGr�r�r��SIGINT�os�kill�getpidr}r�r�r��	getsignal�default_int_handler�r*r�rr�r�test_add_signal_handler�sP�
����
��
���z+EventLoopTestsMixin.test_add_signal_handler�SIGALRMz
No SIGALRMcs^d���fdd�}�j�tj|�t�tjdd��j�d�jj��j����	�d�dS)Nrcs�d7��j��dSr�)r'r�r�r�r*rrr��szLEventLoopTestsMixin.test_signal_handling_while_selecting.<locals>.my_handler�{�G�z�?�<rn�
r'r�r�r��	setitimer�ITIMER_REALr�r�r�r�r�rr�r�$test_signal_handling_while_selecting�s
z8EventLoopTestsMixin.test_signal_handling_while_selectingcsld�d����fdd�}�jjtj|g��R�t�tjdd��j�d�jj��j����	�d�dS)N)�*rcs"�d7���|���j��dSr�)r�r'r�r��r�r*Z	some_argsrrr��szAEventLoopTestsMixin.test_signal_handling_args.<locals>.my_handlerr�r�rnr�r�rr�r�test_signal_handling_args�s
z-EventLoopTestsMixin.test_signal_handling_argsTcCsv|j�|�\}}|�|tj�|�|tj�|�|j|�|rN|�|�	d��|j�|j
�|�|jd�|�
�dS)N�socknamer)r'r&�assertIsInstancer�	Transport�Protocol�assertIsr9�assertIsNotNone�get_extra_infor>�
assertGreaterr;r1)r*�connection_fut�check_sockname�tr�prrrr�_basetest_create_connection�sz/EventLoopTestsMixin._basetest_create_connectioncsTt���8}�jj�fdd�g|j�R�}��|�Wd�n1sF0YdS)Ncst�jd�S�Nri�rSr'rr0rrr�rkz<EventLoopTestsMixin.test_create_connection.<locals>.<lambda>)r}�run_test_serverr'�create_connection�addressr)r*�httpd�conn_futrr0r�test_create_connections

��z*EventLoopTestsMixin.test_create_connectioncsXt�}t���4}�j��fdd�|j�}��||�Wd�n1sJ0YdS)Ncst�jd�Srr	rr0rrr�rkzAEventLoopTestsMixin.test_create_unix_connection.<locals>.<lambda>)r r}�run_test_unix_serverr'�create_unix_connectionrr)r*rr
rrr0r�test_create_unix_connections
�z/EventLoopTestsMixin.test_create_unix_connectionNcCs|r|�|�d��|r,|�||�d��n|�|�d��|�||�d��|�d�}|�|t�|�t|�d|�|�|dt�|�|dt�|�|dt�|�d	�}|�|�|�|��|�d
��|�|�	�|�d��|�|�
�|�d��|�|��|�d
��dS)Nr��peername�peercert�cipherrlrrnroZ
ssl_object�compression)rrr�r�rrI�strrrrZgetpeercert)r*�clientrrrrZsslobjrrr�check_ssl_extra_infos<��



�
�
�
�z(EventLoopTestsMixin.check_ssl_extra_infocCsx|j�|�\}}|�|tj�|�|tj�|�d|jj�	�v�|�
|||�|j�|j�|�|j
d�|��dS)N�sslr)r'r&r�rr�r�r�rWr3�lowerrr>rr;r1)r*rrrrrrrr�_basetest_create_ssl_connection1sz3EventLoopTestsMixin._basetest_create_ssl_connectionc		s|t��d�}��|||�ttd�r�tjjfdddd��fdd�}tjd|d��6}|dd�}��|||���	|j
d	�Wd�n1s�0Y��tj��P}|dd�}t�
����|||�Wd�n1s�0YWd�n1s�0Y��	|jjd
�dS)N�r�Purpose)�cafile�capath�cadatacs��|tjj�t��S)z�
                A ssl.create_default_context() replacement that doesn't enable
                cert validation.
                )r�rr�SERVER_AUTHr}�dummy_ssl_context)Zpurposerr r!r0rr�_dummy_ssl_create_contextEszREventLoopTestsMixin._test_create_ssl_connection.<locals>._dummy_ssl_create_contextzssl.create_default_context)�side_effectTrnZCERTIFICATE_VERIFY_FAILED)r}r#r�hasattrrrr"r�patchr�Z
call_countr��SSLError�disable_logger�	exception�reason)	r*r
rrrrr$�m�cmrr0r�_test_create_ssl_connection=s2�
��
�,

�@z/EventLoopTestsMixin._test_create_ssl_connectionz
No ssl modulecsdtjdd��D}tj�jj�fdd�g|j�R�}�j|||jd�Wd�n1sV0YdS)NT�Zuse_sslcst�jd�Srr	rr0rrr�grkz@EventLoopTestsMixin.test_create_ssl_connection.<locals>.<lambda>�r)r}r
�	functools�partialr'rrr.)r*r
rrr0r�test_create_ssl_connectionbs
���z.EventLoopTestsMixin.test_create_ssl_connectioncslt�}tjdd��D}tj�jj�fdd�|jdd�}�j||||jd�Wd�n1s^0YdS)NTr/cst�jd�Srr	rr0rrr�vrkzEEventLoopTestsMixin.test_create_ssl_unix_connection.<locals>.<lambda>�	127.0.0.1)�server_hostnamer0)	r r}rr1r2r'rrr.)r*rr
rrr0r�test_create_ssl_unix_connectionls��z3EventLoopTestsMixin.test_create_ssl_unix_connectioncs�t���z}t��}�jj�fdd�g|j�Rd|jd|fi�}�j�|�\}}|j�	d�d}��
||�|��Wd�n1s�0YdS)Ncst�jd�Srr	rr0rrr��rkzGEventLoopTestsMixin.test_create_connection_local_addr.<locals>.<lambda>�
local_addrrr�rn)r}r
r
�find_unused_portr'rrr&r9rr�r1)r*r
�port�frrZexpectedrr0r�!test_create_connection_local_addr}s

���z5EventLoopTestsMixin.test_create_connection_local_addrc	s�t����}�jj�fdd�g|j�Rd|ji�}��t��}�j�|�Wd�n1s\0Y��|j	j
t
j���t
|j�|j	j�Wd�n1s�0YdS)Ncst�jd�Srr	rr0rrr��rkzNEventLoopTestsMixin.test_create_connection_local_addr_in_use.<locals>.<lambda>r7)r}r
r'rrr��OSErrorr&r�r*�errno�
EADDRINUSE�assertInr�strerror)r*r
r:r-rr0r�(test_create_connection_local_addr_in_use�s

���*z<EventLoopTestsMixin.test_create_connection_local_addr_in_usec	s|j�G��fdd�dt�}tjddd�}|���d�d�d�����fdd	�}tj|d
d�}|��|��\}}|�d����_��	�j
�fd
d�||d������j�
�|�
�t�|�|�|���|��jd�|��jt���|����dS)Ncs,eZdZ��fdd�Z��fdd�Z�ZS)zAEventLoopTestsMixin.test_connect_accepted_socket.<locals>.MyProtocst��|����j�dSr)rTrRr�r�r-)rWr'rrrR�szQEventLoopTestsMixin.test_connect_accepted_socket.<locals>.MyProto.connection_lostcst��|�|j���dSr)rTrLr9rUrJ)rW�expected_responserrrL�szOEventLoopTestsMixin.test_connect_accepted_socket.<locals>.MyProto.data_received)r3r4r5rRrLrYr)rBr'rVrrS�srS�r4rrn)Zbacklogs	test datasrogerc
sxzDt��}�dur��|�}|���|���|�d��|��Wn.tyr}ztd|�WYd}~n
d}~00dS)N�cz8Failure in client thread in test_connect_accepted_socket)r�Zwrap_socket�connect�sendallr�r1�	Exception�print)Zcsockr.)r_�
client_ssl�message�responserrr�s



�z@EventLoopTestsMixin.test_connect_accepted_socket.<locals>.clientT)r�Zdaemonrics�Srrr��protorrr��rkzBEventLoopTestsMixin.test_connect_accepted_socket.<locals>.<lambda>rrP)r'r6r��
create_server�getsocknamer�r�r�Zacceptr&�connect_accepted_socketr�r9r1r	Zjoin_threadr�Zis_aliver�r:r;rI)	r*Z
server_sslrIrSZlsockr�threadZconn�_r)r_rIrBr'rJrMrKr�test_connect_accepted_socket�s4

��

z0EventLoopTestsMixin.test_connect_accepted_socketcCsLtjdkr,tjdkr,t|jtj�r,t�d��t	�
�}t	��}|�||�dS)Nr)rlrz=SSL not supported with proactor event loops before Python 3.5)
rr�version_info�
isinstancer'rZBaseProactorEventLoop�unittest�SkipTestr}Zsimple_server_sslcontextZsimple_client_sslcontextrS)r*Zserver_contextZclient_contextrrr� test_ssl_connect_accepted_socket�s
���z4EventLoopTestsMixin.test_ssl_connect_accepted_socketcCsdt��}|�|j�|jjt|tjd�}|�t	d��|j�
|�Wd�n1sV0YdS)N)Zssl_handshake_timeoutz1ssl_handshake_timeout is only meaningful with ssl)r��
addCleanupr1r'rPrSr	ZLOOPBACK_TIMEOUT�assertRaisesRegexr�r&)r*�sock�cororrr�9test_connect_accepted_socket_ssl_timeout_for_plain_socket�s��zMEventLoopTestsMixin.test_connect_accepted_socket_ssl_timeout_for_plain_socketzasyncio.base_events.socketc	s��fdd����fdd�}t|�}�tjkrDdd�|D�|��j_ndd�|D�|��j_|�j_t���j_	t���j_
�j��fdd	�|d
�}�j�|�}��
|j�dd�|jD�}��||�dS)
Nc�s>�tjkr �tjdd||ffgS�tjdd||ddffgSdS)Nr��r)r��AF_INETZSOCK_STREAM)�hostr9r��kw)�familyrr�getaddrinfo�s
zEEventLoopTestsMixin.create_server_multiple_hosts.<locals>.getaddrinfocs�j��|i|���Sr)r'�create_task)r��kwds)rcr*rr�getaddrinfo_task�szJEventLoopTestsMixin.create_server_multiple_hosts.<locals>.getaddrinfo_taskcSsg|]}|df�qS)�Pr�rgr`rrr�
<listcomp>�szDEventLoopTestsMixin.create_server_multiple_hosts.<locals>.<listcomp>cSsg|]}|dddf�qS)rgrrrhrrrri�scs
t�j�Srr	rr0rrr��rkzBEventLoopTestsMixin.create_server_multiple_hosts.<locals>.<lambda>rgcSsh|]}|��d�qS)r)�
getsockbyname)rgr[rrr�	<setcomp>�rkzCEventLoopTestsMixin.create_server_multiple_hosts.<locals>.<setcomp>)rur�r_rjr%r'rcr�MockZ_start_serving�
_stop_servingrNr&rYr1�socketsr�)	r*rbZhostsZ	mock_sockrfZunique_hostsr:�serverZserver_hostsr)rbrcr*r�create_server_multiple_hosts�s$
��z0EventLoopTestsMixin.create_server_multiple_hostscCs|�tjgd��dS)N)�1.2.3.4z5.6.7.8rq)rpr�r_r0rrr�&test_create_server_multiple_hosts_ipv4�s�z:EventLoopTestsMixin.test_create_server_multiple_hosts_ipv4cCs|�tjgd��dS)N)�::1z::2rs)rpr��AF_INET6r0rrr�&test_create_server_multiple_hosts_ipv6s�z:EventLoopTestsMixin.test_create_server_multiple_hosts_ipv6cs&t|j��|j��fdd�dd�}|j�|�}|�t|j�d�|jd}|��\}}|�|d�t��}|�	d|f�|�
d�|j��j�|�d�j�t
�|j�fd	d��|�d
�j�|��j�d��|�d�j�d�d��j��|j��j�|�d
�j�|��|��dS)Ncs�SrrrrLrrr�rkz8EventLoopTestsMixin.test_create_server.<locals>.<lambda>�0.0.0.0rrnr4�xxxrBcs
�jdkSr��r;rrLrrr�rkrlr�rrP)rSr'rNr&r�rIrnrOr�rErFr=r:r}r�r;rr9rr1r>�r*r:ror[r`r9rrrLr�test_create_servers.


�
z&EventLoopTestsMixin.test_create_server�SO_REUSEPORTzNo SO_REUSEPORTcs�t|j��|j��fdd�dd�}|j�|�}|�t|j�d�|jd}|�|�t	j
t	j��|��t
�|j�t|j��|jj�fdd�dddd�}|j�|�}|�t|j�d�|jd}|�|�t	j
t	j��|��dS)	Ncs�SrrrrLrrr�-rkzCEventLoopTestsMixin.test_create_server_reuse_port.<locals>.<lambda>rvrrncs�SrrrrLrrr�:rkT)Z
reuse_port)rSr'rNr&r�rIrnr�Z
getsockoptr�Z
SOL_SOCKETr{r1r}r~r�)r*r:ror[rrLr�test_create_server_reuse_port)s6
�
��
�
��z1EventLoopTestsMixin.test_create_server_reuse_portcsDt���|��fdd��|jj|�fi|��}|j�|�}|�fS)Ncstj���ot���Sr)r��path�exists�unlinkr�r}rrr�Erkz7EventLoopTestsMixin._make_unix_server.<locals>.<lambda>)r}Zgen_unix_socket_pathrYr'�create_unix_serverr&)r*�factory�kwargsr:rorr�r�_make_unix_serverCs
z%EventLoopTestsMixin._make_unix_servercs�t|jd��|��fdd��\}}|�t|j�d�t�tj�}|�|�|�	d�|j�
�j�|�d�j�t
�|j�fdd��|�d�j��j��|j�
�j�|�d	�j�|��|��dS)
Nrics�SrrrrLrrr�Orkz=EventLoopTestsMixin.test_create_unix_server.<locals>.<lambda>rnrwrBcs
�jdkSr�rxrrLrrr�XrkrlrP)rSr'r�r�rIrnr��AF_UNIXrErFr&r=r:r}r�r;r9r1r>)r*ror}rrrLr�test_create_unix_serverLs


z+EventLoopTestsMixin.test_create_unix_serverr�zNo UNIX Socketsc	s�t|jd��t��}|�b|jj�fdd�d|d�}|�td��|j�|�Wd�n1sb0YWd�n1s�0YdS)Nrics�SrrrrLrrr�mrkzOEventLoopTestsMixin.test_create_unix_server_path_socket_error.<locals>.<lambda>z/test�r[z3path and sock can not be specified at the same time)rSr'r�r�rZr�r&)r*r[r:rrLr�)test_create_unix_server_path_socket_errorhs�z=EventLoopTestsMixin.test_create_unix_server_path_socket_errorcCs,t�tj�}|jtjO_|�||�|Sr)r�
SSLContextZPROTOCOL_TLS_SERVER�options�OP_NO_SSLv2Zload_cert_chain)r*�certfile�keyfile�
sslcontextrrr�_create_ssl_contextssz'EventLoopTestsMixin._create_ssl_contextc
CsX|�||�}|jj|dd|d�}|j�|�}|jd}|��\}}	|�|d�|||	fS)Nr4rr)r�r'rNr&rnrOr�)
r*r�r�r�r�r:ror[r`r9rrr�_make_ssl_serverys
z$EventLoopTestsMixin._make_ssl_servercCs|�||�}|j||d�S)Nr)r�r�)r*r�r�r�r�rrr�_make_ssl_unix_server�sz)EventLoopTestsMixin._make_ssl_unix_servercs�t|jd��|��fdd�tjtj�\}}}|jjt||t��d�}|j�	|�\}}|�
d�|j�	�j�|�d�j
�t�|j�fdd��|�d�j�|j|||fd	��j��|j�	�j�|�d
�j
�|��|��dS)Nrics�SrrrrLrrr��rkz<EventLoopTestsMixin.test_create_server_ssl.<locals>.<lambda>rrwrBcs
�jdkSr�rxrrLrrr��rkrlr0rP)rSr'r�r}�ONLYCERT�ONLYKEYrr6r#r&rUr=r�r:r�r;rr9r1r>)r*ror`r9�f_crrrrLr�test_create_server_ssl�s&�
�

z*EventLoopTestsMixin.test_create_server_sslcs�t|jd��|��fdd�tjtj�\}}|jjt|t��dd�}|j�	|�\}}|�
d�|j�	�j�|�d�j
�t�|j�fdd��|�d	�j��j��|j�	�j�|�d
�j
�|��|��dS)Nrics�SrrrrLrrr��rkzAEventLoopTestsMixin.test_create_unix_server_ssl.<locals>.<lambda>r^�rr5rwrBcs
�jdkSr�rxrrLrrr��rkrlrP)rSr'r�r}r�r�rr6r#r&rUr=r�r:r�r;r9r1r>)r*ror}r�rrrrLr�test_create_unix_server_ssl�s&�
�

z/EventLoopTestsMixin.test_create_unix_server_sslc
s(t|jd��|��fdd�tj�\}}}t�tj�}|jtj	O_tj
|_t|d�r\d|_
|jjt|||d�}tj�|jd��~t���J|�tjd��|j�|�Wd�n1s�0YWd�n1s�0Yt�|j�Wd�n1�s0Y|��j�|��dS)	Nrics�SrrrrLrrr��rkzJEventLoopTestsMixin.test_create_server_ssl_verify_failed.<locals>.<lambda>�check_hostnameTr�call_exception_handler�(?i)certificate.verify.failed)rSr'r�r}�SIGNED_CERTFILErr��PROTOCOL_TLS_CLIENTr�r��
CERT_REQUIRED�verify_moder&r�rrr'�objectr)rZr(r&r~�assertIsNoner9r1�r*ror`r9�sslcontext_clientr�rrLr�$test_create_server_ssl_verify_failed�s*�

�
�H,z8EventLoopTestsMixin.test_create_server_ssl_verify_failedc
s&t|jd��|��fdd�tj�\}}t�tj�}|jtj	O_tj
|_t|d�rZd|_
|jjt||dd�}tj�|jd��~t���J|�tjd	��|j�|�Wd�n1s�0YWd�n1s�0Yt�|j�Wd�n1�s0Y|��j�|��dS)
Nrics�SrrrrLrrr��rkzOEventLoopTestsMixin.test_create_unix_server_ssl_verify_failed.<locals>.<lambda>r�TZinvalidr�r�r�)rSr'r�r}r�rr�r�r�r�r�r�r&r�rrr'r�r)rZr(r&r~r�r9r1)r*ror}r�r�rrLr�)test_create_unix_server_ssl_verify_failed�s,�

�
�H,z=EventLoopTestsMixin.test_create_unix_server_ssl_verify_failedc
s*t|jd��|��fdd�tj�\}}}t�tj�}|jtj	O_tj
|_|jtj
d�t|d�rjd|_|jjt|||d�}tj�|jd��rt���J|�tjd	��|j�|�Wd�n1s�0YWd�n1s�0YWd�n1�s0Y|��j�|��dS)
Nrics�SrrrrLrrr�rkzIEventLoopTestsMixin.test_create_server_ssl_match_failed.<locals>.<lambda>�rr�Trr�z=IP address mismatch, certificate is not valid for '127.0.0.1')rSr'r�r}r�rr�r�r�r�r�r��load_verify_locations�
SIGNING_CAr&r�rrr'r�r)rZZCertificateErrorr&r�r9r1r�rrLr�#test_create_server_ssl_match_faileds0�
�
�
�hz7EventLoopTestsMixin.test_create_server_ssl_match_failedcs�t|jd��|��fdd�tj�\}}t�tj�}|jtj	O_tj
|_|jtj
d�t|d�rhd|_|jjt||dd�}|j�|�\}}|j��j��j��|��|��|j��j�dS)	Nrics�SrrrrLrrr�%rkzJEventLoopTestsMixin.test_create_unix_server_ssl_verified.<locals>.<lambda>r�r�T�	localhostr�)rSr'r�r}r�rr�r�r�r�r�r�r�r�r&r�rr&r=r9r1r>)r*ror}r�r�rrrrLr�$test_create_unix_server_ssl_verified s(�

�
z8EventLoopTestsMixin.test_create_unix_server_ssl_verifiedcs�t|jd��|��fdd�tj�\}}}t�tj�}|jtj	O_tj
|_|jtj
d�t|d�rjd|_|jjt|||dd�}|j�|�\}}|j��j�|j|||ftjd	��j��|��|��|j��j�dS)
Nrics�SrrrrLrrr�?rkzEEventLoopTestsMixin.test_create_server_ssl_verified.<locals>.<lambda>r�r�Tr�r�)rr)rSr'r�r}r�rr�r�r�r�r�r�r�r�r&r�rr&r=rZPEERCERTr9r1r>)r*ror`r9r�r�rrrrLr�test_create_server_ssl_verified;s.�

��
z3EventLoopTestsMixin.test_create_server_ssl_verifiedc	s�|j���G�fdd�dt�}t�d�}|jj||d�}|j�|�}|jd}|�|��|���|�	�\}}|�|d�t��}|�
d|f�|�d�|��|��dS)	NcseZdZ��fdd�Z�ZS)z@EventLoopTestsMixin.test_create_server_sock.<locals>.TestMyProtocst��|���|�dSr�rTrFrDrE)rWrMrrrF]szPEventLoopTestsMixin.test_create_server_sock.<locals>.TestMyProto.connection_maderXrrLrVr�TestMyProto\sr��rvrr�rrvr4rw)
r'r<rSr�rNr&rnr�r�rOrEr,r1)	r*r��sock_obr:ror[r`r9rrrLr�test_create_server_sockYs



z+EventLoopTestsMixin.test_create_server_sockcCs�t�d�}|jjt|d�}|j�|�}|jd}|��\}}|jjt||d�}|�t��}|j�|�Wd�n1sz0Y|�	|j
jtj�|�
�dS)Nr�r�r�r`r9)r�rNr'rSr&rnrOr�r<r�r*r=r>r1)r*r�r:ror[r`r9r-rrr�test_create_server_addr_in_useps

*z2EventLoopTestsMixin.test_create_server_addr_in_usezIPv6 not supported or enabledc	
s<|j���G�fdd�dt�}d}z*t��}|jj|d|d�}|j�|�}Wq�ty�}z<|jtj	kr�|d7}|�
d|�WYd}~q"n�WYd}~q"d}~00q�q"t��}|�d|f�|�
d�|j���}|j��|��|j���t�tj�}|�d	|f�|�
d�|j���}|j��|��|��dS)
NcseZdZ��fdd�Z�ZS)zFEventLoopTestsMixin.test_create_server_dual_stack.<locals>.TestMyProtocst��|���|�dSrr�rE)rW�f_protorrrF�szVEventLoopTestsMixin.test_create_server_dual_stack.<locals>.TestMyProto.connection_maderXr�r�rVrr��sr�rr�rnrr4rwrs)r'r<rSr
r8rNr&r<r=r>ZassertGreaterEqualr�rEr,r9r1rt)	r*r�Z	try_countr9r:roZexrrMrr�r�test_create_server_dual_stacks8





z1EventLoopTestsMixin.test_create_server_dual_stackcCs�|j�tdd�}|j�|�}|jd}|��\}}t��}|�d|f�|�d�|�	�|�	�t��}|�
t|jd|f�|�	�dS)Nrvrr4rw)r'rNrSr&rnrOr�rEr,r1r��ConnectionRefusedErrorryrrr�test_server_close�s

�z%EventLoopTestsMixin.test_server_closec
s�G�fdd�dt�}�jj|||d�}�j�|�\}�|�d�}t�|tjtjB�\}}��	|t
j���	�|���d�j
����j|��jj�fdd�||fd�}�j�|�\}	���	|	t
j���	�t���d�j
����j|	�|	�d	�t��j�fd
d����d�j�t��j�fdd����d
�j���|	�d��|	���j��j���d�j
��j��dS)Ncs*eZdZ��fdd�Z�fdd�Z�ZS)zOEventLoopTestsMixin._test_create_datagram_endpoint.<locals>.TestMyDatagramProtocst�j�jd�dSr)rTr@r')Z
inner_self)rWr*rrr@�szXEventLoopTestsMixin._test_create_datagram_endpoint.<locals>.TestMyDatagramProto.__init__cs$t��||�|j�d||�dS)Nsresp:)rTr`r9�sendtor^rVrrr`�szaEventLoopTestsMixin._test_create_datagram_endpoint.<locals>.TestMyDatagramProto.datagram_received)r3r4r5r@r`rYrr0rVr�TestMyDatagramProto�sr�)r7rbr�r[cst�jd�Sr�rZr'rr0rrr��rkzDEventLoopTestsMixin._test_create_datagram_endpoint.<locals>.<lambda>)Zremote_addrrwcs�jSrrxr)rorrr��rkrlcs�jSrrxr)rrrr��rk�rP)rZr'�create_datagram_endpointr&rr��getnameinfoZNI_NUMERICHOSTZNI_NUMERICSERVr�rr�r�r:r�r9r�r}r�r;rr1r>)
r*r7rbr�r\Zs_transportr�r`r9r9r)rr*ror�_test_create_datagram_endpoint�s@�
�
�
z2EventLoopTestsMixin._test_create_datagram_endpointcCs|�dtj�dS)NrC)r�r�r_r0rrr�test_create_datagram_endpoint�sz1EventLoopTestsMixin.test_create_datagram_endpointcCs|�dtj�dS)N)rsr)r�r�rtr0rrr�"test_create_datagram_endpoint_ipv6�sz6EventLoopTestsMixin.test_create_datagram_endpoint_ipv6cs�d}d}�j��jj|dtji��}|D]H\}}}}}z(tj|||d�}|�d�|�|�WnYq(0q~q(ds~Jd���jj�fdd�|d�}	�j�|	�\}
}��|
t	j
���|t�|
���j�|j
�dS)	NrC�type)rbr�rMFzCan not create socket.cst�jd�Srr�rr0rrr�rkzHEventLoopTestsMixin.test_create_datagram_endpoint_sock.<locals>.<lambda>r�)r'r&rcr�Z
SOCK_DGRAMr�Zbindr�r�rr�rZr1r>)r*r[Z
local_addressZinfosrbr�rMZcnamerr:rrrr0r�"test_create_datagram_endpoint_sock�s4���
�z6EventLoopTestsMixin.test_create_datagram_endpoint_sockcCsf|��}t|tj�s&|��|�d�|�d|j�|��|�d|j�|�|j	�|�|j
�dS)Nz#loop is not a BaseSelectorEventLooprnr)r{rUrZBaseSelectorEventLoopr1ZskipTestr�Z
_internal_fdsr�Z_csockZ_ssockr?rrr�test_internal_fdss
z%EventLoopTestsMixin.test_internal_fdsrzDon't support pipes for Windowscs�t�jd��t��\}}t�|dd�����fdd�}�j�|��t�|d�t�	�j�fdd����
d	�j�t�|d
�t�	�j�fdd����
dd
g�j���
d�j�t�
|��j��j���
gd��j����j�d��dS)Nri�rbr�c�s^�j��fdd���IdH\}}��|����|�j���ddg�j���d�j�dS)Ncs�SrrrrLrrr�!rkzEEventLoopTestsMixin.test_read_pipe.<locals>.connect.<locals>.<lambda>r8rBr�r'�connect_read_piper�r9r�r:r;�r��p��pipeobjrMr*rrrEs�z3EventLoopTestsMixin.test_read_pipe.<locals>.connect�1cs
�jdkSr�rxrrLrrr�*rkz4EventLoopTestsMixin.test_read_pipe.<locals>.<lambda>rn�2345cs
�jdkS�NrrxrrLrrr�.rkr8rBr�r8rBrMrP�pipe)rbr'r�r��io�openr&rUr}r�r�r;r:r1r>rr9r)r*�rpipe�wpiperErr�r�test_read_pipes$

�z"EventLoopTestsMixin.test_read_pipecs�|���t�d��t�d��t��\}}t�|dd��t�|dd�������fdd�}��|��\}}���|�	dt
|��|�	dt
|��������d|_d|_dS)Nrir�r�r�c�sD���fdd���IdH\}}���fdd���IdH\}}||fS)Ncs�Srrr��
read_protorrr�GrkzSEventLoopTestsMixin.test_unclosed_pipe_transport.<locals>.connect.<locals>.<lambda>cs�Srrr��write_protorrr�Irk)r��connect_write_pipe)�read_transportrR�write_transport�r'r�ZrpipeobjZwpipeobjr�rrrEEs��zAEventLoopTestsMixin.test_unclosed_pipe_transport.<locals>.connectr�)r{rbrdr�r�r�r�r&r1r?�reprZ_pipe)r*r�r�rEr�r�rr�r�test_unclosed_pipe_transport9s

z0EventLoopTestsMixin.test_unclosed_pipe_transportcst�jd��t��\}}t�|dd�����fdd�}�j�|��t�|d�t�	�j�fdd����
d	�j�t�|d
�t�	�j�fdd����
dd
g�j���
d�j�t�
|��j�
��j��j���
gd��j����j�d��dS)Nrir�rc�s^�j��fdd���IdH\}}��|����|�j���ddg�j���d�j�dS)Ncs�SrrrrLrrr�drkzKEventLoopTestsMixin.test_read_pty_output.<locals>.connect.<locals>.<lambda>r8rBrr�r��Zmaster_read_objrMr*rrrEcs�z9EventLoopTestsMixin.test_read_pty_output.<locals>.connectr�cs�jSrrxrrLrrr�nrkz:EventLoopTestsMixin.test_read_pty_output.<locals>.<lambda>rnr�cs
�jdkSr�rxrrLrrr�rrkr8rBrr�r�)rbr'r��openptyr�r�r&rUr}r�r�r;r:r1r9r>rr)r*�master�slaverErr�r�test_read_pty_output[s&


�z(EventLoopTestsMixin.test_read_pty_outputcs6t��\�}t�|dd�}t|jd��|j��fdd�|�}|j�|�\}}|�|��|�|�j	�|�
d�j�|�d�t
���fdd	��t�|j��fd
d��|�
d��|�d�t�|j��fdd��|�
d
��|�
d�j�t���|��j	�d���j	��|j��j�|�
d�j�dS)N�wbr�rics�SrrrrLrrr��rkz5EventLoopTestsMixin.test_write_pipe.<locals>.<lambda>rBr�cst��d�}||7}t|�Sr��r�r�rI�rK�chunk)r�rrr��sz3EventLoopTestsMixin.test_write_pipe.<locals>.readercs���dkSr�rr�rKr�rrr��rkr�cs���dkSr�rrr�rrr��rk�12345r�rP)r�r�r�r�rdr'r�r&r�r9r�r:rUr�r}r�r1rrr>)r*r�r�rEr9r�r)rKrMr�r�r�test_write_pipe~s,



z#EventLoopTestsMixin.test_write_pipecs�t��\}}|�d�t�|��dd�}t|jd��|j��fdd�|�}|j�	|�\}}|�
|��|�
|�j�|�d�j
�|�d�|j�	|j�|d��}|�d|�|��|j�	�j�|�d	�j
�dS)
NFr�r�rics�SrrrrLrrr��rkzIEventLoopTestsMixin.test_write_pipe_disconnect_on_close.<locals>.<lambda>rBr�rP)r�r�r�r�r��detachrdr'r�r&r�r9r�r:rU�	sock_recvr1r>)r*ZrsockZwsockr�rEr9r�rKrrLr�#test_write_pipe_disconnect_on_close�s

z7EventLoopTestsMixin.test_write_pipe_disconnect_on_closerr�csBt��\�}t�|dd�}t|jd��|j��fdd�|�}|j�|�\}}|�|��|�|�j	�|�
d�j�|�d�t
���fdd	��tj|j��fd
d�tjd�|�
d��|�d�tj|j��fd
d�tjd�|�
d��|�
d�j�t���|��j	�d���j	��|j��j�|�
d�j�dS)Nr�rrics�SrrrrLrrr��rkz4EventLoopTestsMixin.test_write_pty.<locals>.<lambda>rBr�cst��d�}||7}t|�Sr�r�r��r�rrr��sz2EventLoopTestsMixin.test_write_pty.<locals>.readercs���dkSr�rrr�rrr��rk�Ztimeoutr�cs���dkSr�rrr�rrr��rkr�r�rP)r�r�r�r�rdr'r�r&r�r9r�r:rUr�r}r�r	�
SHORT_TIMEOUTr1rrr>)r*r��slave_write_objrEr9r�r)rKr�rMr�r�test_write_pty�s4
�
�

z"EventLoopTestsMixin.test_write_ptyc
s�t��\�}t�|�}t�|�t�|dd�}t|jd��|j�	�fdd�|�}|j�
|�\}}|�|��|�|�j�|�
ddg�j�|�
d�j�t�|dd�}t|jd��|j��fd	d�|�}|j�
|�\}	}|�|��|�|	�j�|�
d�j�t���fd
d��|	�d�tj|j��fd
d�tjd�|�
d��|�
ddg�j�|�
d�j�t��d�tj|j�fdd�tjd�|�
ddg�j�|�
d�j�|�
d�j�|	�d�tj|j��fdd�tjd�|�
d��|�
ddg�j�|�
d�j�t��d�tj|j�fdd�tjd�|�
ddg�j�|�
d�j�|�
d�j�t���|��|j�
�j�|�
gd��j�|	��|j�
�j�|�
d�j�dS)Nr�rrics�Srrrr�rrr��rkz<EventLoopTestsMixin.test_bidirectional_pty.<locals>.<lambda>r8rBr�cs�Srrrr�rrr��rkcst��d�}||7}t|�Sr�r�r�r�rrr�sz:EventLoopTestsMixin.test_bidirectional_pty.<locals>.readerr�cs���dkSr�rrr�rrr�
rkr��acs
�jdkSr�rxrr�rrr�rkrnr�cs���dkSr�rrr�rrr�rkr�sbcdecs
�jdkSr�rxrr�rrr�"rkrr�rP)r�r��dup�ttyZsetrawr�r�rbr'r�r&r�r9r�r:r;rdr�r�rUr}r�r	r�r1r>)
r*Z
read_slaveZwrite_slaveZslave_read_objZread_connectr�r�r�Z
write_connectr�r)rKr�r�r�r�r�test_bidirectional_pty�sz

��
��
��

�z*EventLoopTestsMixin.test_bidirectional_ptycs�t��\}}|�d��j��j�|d���t�dd�}|durL��|j���fdd�}t	�
�}�j�|��}�j��t	�
�|}��|d���
|��d���tj�j�|durƈ�|j��j�|�|��|��dS)NFrn�ovc�sZzHz�j��j��IdHWntjy6d}Yn0d}W�j��n�j��0|S)N�	cancelled)r'r�r�r�CancelledErrorr�)r��r:r*rr�main;s
z:EventLoopTestsMixin.test_prompt_cancellation.<locals>.mainr�r�)r�r�r�r'rdr��getattrr�Zpendingr��	monotonicr�Z
assertLessr��resultr�rr�r�rmr1)r*r�r�r�r�r�r��elapsedrr�r�test_prompt_cancellation3s&

z,EventLoopTestsMixin.test_prompt_cancellationcsh��fdd�}�jj�d�j_|�j_�fdd�}�j�|�����jjd�jj�jjjjd��dS)Ncs�jjd7_��dSr�)r'�_run_once_counterr�Z
orig_run_oncer*rr�	_run_onceWsz<EventLoopTestsMixin.test_timeout_rounding.<locals>._run_oncerc�sZ�j}t�d�IdHt�d�IdHt�d�IdHt�d�IdHt�d�IdHdS)Nr�g-C��6?g���ư>g:�0�yE>g�����|�=)r'rr�rir0rr�wait_sz7EventLoopTestsMixin.test_timeout_rounding.<locals>.wait�)Zclock_resolutionZselector)	r'rrr&ZassertLessEqualZ_clock_resolutionZ	_selectorrWr3)r*rrrrr�test_timeout_roundingVs
��z)EventLoopTestsMixin.test_timeout_roundingcCsx|��}dd�}t��\}}|�|j�|�|j�|�||�|�||�|��|�|�|��|�|�	|��dS)NcSsdSrrrrrrr�rrkzCEventLoopTestsMixin.test_remove_fds_after_closing.<locals>.<lambda>)
r{r�r�rYr1r�r�r�r�r��r*r'r�r�r�rrr�test_remove_fds_after_closingpsz1EventLoopTestsMixin.test_remove_fds_after_closingcCs�|��}dd�}t��\}}|�|j�|�|j�|��|�t��|�||�Wd�n1sh0Y|�t��|�||�Wd�n1s�0YdS)NcSsdSrrrrrrr�~rkz@EventLoopTestsMixin.test_add_fds_after_closing.<locals>.<lambda>)	r{r�r�rYr1r�r�r�r�rrrr�test_add_fds_after_closing|s*z.EventLoopTestsMixin.test_add_fds_after_closingcsP�fdd�}|�j�}��t���j�|�Wd�n1sB0YdS)Nc�s�j��dSr)r'r1rir0rr�
close_loop�szEEventLoopTestsMixin.test_close_running_event_loop.<locals>.close_loop)r'r�r�r&)r*r
r\rr0r�test_close_running_event_loop�s
z1EventLoopTestsMixin.test_close_running_event_loopcCsJ|j��dd�}dd�}|�}|�|j�|�t��|j��Wd�n1sV0Y|�t��&|j��}|j�|�Wd�n1s�0Y|�t��|j�|�Wd�n1s�0Y|�t��|j�	|�Wd�n1�s0Y|�t��|j�
d|�Wd�n1�s>0Y|�t��(|j�|j��d|�Wd�n1�s�0Y|�t��|j�
|�Wd�n1�s�0Y|�t�� |j�tj|�Wd�n1�s�0Y|�t��*|j�d|���}t|�Wd�n1�s<0YdS)Nc�sdSrrrrrr�test�sz,EventLoopTestsMixin.test_close.<locals>.testcSsdS�NFrrrrrr��rkz0EventLoopTestsMixin.test_close.<locals>.<lambda>g�?g)r'r1rYr�r�r�r<r&r�r�r��call_atr�rdr�r��SIGTERMr�r2�next)r*r�funcr\Zfut�itrrr�
test_close�s2
(
**,.8,0zEventLoopTestsMixin.test_close)T)TN)TN)NN)N)N)N)Yr3r4r5rzrr�r�r�r�r�r�r�r�r�r�r�rV�
skipUnlessr&r�r�r�r�rrr
Zskip_unless_bind_unix_socketrrrr.�skipIfrr3r6r;rArSrXr]rr'rprrrurzr�r|r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�ZIPV6_ENABLEDr�r�r�r�r�r�r�rrr�r�r�r�r�r	�requires_mac_verr�r�rrrr	rrrYrrrVrry�s�		

+




�
!�

�
%
	

6


$
	










(0
�
 �
 �
!�
%�
�
'�
F#ryc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Ze�
ejdkd�dd��Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#S)$�SubprocessTestsMixincCs,tjdkr|�|t�n|�tj|�dS�Nr)rrr�rr�r�r�r*rsrrr�check_terminated�s
z%SubprocessTestsMixin.check_terminatedcCs,tjdkr|�|t�n|�tj|�dSr)rrr�rr�r�r�rrrr�check_killed�s
z!SubprocessTestsMixin.check_killedcCs�tj�tj�t�d�}|j�t�t	|j�t
j|�}|j�|�\}}|�
|t	�|j�|j�|�d|j�|�d�}|�d�|j�|jd���t���|��Wd�n1s�0Y|j�|j�|�|j�|�d|jd�dS)N�echo.pyrBr�Python The Winnerrn)r�r}r��dirname�__file__r'�subprocess_execr1r2rfr�
executabler&r�r=r�r:�get_pipe_transportrUrtrr}r)r1rprrsrK�r*�progrE�transprM�stdinrrr�test_subprocess_exec�s"�


&z)SubprocessTestsMixin.test_subprocess_execcCs6tj�tj�t�d�}|j�t�t	|j�t
j|�}|j�|�\}}|�
|t	�|j�|j�|�d|j�|�d�}|�d�|j�|jd���|jd��|�d|jd�|�d�|j�|jd���|�d|jd�t���|��Wd�n1�s0Y|j�|j�|�|j�dS)NrrBrsPython rns
The Winnerr)r�r}r�rrr'r r1r2rfrr!r&r�r=r�r:r"rUrtr�clearrKr}r)r1rprrsr#rrr�test_subprocess_interactive�s*�



(z0SubprocessTestsMixin.test_subprocess_interactivecCs�|j�t�t|j�d�}|j�|�\}}|�|t�|j�|j�|�d��	�|j�|j
�|�d|j�|�
tdd�|j��D���|�|jd�d�d�|�|jdd	�|�	�dS)
Nzecho Pythonrcss|]}|��VqdSr)r>)rgr:rrr�	<genexpr>�rkz=SubprocessTestsMixin.test_subprocess_shell.<locals>.<genexpr>rns
sPythonrork)r'�subprocess_shellr1r2rfr&r�r=r"r1rpr�rsr��allrr�valuesrK�rstrip�r*rEr%rMrrr�test_subprocess_shell�s�z*SubprocessTestsMixin.test_subprocess_shellcCsd|jjt�t|j�ddddd�}|j�|�\}}|�|t�|j�|j�|�d|j	�|�
�dS)N�exit 7�r&�stdout�stderr��r'r+r1r2rfr&r�rpr�rsr1r/rrr�test_subprocess_exitcodes�z-SubprocessTestsMixin.test_subprocess_exitcodecCs�|jjt�t|j�ddddd�}|j�|�\}}|�|t�|�|�d��|�|�d��|�|�d��|j�|j	�|�
d|j�|�|���dS)Nr1r2rrnror5)
r'r+r1r2rfr&r�r�r"rpr�rsr1r/rrr�"test_subprocess_close_after_finishs�z7SubprocessTestsMixin.test_subprocess_close_after_finishcCs�tj�tj�t�d�}|j�t�t	|j�t
j|�}|j�|�\}}|�
|t	�|j�|j�|��|j�|j�|�|j�|��dS�Nr)r�r}r�rrr'r r1r2rfrr!r&r�r=r�rprrsr1�r*r$rEr%rMrrr�test_subprocess_kills�z)SubprocessTestsMixin.test_subprocess_killcCs�tj�tj�t�d�}|j�t�t	|j�t
j|�}|j�|�\}}|�
|t	�|j�|j�|��|j�|j�|�|j�|��dSr9)r�r}r�rrr'r r1r2rfrr!r&r�r=Z	terminaterprrsr1r:rrr�test_subprocess_terminate,s�z.SubprocessTestsMixin.test_subprocess_terminaterzDon't have SIGHUPc
Cs�t�tjtj�}z�tj�tj�t�d�}|j�	t
�t|j�t
j|�}|j�|�\}}|�|t�|j�|j�|�tj�|j�|j�|�tj|j�|��Wt�tj|�nt�tj|�0dSr9)r��SIGHUP�SIG_DFLr�r}r�rrr'r r1r2rfrr!r&r�r=Zsend_signalrpr�rsr1)r*Zold_handlerr$rEr%rMrrr�test_subprocess_send_signal<s�
z0SubprocessTestsMixin.test_subprocess_send_signalcCs�tj�tj�t�d�}|j�t�t	|j�t
j|�}|j�|�\}}|�
|t	�|j�|j�|�d�}|�d�|j�|j�|��|�d|jd�|�|jd�d�|jd�|�d|j�dS)N�echo2.pyr�test�OUT:testrnrosERR:test)r�r}r�rrr'r r1r2rfrr!r&r�r=r"rUrpr1r�rKr�rrsr#rrr�test_subprocess_stderrTs�

z+SubprocessTestsMixin.test_subprocess_stderrcCs�tj�tj�t�d�}|jjt�t	|j�t
j|tj
d�}|j�|�\}}|�|t	�|j�|j�|�d�}|�|�d��|�|�d��|�d�|j�|j�|�|jd�d�|jd�|�d|jd�|��|�d|j�dS)	Nr@)r4rrnrorAsOUT:testERR:testrk)r�r}r�rrr'r r1r2rfrr!�
subprocessZSTDOUTr&r�r=r"rr�rUrpr�rKrr�r1rsr#rrr�)test_subprocess_stderr_redirect_to_stdoutis&
�

�z>SubprocessTestsMixin.test_subprocess_stderr_redirect_to_stdoutcCs\tj�tj�t�d�}|j�t�t	|j�t
j|�}|j�|�\}}|�
|t	�|j�|j�|�d�}|�d�}|�d�|j�|jd���|�d|jd�|��|j�|jd�|�d�|j�|jd���t
jdkr�|�d	|jd�n|�d
|jd�t���|��Wd�n1�s40Y|j�|j�|�|j�dS)Nzecho3.pyrrnrArBrwrorsERR:BrokenPipeErrorsERR:OSError)r�r}r�rrr'r r1r2rfrr!r&r�r=r"rUrtrr�rKr1rrrr}r)rprrs)r*r$rEr%rMr&r3rrr�#test_subprocess_close_client_stream�s0�





(z8SubprocessTestsMixin.test_subprocess_close_client_streamcCsf|jjt�t|j�dddddd�}|j�|�\}}|�|t�|j�|j�|�d|j	�|�
�dS)Nr1T)r&r3r4Zstart_new_sessionr5r6r/rrr�"test_subprocess_wait_no_same_group�s�z7SubprocessTestsMixin.test_subprocess_wait_no_same_groupcs��fdd�}��t��"�j�|dd��Wd�n1s>0Y��t��"�j�|dd��Wd�n1sz0Y��t��"�j�|dd��Wd�n1s�0YdS)Nc�s"�jjtjdfi|��IdHdS�N�pwd)r'r r�SubprocessProtocol)rer0rrrE�s��zGSubprocessTestsMixin.test_subprocess_exec_invalid_args.<locals>.connectT�Zuniversal_newlines���bufsize��shell�r�r�r'r&�r*rErr0r�!test_subprocess_exec_invalid_args�s00z6SubprocessTestsMixin.test_subprocess_exec_invalid_argscsd�fdd�	}��t��$�j�|ddg��Wd�n1sB0Y��t��"�j�|dd��Wd�n1s~0Y��t��"�j�|dd��Wd�n1s�0Y��t��"�j�|d	d
��Wd�n1s�0YdS)Nc�s*|sd}�jjtj|fi|��IdHdSrH)r'r+rrJ)�cmdrer0rrrE�s��zHSubprocessTestsMixin.test_subprocess_shell_invalid_args.<locals>.connectZlsz-lTrKrLrMFrO)NrQrRrr0r�"test_subprocess_shell_invalid_args�s200z7SubprocessTestsMixin.test_subprocess_shell_invalid_argsN)r3r4r5rrr'r)r0r7r8r;r<rVrrrr?rCrErFrGrSrUrrrrr�s"

!
rc@seZdZdd�ZdS)�SelectEventLoopTestscCst��Sr)r�SelectorEventLoopr0rrrr{�s�&SelectEventLoopTests.create_event_loopN�r3r4r5r{rrrrrV�srVc@s<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�ProactorEventLoopTestscCst��Sr)rZProactorEventLoopr0rrrr{�sz(ProactorEventLoopTests.create_event_loopcCst�d��dS�Nz(IocpEventLoop does not have add_reader()�rVrWr0rrrr��sz+ProactorEventLoopTests.test_reader_callbackcCst�d��dSr[r\r0rrr�test_reader_callback_cancel�sz2ProactorEventLoopTests.test_reader_callback_cancelcCst�d��dS�Nz(IocpEventLoop does not have add_writer()r\r0rrrr��sz+ProactorEventLoopTests.test_writer_callbackcCst�d��dSr^r\r0rrr�test_writer_callback_cancel�sz2ProactorEventLoopTests.test_writer_callback_cancelcCst�d��dSr[r\r0rrrr�sz4ProactorEventLoopTests.test_remove_fds_after_closingN)	r3r4r5r{r�r]r�r_rrrrrrZ�srZcs(eZdZ�fdd�Z�fdd�Z�ZS)�UnixEventLoopTestsMixincs,t���t��}|�|j�t�|�dSr)rTrzr�SafeChildWatcher�attach_loopr'�set_child_watcher�r*ZwatcherrVrrrz�s
zUnixEventLoopTestsMixin.setUpcst�d�t���dSr)rrcrTrr0rVrrr�s
z UnixEventLoopTestsMixin.tearDown)r3r4r5rzrrYrrrVrr`�sr`�KqueueSelectorcs\eZdZdd�Ze�dd�e�ej	�
d�d��fdd���Ze�dd��fd	d
��Z�Z
S)�KqueueEventLoopTestscCst�t���Sr)rrW�	selectorsrer0rrrr{�s�z&KqueueEventLoopTests.create_event_loopr�	Zopenbsdztest hangs on OpenBSDcst���dSr)rTr�r0rVrrr�sz)KqueueEventLoopTests.test_read_pty_outputcst���dSr)rTr�r0rVrrr�sz#KqueueEventLoopTests.test_write_pty)r3r4r5r{r	rrVrrrrr�r�rYrrrVrrf�s
�
rf�
EpollSelectorc@seZdZdd�ZdS)�EPollEventLoopTestscCst�t���Sr)rrWrgrir0rrrr{sz%EPollEventLoopTests.create_event_loopNrYrrrrrjsrj�PollSelectorc@seZdZdd�ZdS)�PollEventLoopTestscCst�t���Sr)rrWrgrkr0rrrr{ sz$PollEventLoopTests.create_event_loopNrYrrrrrlsrlc@seZdZdd�ZdS)rVcCst�t���Sr)rrWrgZSelectSelectorr0rrrr{(srXNrYrrrrrV$scOsdSrr)r�r�rrr�noop,srmcsheZdZ�fdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	e
�ee
jd�d�dd��Z�ZS)�HandleTestscs"t���t��|_d|jj_dSr�)rTrzrrlr'�	get_debug�return_valuer0rVrrrz2s

zHandleTests.setUpcCs`dd�}d}t�|||j�}|�|j|�|�|j|�|�|���|��|�	|���dS)NcWs|Srrr�rrrr�8sz)HandleTests.test_handle.<locals>.callbackr)
r�Handler'r��	_callback�_argsr�r�r�r�)r*r�r��hrrr�test_handle7szHandleTests.test_handlecCs\dd�}t��|_t��|j_t�|d|j�}|��|jj�t�	d�tj
||jd��dS)NcSs
t��dSr)r�rrrrr�Esz:HandleTests.test_callback_with_exception.<locals>.callbackrzException in callback.*)rJr*ZhandleZsource_traceback)rrlr'r�rrqZ_run�assert_called_withr}ZMockPattern�ANY�_source_traceback)r*r�rtrrr�test_callback_with_exceptionDs
�z(HandleTests.test_callback_with_exceptioncCs(t��}t�dd�d|j�}||d<dS)NcSsdSrrrrrrr�Wrkz1HandleTests.test_handle_weakref.<locals>.<lambda>rrt)�weakrefZWeakValueDictionaryrrqr')r*Zwdrtrrr�test_handle_weakrefUszHandleTests.test_handle_weakrefcCs�d|jj_t�td|j�}t�t�\}}|�t	|�d||f�|�
�|�t	|�d�|�t��t�
t�}Wd�n1s�0Yt�|d|j�}|�t	|�d||f�t�tdd�}t�|d	|j�}d
t�|�|f}|�t	|�|�tjtdd�}t�|d|j�}d
t�|�|f}|�t	|�|�tjdk�r�tj}t�|�}t�|�\}}t�|d|j�}d}d|}d|t�|�|f}|�t	|�|�dS)NFrmz<Handle noop(1, 2) at %s:%s>z<Handle cancelled>rz<Handle noop() at %s:%s>rnro)rlz%^<Handle noop\(1, 2\)\(3\) at %s:%s>$)�x)rorlz'^<Handle noop\(x=1\)\(2, 3\) at %s:%s>$)rl�z*<function HandleTests.test_handle_repr .*>z%functools.partialmethod\(%s, , \)\(\)z^<Handle %s at %s:%s>$)r'rorprrqrmr}�get_function_sourcer�r�r�ZassertWarns�DeprecationWarning�	coroutiner1r2�re�escapeZassertRegexrrTrn�test_handle_repr�
partialmethod)r*rt�filename�linenor�Zregex�methodZcb_regexrrrr�ZsV

��
�(
����
�zHandleTests.test_handle_reprcCs�d|jj_t}t��jd}t�t	d|j�}t
�t	�\}}|�t
|�d||||f�|��|�t
|�d||||f�|��|�t
|�d||||f�dS)NTrnrmz-<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'rorprr�	_getframe�f_linenorrqrmr}r~r�r�r��r*Zcreate_filenameZ
create_linenortr�r�rrr�test_handle_repr_debug�s0


��
��
��z"HandleTests.test_handle_repr_debugcs|t����}|�d���|��fdd�}|�t�}||�|�t�}||�|�dt�}||�|�dt�}||�dS)NTcsBt�d�jd}��|jt���|jddd�t|df�dS)Nrnr�rl�test_handle_source_traceback)rr�r�r�rx�listr�r)rtr�r0rr�check_source_traceback�s��zHHandleTests.test_handle_source_traceback.<locals>.check_source_tracebackr)	r�get_event_loop_policyr$�	set_debugr%r�rmr�r�)r*r'r�rtrr0rr��s

	

z(HandleTests.test_handle_source_traceback�	CoroutinezNo collections.abc.CoroutinecCs�t�}d|_|�t�|��|�t�|�d�d|_|�t�|�d�d|_	|�t�|�d�d|_|_|�t�|�d�t�}d|_|�t�|�d	�t�}d|_d|_
|�t�|�d�dS)
NZAAAzAAA()ZBBBzBBB()Tz
BBB() runningz%<CoroLike without __name__>() runningr)z
CoroLike())r)r3r�rZiscoroutiner�rZ_format_coroutiner5�
cr_running�cr_code)r*r\rrr�+test_coroutine_like_object_debug_formatting�s&�z7HandleTests.test_coroutine_like_object_debug_formatting)r3r4r5rzruryr{r�r�r�rVrr&�collections�abcr�rYrrrVrrn0s
2�rncsLeZdZ�fdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	�Z
S)�
TimerTestscst���t��|_dSr)rTrzrrlr'r0rVrrrz�s
zTimerTests.setUpcCs8t��}t�|dd�dt���}|�t|�t|��dS)NcSsdSr
rrrrrr��rkz&TimerTests.test_hash.<locals>.<lambda>r)r�r�r�TimerHandlerrlr��hash�r*�whenrtrrr�	test_hash�s
�zTimerTests.test_hashcCs4t��}t�|dd�dt���}|�||���dS)NcSsdSr
rrrrrr��rkz&TimerTests.test_when.<locals>.<lambda>r)r�r�rr�rrlr�r�r�rrr�	test_when�s
�zTimerTests.test_whencCs�dd�}d}t��}t�|||t���}|�|j|�|�|j|�|�	|�
��|��|�|�
��|�
|j�|�
|j�|�ttjd|||j�dS)NcWs|Srrr�rrrr��sz'TimerTests.test_timer.<locals>.callback)rnrorl)r�r�rr�rrlr�rrrsr�r�r�r�r�r��AssertionErrorr')r*r�r�r�rtrrr�
test_timer�s
�zTimerTests.test_timercCsVd|jj_t�dtd|j�}t�t�}|�t	|�d|�|�
�|�t	|�d�dS)NF�{rz&<TimerHandle when=123 noop() at %s:%s>z <TimerHandle cancelled when=123>)r'rorprr�rmr}r~r�r�r�)r*rt�srcrrr�test_timer_repr
	s


�
�zTimerTests.test_timer_reprcCs�d|jj_t}t��jd}t�dt	d|j�}t
�t	�\}}|�t
|�d||||f�|��|�t
|�d||||f�dS)NTrnr�rz7<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'rorprrr�r�rr�rmr}r~r�r�r�r�rrr�test_timer_repr_debug	s 


��

��z TimerTests.test_timer_repr_debugcCs:dd�}t��}t�||d|j�}t�||d|j�}|�||k�|�||k�|�||k�|�||k�|�||k�|�||k�|�||k�|�||k�|�||k�|�||k�|��|�||k�t�||d|j�}t�|d|d|j�}|�||k�|�||k�|�||k�|�||k�|�||k�|�||k�|�||k�|�||k�|�||k�|�||k�t�|d|j�}|�	t
|�|��|�	t
|�|��|�
t��|dkWd�n1�s�0Y|�
t��|dkWd�n1�s0Y|�
t��|dkWd�n1�sP0Y|�
t��|dkWd�n1�s�0Y|�|dk�|�|dk�|�|tk�|�|tk�|�|tk�|�|tk�|�|tk�|�|tk�|�|tk�|�|tk�|�|tk�|�|tk�dS)NcWs|Srrr�rrrr�1	sz2TimerTests.test_timer_comparison.<locals>.callbackrg$@)r�r�rr�r'r�r�r�rqr��NotImplemented�__eq__�__ne__r�r�rrr
)r*r�r�Zh1Zh2Zh3rrr�test_timer_comparison0	sf((((z TimerTests.test_timer_comparison)r3r4r5rzr�r�r�r�r�r�rYrrrVrr��sr�c@seZdZdd�Zdd�ZdS)�AbstractEventLoopTestscCs�t��}t��}|�t|j�|�t|jd�|�t|j�|�t|j	�|�t|j
�|�t|j�|�t|jd�|�t|j
dd�|�t|j||�|�t|jd�|�t|j�|�t|jd�|�t|j|�|�t|jd|�|�t|jd�|�t|jd|�|�t|jd�|�t|jd|�|�t|jd�|�t|jd�|�t|j|�|�t|j|�|�t|j|�|�t|j�|�t|j|�dSr�)rrlr�AbstractEventLoopr��NotImplementedErrorr�r&r�r�r|r1rdr�rr�r�r�Zset_default_executorr�r�r�r�r�r�Zset_exception_handlerZdefault_exception_handlerr�ror�)r*r:r'rrr�test_not_implementedq	s��������
�
�����
��
��
��������z+AbstractEventLoopTests.test_not_implementedcs,�fdd�}t��}|�|��|��dS)Nc�s(t��}t��}��t��"|�||�IdHWd�n1sB0Y��t��"|�dd�IdHWd�n1s~0Y��t�� |�d�IdHWd�n1s�0Y��t�� |�	|�IdHWd�n1s�0Y��t�� |�
|�IdHWd�n1�s.0Y��t�� |�|�IdHWd�n1�sj0Y��t��"|�|d�IdHWd�n1�s�0Y��t��"|�
|d�IdHWd�n1�s�0Y��t��"|�|d�IdHWd�n1�s$0Y��t��"|�||�IdHWd�n1�sb0Y��t�� |�|�IdHWd�n1�s�0Y��t��"|�||�IdHWd�n1�s�0Y��t��"|�||�IdHWd�n1�s0Y��t��&|�|tjj�IdHWd�n1�s\0Y��t��&|�|tjj�IdHWd�n1�s�0Y��t��$|�|tj�IdHWd�n1�s�0Y��t�� |�|�IdHWd�n1�s0YdS)Nr��)r�r�r)rrlrr�r�r�r�rcr�rrNr�r�Zsock_recv_intoZsock_sendallZsock_connectZsock_acceptZ
sock_sendfile�sendfiler��sentinelr�r�r+r )r:r'r0rr�inner�	sH00..002222022664z@AbstractEventLoopTests.test_not_implemented_async.<locals>.inner)rr$r&r1)r*r�r'rr0r�test_not_implemented_async�	s'z1AbstractEventLoopTests.test_not_implemented_asyncN)r3r4r5r�r�rrrrr�o	s6r�c@s^eZdZdd�Zdd�Zdd�Zdd�Ze�d	�d
d��Z	dd
�Z
dd�Zdd�Zdd�Z
dS)�PolicyTestscCsZt��}|�t|j�|�t|jt��|�t|j�|�t|j�|�t|j	t��dSr)
r�AbstractEventLoopPolicyr�r��get_event_loopr%r�r$Zget_child_watcherrc�r*�policyrrr�test_event_loop_policy�	s
�z"PolicyTests.test_event_loop_policycCsXt��}|�|jj�|��}|�|tj�|�|jj|�|�||���|�	�dSr)
r�DefaultEventLoopPolicyr��_localZ_loopr�r�r�r�r1�r*r�r'rrr�test_get_event_loop�	szPolicyTests.test_get_event_loopcCsZt��}tjj|d|jd��"}|��}|�|�Wd�n1sD0Y|��dS)Nr%)�wraps)	rr�rr'r�r%r�rvr1)r*r�Zm_set_event_loopr'rrr�(test_get_event_loop_calls_set_event_loop�	s�(z4PolicyTests.test_get_event_loop_calls_set_event_loopcCs$t��}|�d�|�t|j�dSr)rr�r%r�r�r�r�rrr�"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�}|��|��dS)Ncst��}��t|j�dSr)rr�r�r�r�)r�r0rrr:
sz1PolicyTests.test_get_event_loop_thread.<locals>.fr�)r�r�r�r�)r*Zm_current_threadr:Zthrr0r�test_get_event_loop_thread
sz&PolicyTests.test_get_event_loop_threadcCs*t��}|��}|�|tj�|��dSr)rr�r$r�r�r1r�rrr�test_new_event_loop
szPolicyTests.test_new_event_loopcCsht��}|��}|�t|jt��|��}|�|�|�||���|�	||���|�
�|�
�dSr)rr�r�r�r�r%r�r$r��assertIsNotr1)r*r�Zold_loopr'rrr�test_set_event_loop
s
zPolicyTests.test_set_event_loopcCs*t��}|�|tj�|�|t���dSr)rr�r�r�r�r�rrr�test_get_event_loop_policy
sz&PolicyTests.test_get_event_loop_policycCsL|�ttjt��t��}t��}t�|�|�|t���|�||�dSr)	r�r�rrr�r�r�r�r�)r*�
old_policyr�rrr�test_set_event_loop_policy$
s
�
z&PolicyTests.test_set_event_loop_policyN)r3r4r5r�r�r�r�rr'r�r�r�r�r�rrrrr��	s	


r�csReZdZdZdZdZdZ�fdd�Z�fdd�Ze	j
dkrBdd�Zd	d
�Z�Z
S)�GetEventLoopTestsMixinNcs�tj|_tj|_tj|_tj|_t	|�j
t_t	|�jt_t	|�jt_t	|�j
t_t	|�j
t_t	|�jt_t	|�jt_t	|�j
t_t���t��|_t�|j�tjdkr�t��}|�|j�t�|�dSr)r�_get_running_loop�_get_running_loop_saved�_set_running_loop�_set_running_loop_saved�get_running_loop�get_running_loop_savedr��get_event_loop_savedr��_get_running_loop_impl�_set_running_loop_impl�get_running_loop_impl�get_event_loop_implrrTrzr$r'r%rrrarbrcrdrVrrrz7
s&


zGetEventLoopTestsMixin.setUpc	s�zvtjdkrt�d�t���W|j��t�d�|j	t
_|jt
_
|jt
_|jt
_|j	t_|jt_
|jt_|jt_nV|j��t�d�|j	t
_|jt
_
|jt
_|jt
_|j	t_|jt_
|jt_|jt_0dSr)rrrrcrTrr'r1r%r�rr�r�r�r�r�r�r�r0rVrrrQ
s0




�

zGetEventLoopTestsMixin.tearDownrcs.t���fdd�}���j�|��d�dS)Nc�s*tj��}�j�|t�IdH}|��|Sr)�
concurrentZfuturesZProcessPoolExecutorr'r�r(Zshutdown)Zpoolr�r0rrr�m
s
�
zDGetEventLoopTestsMixin.test_get_event_loop_new_process.<locals>.mainr")r	Z*skip_if_broken_multiprocessing_synchronizer�r'r&)r*r�rr0r�test_get_event_loop_new_processg
s�z6GetEventLoopTestsMixin.test_get_event_loop_new_processc	s&Gdd�dt��G�fdd�dtj�}t��}�z�t�|��t��������t��Wd�n1sn0Yt�d������t��Wd�n1s�0Y��	t
d�� ��t��d�Wd�n1s�0Y��t�
�d���fdd�}��|��t��������t��Wd�n1�sN0Yt�d������t��Wd�n1�s�0YWt�|��du�rԈ��nt�|��du�r҈��0��	t
d�� ��t��d�Wd�n1�s0Y��t�
�d�dS)Nc@seZdZdS)zRGetEventLoopTestsMixin.test_get_event_loop_returns_running_loop.<locals>.TestErrorN)r3r4r5rrrr�	TestErrory
sr�cseZdZ�fdd�ZdS)zOGetEventLoopTestsMixin.test_get_event_loop_returns_running_loop.<locals>.Policycs��dSrrr0�r�rrr�}
sz^GetEventLoopTestsMixin.test_get_event_loop_returns_running_loop.<locals>.Policy.get_event_loopN)r3r4r5r�rr�rr�Policy|
sr�z
no runningc�s4��t������t������t����dSr)r�rr�r�r�r)r'r*rrr�
szMGetEventLoopTestsMixin.test_get_event_loop_returns_running_loop.<locals>.func)rGrr�r�rr$r�r�r%rZr�r�r�r�r&r1)r*r�r�rr)r�r'r*r�(test_get_event_loop_returns_running_loopx
s>&
&.
(
*


�


0z?GetEventLoopTestsMixin.test_get_event_loop_returns_running_loop)r3r4r5r�r�r�r�rzrrrr�r�rYrrrVrr�0
s
r�c@s$eZdZejZejZejZ	ej
ZdS)�TestPyGetEventLoopN)r3r4r5rZ_py__get_running_loopr�Z_py__set_running_loopr�Z_py_get_running_loopr�Z_py_get_event_loopr�rrrrr��
sr�c@s$eZdZejZejZejZ	ej
ZdS)�TestCGetEventLoopN)r3r4r5rZ_c__get_running_loopr�Z_c__set_running_loopr�Z_c_get_running_loopr�Z_c_get_event_loopr�rrrrr��
sr�c@seZdZdd�ZdS)�
TestServercsbt��}|�|j�t|��|�|��fdd�dd��}|�|��|�|��|�|�	��dS)Ncs�SrrrrLrrr��
rkz*TestServer.test_get_loop.<locals>.<lambda>rvr)
rr$rYr1rSr&rNr��get_loop�wait_closed)r*r'rorrLr�
test_get_loop�
szTestServer.test_get_loopN)r3r4r5r�rrrrr��
sr�c@s$eZdZdd�Zdd�Zdd�ZdS)�TestAbstractServercCs:|�t��t����Wd�n1s,0YdSr)r�r�r�AbstractServerr1r0rrrr�
szTestAbstractServer.test_closecCsTt��}|�|j�|�t��"|�t���	��Wd�n1sF0YdSr)
rr$rYr1r�r�r&rr�r�r?rrr�test_wait_closed�
sz#TestAbstractServer.test_wait_closedcCs:|�t��t����Wd�n1s,0YdSr)r�r�rr�r�r0rrrr��
sz TestAbstractServer.test_get_loopN)r3r4r5rr�r�rrrrr��
sr��__main__)L�__doc__�collections.abcr�Zconcurrent.futuresr�r1r�r�rr�r�r�r�ImportErrorrDrr�r�r=rVrrzr�rrrrrZtest.test_asynciorr}rr	Ztest.supportr
rrr
rr r(r)r�r6rSZDatagramProtocolrZrbZBaseProtocolrdrJrfryrZTestCaserVrZrgr`r&rfrjrlrmrnr�r�r�r�r�Z_asyncior�r�r�r3r�rrrr�<module>s�

	" )Q������6f[y