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.opt-1.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__cCs"||_d|_|jr|j�d�dS�N�	CONNECTED�r9r:r=�
set_result�r*r9rrr�connection_madeYszMyBaseProto.connection_madecCs|jt|�7_dSr�r;�len�r*�datarrr�
data_received`szMyBaseProto.data_receivedcCs
d|_dS�N�EOF)r:r0rrr�eof_receiveddszMyBaseProto.eof_receivedcCsd|_|jr|j�d�dS�N�CLOSED�r:r>rDr-rrr�connection_losthszMyBaseProto.connection_lost)N)
r3r4r5r=r>r@rFrKrNrRrrrrr6Ms
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||_d|_dS)N�INITIALIZED�r9r:rErrrrF~szMyDatagramProto.connection_madecCs|jt|�7_dSrrG�r*rJ�addrrrr�datagram_received�sz!MyDatagramProto.datagram_receivedcCsdSrrr-rrr�error_received�szMyDatagramProto.error_receivedcCsd|_|jr|j�d�dSrOrQr-rrrrR�szMyDatagramProto.connection_lost)N)	r3r4r5r>r@rFr_r`rRrrrrrZus
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||_|j�d�dSrA)r9r:�appendrErrrrF�szMyReadPipeProto.connection_madecCs|jt|�7_dSrrGrIrrrrK�szMyReadPipeProto.data_receivedcCs|j�d�dSrL)r:rbr0rrrrN�szMyReadPipeProto.eof_receivedcCs8d|jvr|j�d�|j�d�|jr4|j�d�dS)NrMrP)r:rbr>rDr-rrrrR�s

zMyReadPipeProto.connection_lost)N)	r3r4r5r>r@rFrKrNrRrrrrra�s
rac@s*eZdZdZddd�Zdd�Zdd�ZdS)	�MyWritePipeProtoNcCs"d|_d|_|dur|��|_dS)Nr8)r:r9r<r>r?rrrr@�szMyWritePipeProto.__init__cCs||_d|_dSrAr\rErrrrF�sz MyWritePipeProto.connection_madecCsd|_|jr|j�d�dSrOrQr-rrrrR�sz MyWritePipeProto.connection_lost)N)r3r4r5r>r@rFrRrrrrrc�s
rcc@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>�ri���)r:r9r<r=�	completed�range�disconnectsrJ�
returncoderZEvent�got_datar?rrgrr@�s

�zMySubprocessProtocol.__init__cCs||_d|_|j�d�dSrArCrErrrrF�sz$MySubprocessProtocol.connection_madecCsd|_|j�d�dSrO)r:rnrDr-rrrrR�sz$MySubprocessProtocol.connection_lostcCs$|j||7<|j|��dSr)rJrr�set)r*rfrJrrr�pipe_data_received�sz'MySubprocessProtocol.pipe_data_receivedcCs*|r|j|�|�n|j|�|�dSr)rpZ
set_exceptionrD)r*rfr.rrr�pipe_connection_lost�sz)MySubprocessProtocol.pipe_connection_lostcCs|j��|_dSr)r9Zget_returncoderqr0rrr�process_exited�sz#MySubprocessProtocol.process_exitedN)	r3r4r5r@rFrRrtrurvrrrrrd�srdcs0eZdZ�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%r0rVrrrx�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&rrr�)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'�stoprrrr0rr�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�rbr'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�Nrm�rbrHr'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�rrrrrr�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�rJ��
bytes_read�rr*rr�reader{sz8EventLoopTestsMixin.test_reader_callback.<locals>.readersabccst��dkS)Nrj�rHr�r�rr�<lambda>�riz:EventLoopTestsMixin.test_reader_callback.<locals>.<lambda>sdefcst��dkS)N�r�rr�rrr��risabcdef)�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>.writersxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxrm)r�r�r�r'�
add_writerr�r�r��
remove_writerr�r1r�rHr�)r*r�r�rJ�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�Nrlrr��caughtrr�
my_handler�sz?EventLoopTestsMixin.test_add_signal_handler.<locals>.my_handlerZboomrl���cs�Srrrr�rrr��riz=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�?�<rl�
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�rlr�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�Nrg�rSr'rr0rrr�riz<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�Srrrr0rrr�rizAEventLoopTestsMixin.test_create_unix_connection.<locals>.<lambda>)r r{�run_test_unix_serverr'�create_unix_connectionr
r)r*rrrrr0r�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�cipherrjrrlrmZ
ssl_object�compression)r�r�r�r�rrH�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)Zpurposerrrr0rr�_dummy_ssl_create_contextEszREventLoopTestsMixin._test_create_ssl_connection.<locals>._dummy_ssl_create_contextzssl.create_default_context)�side_effectTrlZCERTIFICATE_VERIFY_FAILED)r{r!r�hasattrrrr r�patchr�Z
call_countr��SSLError�disable_logger�	exception�reason)	r*rr	rrrr"�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�Srrrr0rrr�griz@EventLoopTestsMixin.test_create_ssl_connection.<locals>.<lambda>�r)r{r�	functools�partialr'r	r
r,)r*rr	rr0r�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�Srrrr0rrr�vrizEEventLoopTestsMixin.test_create_ssl_unix_connection.<locals>.<lambda>�	127.0.0.1)�server_hostnamer.)	r r{rr/r0r'rr
r,)r*rrr	rr0r�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�Srrrr0rrr��rizGEventLoopTestsMixin.test_create_connection_local_addr.<locals>.<lambda>�
local_addrrr�rl)r{rr
�find_unused_portr'r	r
r&r9r�r�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�Srrrr0rrr��rizNEventLoopTestsMixin.test_create_connection_local_addr_in_use.<locals>.<lambda>r5)r{rr'r	r
r��OSErrorr&r�r(�errno�
EADDRINUSE�assertInr�strerror)r*rr8r+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)rTrKr9rUrI)rW�expected_responserrrK�szOEventLoopTestsMixin.test_connect_accepted_socket.<locals>.MyProto.data_received)r3r4r5rRrKrYr)r@r'rVrrS�srS�r2rrl)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�Zdaemonrgcs�Srrr��protorrr��rizBEventLoopTestsMixin.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;rH)	r*Z
server_sslrGrSZlsockr�threadZconn�_r)r^rGr@r'rHrKrIr�test_connect_accepted_socket�s4

��

z0EventLoopTestsMixin.test_connect_accepted_socketcCsLtjdkr,tjdkr,t|jtj�r,t�d��t	�
�}t	��}|�||�dS)Nr)rjrz=SSL not supported with proactor event loops before Python 3.5)
rr�version_info�
isinstancer'rZBaseProactorEventLoop�unittest�SkipTestr{Zsimple_server_sslcontextZsimple_client_sslcontextrQ)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'rNrSr	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)�hostr7r��kw)�familyrr�getaddrinfo�s
zEEventLoopTestsMixin.create_server_multiple_hosts.<locals>.getaddrinfocs�j��|i|���Sr)r'�create_task)r��kwds)rar*rr�getaddrinfo_task�szJEventLoopTestsMixin.create_server_multiple_hosts.<locals>.getaddrinfo_taskcSsg|]}|df�qS)�Pr�rer^rrr�
<listcomp>�szDEventLoopTestsMixin.create_server_multiple_hosts.<locals>.<listcomp>cSsg|]}|dddf�qS)rerrrfrrrrg�scs
t�j�Srrrr0rrr��rizBEventLoopTestsMixin.create_server_multiple_hosts.<locals>.<lambda>recSsh|]}|��d�qS)r)�
getsockbyname)rerYrrr�	<setcomp>�rizCEventLoopTestsMixin.create_server_multiple_hosts.<locals>.<setcomp>)rsr�r]rhr#r'rar�MockZ_start_serving�
_stop_servingrLr&rWr1�socketsr�)	r*r`ZhostsZ	mock_sockrdZunique_hostsr8�serverZserver_hostsr)r`rar*r�create_server_multiple_hosts�s$
��z0EventLoopTestsMixin.create_server_multiple_hostscCs|�tjgd��dS)N)�1.2.3.4z5.6.7.8ro)rnr�r]r0rrr�&test_create_server_multiple_hosts_ipv4�s�z:EventLoopTestsMixin.test_create_server_multiple_hosts_ipv4cCs|�tjgd��dS)N)�::1z::2rq)rnr��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�SrrrrJrrr�riz8EventLoopTestsMixin.test_create_server.<locals>.<lambda>�0.0.0.0rrlr2�xxxrBcs
�jdkSr~�r;rrJrrr�rirjr�rrP)rSr'rLr&r�rHrlrMr�rCrDr=r:r{r�r;r�r9r�r1r>�r*r8rmrYr^r7rrrJr�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�SrrrrJrrr�-rizCEventLoopTestsMixin.test_create_server_reuse_port.<locals>.<lambda>rtrrlcs�SrrrrJrrr�:riT)Z
reuse_port)rSr'rLr&r�rHrlr�Z
getsockoptr�Z
SOL_SOCKETryr1r{r|r�)r*r8rmrYrrJr�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�Eriz7EventLoopTestsMixin._make_unix_server.<locals>.<lambda>)r{Zgen_unix_socket_pathrWr'�create_unix_serverr&)r*�factory�kwargsr8rmrr~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)
Nrgcs�SrrrrJrrr�Oriz=EventLoopTestsMixin.test_create_unix_server.<locals>.<lambda>rlrurBcs
�jdkSr~rvrrJrrr�XrirjrP)rSr'r�r�rHrlr��AF_UNIXrCrDr&r=r:r{r�r;r9r1r>)r*rmr{rrrJr�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)Nrgcs�SrrrrJrrr�mrizOEventLoopTestsMixin.test_create_unix_server_path_socket_error.<locals>.<lambda>z/test�rYz3path and sock can not be specified at the same time)rSr'r�rrXr�r&)r*rYr8rrJr�)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)Nr2rr)r�r'rLr&rlrMr�)
r*r�r�r�r�r8rmrYr^r7rrr�_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)Nrgcs�SrrrrJrrr��riz<EventLoopTestsMixin.test_create_server_ssl.<locals>.<lambda>rrurBcs
�jdkSr~rvrrJrrr��rirjr.rP)rSr'r�r{�ONLYCERT�ONLYKEYr	r6r!r&rUr=r�r:r�r;rr9r1r>)r*rmr^r7�f_crrrrJr�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)Nrgcs�SrrrrJrrr��rizAEventLoopTestsMixin.test_create_unix_server_ssl.<locals>.<lambda>r\�rr3rurBcs
�jdkSr~rvrrJrrr��rirjrP)rSr'r�r{r�r�rr6r!r&rUr=r�r:r�r;r9r1r>)r*rmr{r�rrrrJr�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)	Nrgcs�SrrrrJrrr��rizJEventLoopTestsMixin.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�r	rr%�objectr'rXr&r&r|�assertIsNoner9r1�r*rmr^r7�sslcontext_clientr�rrJr�$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)
Nrgcs�SrrrrJrrr��rizOEventLoopTestsMixin.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'rXr&r&r|r�r9r1)r*rmr{r�r�rrJr�)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)
Nrgcs�SrrrrJrrr�rizIEventLoopTestsMixin.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�r	rr%r�r'rXZCertificateErrorr&r�r9r1r�rrJr�#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)	Nrgcs�SrrrrJrrr�%rizJEventLoopTestsMixin.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*rmr{r�r�rrrrJr�$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)
Nrgcs�SrrrrJrrr�?rizEEventLoopTestsMixin.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�r	r&r=rZPEERCERTr9r1r>)r*rmr^r7r�r�rrrrJr�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)rWrKrrrF]szPEventLoopTestsMixin.test_create_server_sock.<locals>.TestMyProto.connection_maderXrrJrVr�TestMyProto\sr��rtrr�rrtr2ru)
r'r<rSr�rLr&rlr�r�rMrCr,r1)	r*r��sock_obr8rmrYr^r7rrrJr�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^r7)r�rLr'rSr&rlrMr�r:r�r(r;r<r1)r*r�r8rmrYr^r7r+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�rlrr2rurq)r'r<rSr
r6rLr&r:r;r<ZassertGreaterEqualr�rCr,r9r1rr)	r*r�Z	try_countr7r8rmZexrrKrr�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)Nrtrr2ru)r'rLrSr&rlrMr�rCr,r1r��ConnectionRefusedErrorrwrrr�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�)r5r`r�r[cst�jd�Sr�rZr'rr0rrr��rizDEventLoopTestsMixin._test_create_datagram_endpoint.<locals>.<lambda>)Zremote_addrrucs�jSrrvr)rmrrr��rirjcs�jSrrvr)rrrr��ri�rP)rZr'�create_datagram_endpointr&r�r��getnameinfoZNI_NUMERICHOSTZNI_NUMERICSERVr�rr�r�r:r�r9r�r{r�r;r�r1r>)
r*r5r`r�rZZs_transportr�r^r7r9r)rr*rmr�_test_create_datagram_endpoint�s@�
�
�
z2EventLoopTestsMixin._test_create_datagram_endpointcCs|�dtj�dS)NrA)r�r�r]r0rrr�test_create_datagram_endpoint�sz1EventLoopTestsMixin.test_create_datagram_endpointcCs|�dtj�dS)N)rqr)r�r�rrr0rrr�"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(0qrq(�jj�fdd�|d�}	�j�|	�\}
}��|
t	j
���|t�|
���j�|j
�dS)NrA�type)r`r�rKFcst�jd�Srr�rr0rrr�rizHEventLoopTestsMixin.test_create_datagram_endpoint_sock.<locals>.<lambda>r�)r'r&rar�Z
SOCK_DGRAMr�Zbindr�r�rr�rZr1r>)r*rYZ
local_addressZinfosr`r�rKZcnamer
r8rrrr0r�"test_create_datagram_endpoint_sock�s2���
�z6EventLoopTestsMixin.test_create_datagram_endpoint_sockcCsf|��}t|tj�s&|��|�d�|�d|j�|��|�d|j�|�|j	�|�|j
�dS)Nz#loop is not a BaseSelectorEventLooprlr)ryrSrZBaseSelectorEventLoopr1ZskipTestr�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)Nrg�rbr�c�s^�j��fdd���IdH\}}��|����|�j���ddg�j���d�j�dS)Ncs�SrrrrJrrr�!rizEEventLoopTestsMixin.test_read_pipe.<locals>.connect.<locals>.<lambda>r8rBr�r'�connect_read_piper�r9r�r:r;�r��p��pipeobjrKr*rrrCs�z3EventLoopTestsMixin.test_read_pipe.<locals>.connect�1cs
�jdkSr�rvrrJrrr�*riz4EventLoopTestsMixin.test_read_pipe.<locals>.<lambda>rl�2345cs
�jdkS�NrrvrrJrrr�.rir8rBr�r8rBrMrP�pipe)rar'r�r��io�openr&rUr{r�r�r;r:r1r>r�r9r�)r*�rpipe�wpiperCrr�r�test_read_pipes$

�z"EventLoopTestsMixin.test_read_pipecs�|���t�d��t�d��t��\}}t�|dd��t�|dd�������fdd�}��|��\}}���|�	dt
|��|�	dt
|��������d|_d|_dS)Nrgr�r�r�c�sD���fdd���IdH\}}���fdd���IdH\}}||fS)Ncs�Srrr��
read_protorrr�GrizSEventLoopTestsMixin.test_unclosed_pipe_transport.<locals>.connect.<locals>.<lambda>cs�Srrr��write_protorrr�Iri)r��connect_write_pipe)�read_transportrP�write_transport�r'r�ZrpipeobjZwpipeobjr�rrrCEs��zAEventLoopTestsMixin.test_unclosed_pipe_transport.<locals>.connectr�)ryrarcr�r�r�r�r&r1r=�reprZ_pipe)r*r�r�rCr�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)Nrgr�rc�s^�j��fdd���IdH\}}��|����|�j���ddg�j���d�j�dS)Ncs�SrrrrJrrr�drizKEventLoopTestsMixin.test_read_pty_output.<locals>.connect.<locals>.<lambda>r8rBrr�r��Zmaster_read_objrKr*rrrCcs�z9EventLoopTestsMixin.test_read_pty_output.<locals>.connectr�cs�jSrrvrrJrrr�nriz:EventLoopTestsMixin.test_read_pty_output.<locals>.<lambda>rlr�cs
�jdkSr�rvrrJrrr�rrir8rBrr�r�)rar'r��openptyr�r�r&rUr{r�r�r;r:r1r9r>r�r�)r*�master�slaverCrr�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�rgcs�SrrrrJrrr��riz5EventLoopTestsMixin.test_write_pipe.<locals>.<lambda>rBr�cst��d�}||7}t|�Sr��r�r�rH�rJ�chunk)r�rrr��sz3EventLoopTestsMixin.test_write_pipe.<locals>.readercs���dkSr�rr�rJr�rrr��rir�cs���dkSr�rrr�rrr��ri�12345r�rP)r�r�r�r�rcr'r�r&r�r9r�r:rUr�r{r�r1r�r�r>)r*r�r�rCr9r�r)rJrKr�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�rgcs�SrrrrJrrr��rizIEventLoopTestsMixin.test_write_pipe_disconnect_on_close.<locals>.<lambda>rBr�rP)r�r�r�r�r��detachrcr'r�r&r�r9r�r:rU�	sock_recvr1r>)r*ZrsockZwsockr�rCr9r�rJrrJr�#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�rrgcs�SrrrrJrrr��riz4EventLoopTestsMixin.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��ri�Ztimeoutr�cs���dkSr�rrr�rrr��rir�r�rP)r�r�r�r�rcr'r�r&r�r9r�r:rUr�r{r�r	�
SHORT_TIMEOUTr1r�r�r>)r*r��slave_write_objrCr9r�r)rJr�rKr�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�rrgcs�Srrrr�rrr��riz<EventLoopTestsMixin.test_bidirectional_pty.<locals>.<lambda>r8rBr�cs�Srrrr�rrr��ricst��d�}||7}t|�Sr�r�r�r�rrr�sz:EventLoopTestsMixin.test_bidirectional_pty.<locals>.readerr�cs���dkSr�rrr�rrr�
rir��acs
�jdkSr�rvrr�rrr�rirlr�cs���dkSr�rrr�rrr�rir�sbcdecs
�jdkSr�rvrr�rrr�"rirr�rP)r�r��dup�ttyZsetrawr�r�rar'r�r&r�r9r�r:r;rcr�r�rUr{r�r	r�r1r>)
r*Z
read_slaveZwrite_slaveZslave_read_objZread_connectr�r�r�Z
write_connectr�r)rJr�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)NFrl�ovc�sZzHz�j��j��IdHWntjy6d}Yn0d}W�j��n�j��0|S)N�	cancelled)r'r�r�r�CancelledErrorr�)r��r8r*rr�main;s
z:EventLoopTestsMixin.test_prompt_cancellation.<locals>.mainr�r�)r�r�r�r'rbr��getattrr�Zpendingr��	monotonicr�Z
assertLessr��resultr�rr�r�rkr1)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'rrrgr0rr�wait_sz7EventLoopTestsMixin.test_timeout_rounding.<locals>.wait�)Zclock_resolutionZselector)	r'rr�r&ZassertLessEqualZ_clock_resolutionZ	_selectorrWr3)r*rrrrr�test_timeout_roundingVs
��z)EventLoopTestsMixin.test_timeout_roundingcCsx|��}dd�}t��\}}|�|j�|�|j�|�||�|�||�|��|�|�|��|�|�	|��dS)NcSsdSrrrrrrr�rrizCEventLoopTestsMixin.test_remove_fds_after_closing.<locals>.<lambda>)
ryr�r�rWr1r�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�~riz@EventLoopTestsMixin.test_add_fds_after_closing.<locals>.<lambda>)	ryr�r�rWr1r�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'r1rgr0rr�
close_loop�szEEventLoopTestsMixin.test_close_running_event_loop.<locals>.close_loop)r'r�r�r&)r*rrZrr0r�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��riz0EventLoopTestsMixin.test_close.<locals>.<lambda>g�?g)r'r1rWr�r�r�r<r&r�r�r��call_atr�rbr�r��SIGTERMr�r2�next)r*r
�funcrZZfut�itrrr�
test_close�s2
(
**,.8,0zEventLoopTestsMixin.test_close)T)TN)TN)NN)N)N)N)Yr3r4r5rxr}r�r�r�r�r�r�r�r�r�r�r�rT�
skipUnlessr$r�r�r�r�rr
r
Zskip_unless_bind_unix_socketrrrr,�skipIfrr1r4r9r?rQrVr[rr%rnrprsrxr�rzr�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�r�rrrr	rrYrrrVrrw�s�		

+




�
!�

�
%
	

6


$
	










(0
�
 �
 �
!�
%�
�
'�
F#rwc@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*rqrrr�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 Winnerrl)r�r{r��dirname�__file__r'�subprocess_execr/r0rdr�
executabler&r�r=r�r:�get_pipe_transportrUrrrr{r'r1rnrrqrJ�r*�progrC�transprK�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 rls
The Winnerr)r�r{r�rrr'rr/r0rdrrr&r�r=r�r:r rUrrr�clearrJr{r'r1rnrrqr!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>)rer8rrr�	<genexpr>�riz=SubprocessTestsMixin.test_subprocess_shell.<locals>.<genexpr>rls
sPythonrmri)r'�subprocess_shellr/r0rdr&r�r=r r1rnr�rqr��allrp�valuesrJ�rstrip�r*rCr#rKrrr�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)r/r0rdr&r�rnr�rqr1r-rrr�test_subprocess_exitcodes�z-SubprocessTestsMixin.test_subprocess_exitcodecCs�|jjt�t|j�ddddd�}|j�|�\}}|�|t�|�|�d��|�|�d��|�|�d��|j�|j	�|�
d|j�|�|���dS)Nr/r0rrlrmr3)
r'r)r/r0rdr&r�r�r rnr�rqr1r-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'rr/r0rdrrr&r�r=r�rnrrqr1�r*r"rCr#rKrrr�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�|��dSr7)r�r{r�rrr'rr/r0rdrrr&r�r=Z	terminaternrrqr1r8rrr�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|�0dSr7)r��SIGHUP�SIG_DFLr�r{r�rrr'rr/r0rdrrr&r�r=Zsend_signalrnr�rqr1)r*Zold_handlerr"rCr#rKrrr�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:testrlrmsERR:test)r�r{r�rrr'rr/r0rdrrr&r�r=r rUrnr1r�rJr�rrqr!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>)r2rrlrmr?sOUT:testERR:testri)r�r{r�rrr'rr/r0rdrr�
subprocessZSTDOUTr&r�r=r r�r�rUrnr�rJrr�r1rqr!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.pyrrlr?r@rurmrsERR:BrokenPipeErrorsERR:OSError)r�r{r�rrr'rr/r0rdrrr&r�r=r rUrrrr�rJr1rprr{r'rnrrq)r*r"rCr#rKr$r1rrr�#test_subprocess_close_client_stream�s0�





(z8SubprocessTestsMixin.test_subprocess_close_client_streamcCsf|jjt�t|j�dddddd�}|j�|�\}}|�|t�|j�|j�|�d|j	�|�
�dS)Nr/T)r$r1r2Zstart_new_sessionr3r4r-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'rr�SubprocessProtocol)rcr0rrrC�s��zGSubprocessTestsMixin.test_subprocess_exec_invalid_args.<locals>.connectT�Zuniversal_newlines���bufsize��shell�r�r�r'r&�r*rCrr0r�!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|��IdHdSrF)r'r)rrH)�cmdrcr0rrrC�s��zHSubprocessTestsMixin.test_subprocess_shell_invalid_args.<locals>.connectZlsz-lTrIrJrKFrM)NrOrPrr0r�"test_subprocess_shell_invalid_args�s200z7SubprocessTestsMixin.test_subprocess_shell_invalid_argsN)r3r4r5rrr%r'r.r5r6r9r:rTrrrr=rArCrDrErQrSrrrrr�s"

!
rc@seZdZdd�ZdS)�SelectEventLoopTestscCst��Sr)r�SelectorEventLoopr0rrrry�s�&SelectEventLoopTests.create_event_loopN�r3r4r5ryrrrrrT�srTc@s<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�ProactorEventLoopTestscCst��Sr)rZProactorEventLoopr0rrrry�sz(ProactorEventLoopTests.create_event_loopcCst�d��dS�Nz(IocpEventLoop does not have add_reader()�rTrUr0rrrr��sz+ProactorEventLoopTests.test_reader_callbackcCst�d��dSrYrZr0rrr�test_reader_callback_cancel�sz2ProactorEventLoopTests.test_reader_callback_cancelcCst�d��dS�Nz(IocpEventLoop does not have add_writer()rZr0rrrr��sz+ProactorEventLoopTests.test_writer_callbackcCst�d��dSr\rZr0rrr�test_writer_callback_cancel�sz2ProactorEventLoopTests.test_writer_callback_cancelcCst�d��dSrYrZr0rrrr�sz4ProactorEventLoopTests.test_remove_fds_after_closingN)	r3r4r5ryr�r[r�r]rrrrrrX�srXcs(eZdZ�fdd�Z�fdd�Z�ZS)�UnixEventLoopTestsMixincs,t���t��}|�|j�t�|�dSr)rTrxr�SafeChildWatcher�attach_loopr'�set_child_watcher�r*ZwatcherrVrrrx�s
zUnixEventLoopTestsMixin.setUpcst�d�t���dSr)rrarTr}r0rVrrr}�s
z UnixEventLoopTestsMixin.tearDown)r3r4r5rxr}rYrrrVrr^�sr^�KqueueSelectorcs\eZdZdd�Ze�dd�e�ej	�
d�d��fdd���Ze�dd��fd	d
��Z�Z
S)�KqueueEventLoopTestscCst�t���Sr)rrU�	selectorsrcr0rrrry�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)r3r4r5ryr	rrTrrrrr�r�rYrrrVrrd�s
�
rd�
EpollSelectorc@seZdZdd�ZdS)�EPollEventLoopTestscCst�t���Sr)rrUrergr0rrrrysz%EPollEventLoopTests.create_event_loopNrWrrrrrhsrh�PollSelectorc@seZdZdd�ZdS)�PollEventLoopTestscCst�t���Sr)rrUrerir0rrrry sz$PollEventLoopTests.create_event_loopNrWrrrrrjsrjc@seZdZdd�ZdS)rTcCst�t���Sr)rrUreZSelectSelectorr0rrrry(srVNrWrrrrrT$scOsdSrr)r�r�rrr�noop,srkcsheZdZ�fdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	e
�ee
jd�d�dd��Z�ZS)�HandleTestscs"t���t��|_d|jj_dSr�)rTrxrrjr'�	get_debug�return_valuer0rVrrrx2s

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.*)rHr(ZhandleZsource_traceback)rrjr'r�rroZ_run�assert_called_withr{ZMockPattern�ANY�_source_traceback)r*r�rrrrr�test_callback_with_exceptionDs
�z(HandleTests.test_callback_with_exceptioncCs(t��}t�dd�d|j�}||d<dS)NcSsdSrrrrrrr�Wriz1HandleTests.test_handle_weakref.<locals>.<lambda>rrr)�weakrefZWeakValueDictionaryrror')r*Zwdrrrrr�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)NFrkz<Handle noop(1, 2) at %s:%s>z<Handle cancelled>rz<Handle noop() at %s:%s>rlrm)rjz%^<Handle noop\(1, 2\)\(3\) at %s:%s>$)�x)rmrjz'^<Handle noop\(x=1\)\(2, 3\) at %s:%s>$)rj�z*<function HandleTests.test_handle_repr .*>z%functools.partialmethod\(%s, , \)\(\)z^<Handle %s at %s:%s>$)r'rmrnrrorkr{�get_function_sourcer�r�r�ZassertWarns�DeprecationWarning�	coroutiner/r0�re�escapeZassertRegexrrRrl�test_handle_repr�
partialmethod)r*rr�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)NTrlrkz-<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'rmrnrr�	_getframe�f_linenorrorkr{r|r�r�r��r*Zcreate_filenameZ
create_linenorrr�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)Nrlr�rj�test_handle_source_traceback)rr�r�r�rv�listr�r)rrr�r0rr�check_source_traceback�s��zHHandleTests.test_handle_source_traceback.<locals>.check_source_tracebackr)	r�get_event_loop_policyr$�	set_debugr%r�rkr�r�)r*r'r�rrrr0rr��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*rZrrr�+test_coroutine_like_object_debug_formatting�s&�z7HandleTests.test_coroutine_like_object_debug_formatting)r3r4r5rxrsrwryr�r�r�rTrr$�collections�abcr�rYrrrVrrl0s
2�rlcsLeZdZ�fdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	�Z
S)�
TimerTestscst���t��|_dSr)rTrxrrjr'r0rVrrrx�s
zTimerTests.setUpcCs8t��}t�|dd�dt���}|�t|�t|��dS)NcSsdSrrrrrrr��riz&TimerTests.test_hash.<locals>.<lambda>r)r�r�r�TimerHandlerrjr��hash�r*�whenrrrrr�	test_hash�s
�zTimerTests.test_hashcCs4t��}t�|dd�dt���}|�||���dS)NcSsdSrrrrrrr��riz&TimerTests.test_when.<locals>.<lambda>r)r�r�rr�rrjr�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)rlrmrj)r�r�rr�rrjr�rprqr�r�r�r�r�r��AssertionErrorr')r*r�r�r�rrrrr�
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'rmrnrr�rkr{r|r�r�r�)r*rr�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)NTrlr�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'rmrnrrr�r�rr�rkr{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�ror��NotImplemented�__eq__�__ne__r�r�rrr
)r*r�r�Zh1Zh2Zh3rrr�test_timer_comparison0	sf((((z TimerTests.test_timer_comparison)r3r4r5rxr�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�)rrjr�AbstractEventLoopr��NotImplementedErrorr�r&r�r�rzr1rbr�rr�r�r�Zset_default_executorr�r�r�r�r�r�Zset_exception_handlerZdefault_exception_handlerr�rmr�)r*r8r'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)rrjrr�r�r�r�rar�r	rLr�r�Zsock_recv_intoZsock_sendallZsock_connectZsock_acceptZ
sock_sendfile�sendfiler��sentinelr�r�r)r)r8r'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_watcherra�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�rtr1)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�r0rrr8
sz1PolicyTests.test_get_event_loop_thread.<locals>.fr�)r�r�r�r�)r*Zm_current_threadr8Zthrr0r�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_implrrTrxr$r'r%rrr_r`rarbrVrrrx7
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)rrrrarTr}r'r1r%r�rr�r�r�r�r�r�r�r0rVrrr}Q
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)rErr�r�rr$r�r�r%rXr�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�rxr}rrr�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�SrrrrJrrr��
riz*TestServer.test_get_loop.<locals>.<lambda>rtr)
rr$rWr1rSr&rLr��get_loop�wait_closed)r*r'rmrrJr�
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$rWr1r�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�r/r�r�rrr�r�r�ImportErrorrBrr�r�r;rTrrxr�rrrrrZtest.test_asynciorr{r
r	Ztest.supportr
rrr
rr r(r)r�r6rSZDatagramProtocolrZraZBaseProtocolrcrHrdrwrZTestCaserTrXrer^r$rdrhrjrkrlr�r�r�r�r�Z_asyncior�r�r�r3r�rrrr�<module>s�

	" )Q������6f[y