HEX
Server: Apache
System: Linux zacp120.webway.host 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
User: govancoz (1003)
PHP: 8.3.26
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: //usr/local/lib/python3.10/test/test_asyncio/__pycache__/test_events.cpython-310.opt-2.pyc
o

�i)��@s�	ddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
zddlZWney6dZYnwddl
Z
ddlZddlZddlZddlZddlZddlmZddlZejdvrbddlZddlZddlmZddlmZddlmZddlmZddlmZdd	lmZdd
l m!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$�Z5ejd%k�rGd&d'�d'e4ej6�Z7Gd(d)�d)e4e5ej6�Z8nJddl9Z9Gd*d+�d+e4�Z:e;e9d,��r/Gd-d.�d.e:e5ej6�Z<e;e9d/��r@Gd0d1�d1e:e5ej6�Z=e;e9d2��rQGd3d4�d4e:e5ej6�Z>Gd5d'�d'e:e5ej6�Z7d6d7�Z?Gd8d9�d9ej6�Z@Gd:d;�d;ej6�ZAGd<d=�d=ej6�ZBGd>d?�d?ej6�ZCGd@dA�dA�ZDGdBdC�dCeDej6�ZEzddlFZFWn
e�y�YnwGdDdE�dEeDej6�ZGGdFdG�dGej6�ZHGdHdI�dIej6�ZIeJdJk�r�e�K�dSdS)K�N)�mock)�win32�vxworks)�
coroutines)�events)�proactor_events)�selector_events)�utils)�support)�
socket_helper)�threading_helper)�	ALWAYS_EQ�LARGEST�SMALLESTcCst�d�dS�N)�asyncio�set_event_loop_policy�rr�:/usr/local/lib/python3.10/test/test_asyncio/test_events.py�tearDownModule(�rcCsH	tj�d�r	dStjdkrdSt��d}ttt|�d���}|dkS)NZaixT�darwinFr�.)�
�)�sys�platform�
startswithZmac_ver�tuple�map�int�split)�versionrrr�broken_unix_getsockname,s
r#cCs&dd�}t��}t�|�|�|��S)Nc�s�dS�N�hellorrrrr�doit8��z8_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_proc7s
r,c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�CoroLikecC�dSrr)�self�vrrr�sendA�z
CoroLike.sendcGr.rr�r/�excrrr�throwDr2zCoroLike.throwcCr.rr�r/rrr�closeGr2zCoroLike.closecCr.rrr6rrr�	__await__Jr2zCoroLike.__await__N)�__name__�
__module__�__qualname__r1r5r7r8rrrrr-@s
r-c@sFeZdZdZdZddd�Zdd�Zdd�Zdd	�Zd
d�Z	dd
�Z
dS)�MyBaseProtoNcCs6d|_d|_d|_|dur|��|_|��|_dSdS�N�INITIALr)�	transport�state�nbytes�
create_future�	connected�done�r/r+rrr�__init__Rs
�zMyBaseProto.__init__cGs$|j|vrtd|j�d|����dS�Nzstate: z, expected: �r@�AssertionError�r/�expectedrrr�
_assert_stateZ�
�zMyBaseProto._assert_statecCs0||_|�d�d|_|jr|j�d�dSdS�Nr>�	CONNECTED�r?rLr@rC�
set_result�r/r?rrr�connection_made^s
�zMyBaseProto.connection_madecC� |�d�|jt|�7_dS�NrO�rLrA�len�r/�datarrr�
data_receivede�
zMyBaseProto.data_receivedcCs|�d�d|_dS)NrO�EOF)rLr@r6rrr�eof_receivedis

zMyBaseProto.eof_receivedcCs,|�dd�d|_|jr|j�d�dSdS)NrOr\�CLOSED�rLr@rDrQr3rrr�connection_lostms
�zMyBaseProto.connection_lostr)r9r:r;rCrDrFrLrSrZr]r`rrrrr<Ns
r<cseZdZ�fdd�Z�ZS)�MyProtocst��|�|�d�dS)Ns%GET / HTTP/1.0
Host: example.com

)�superrS�writerR��	__class__rrrSu�zMyProto.connection_made�r9r:r;rS�
__classcell__rrrdrratsrac@�BeZdZdZddd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)�MyDatagramProtoNcCs&d|_d|_|dur|��|_dSdSr=)r@rArBrDrErrrrF}�
�zMyDatagramProto.__init__cC�$|j|krtd|j�d|����dSrGrHrJrrrrL�rMzMyDatagramProto._assert_statecC�||_|�d�d|_dS)Nr>�INITIALIZED�r?rLr@rRrrrrS��

zMyDatagramProto.connection_madecCrT�NrnrV�r/rY�addrrrr�datagram_received�r[z!MyDatagramProto.datagram_receivedcCs|�d�dSrq)rLr3rrr�error_received�rzMyDatagramProto.error_receivedcC�*|�d�d|_|jr|j�d�dSdS)Nrnr^r_r3rrrr`��

�zMyDatagramProto.connection_lostr)
r9r:r;rDrFrLrSrtrur`rrrrrjzs
rjc@ri)�MyReadPipeProtoNcCs.dg|_d|_d|_|dur|��|_dSdSr=)r@rAr?rBrDrErrrrF�s�zMyReadPipeProto.__init__cCrlrGrHrJrrrrL�rMzMyReadPipeProto._assert_statecCs"||_|�dg�|j�d�dSrN)r?rLr@�appendrRrrrrS�szMyReadPipeProto.connection_madecCs$|�ddg�|jt|�7_dSrNrVrXrrrrZ��zMyReadPipeProto.data_receivedcCs|�ddg�|j�d�dS)Nr>rOr\)rLr@ryr6rrrr]�szMyReadPipeProto.eof_receivedcCsJd|jvr|j�d�|�gd��|j�d�|jr#|j�d�dSdS)Nr\)r>rOr\r^)r@ryrLrDrQr3rrrr`�s
�zMyReadPipeProto.connection_lostr)
r9r:r;rDrFrLrSrZr]r`rrrrrx�s
rxc@s2eZdZdZd
dd�Zdd�Zdd�Zdd	�ZdS)�MyWritePipeProtoNcCs&d|_d|_|dur|��|_dSdS)Nr>)r@r?rBrDrErrrrF�rkzMyWritePipeProto.__init__cCrlrGrHrJrrrrL�rMzMyWritePipeProto._assert_statecCrmrNrorRrrrrS�rpz MyWritePipeProto.connection_madecCrv�NrOr^r_r3rrrr`�rwz MyWritePipeProto.connection_lostr)r9r:r;rDrFrLrSr`rrrrr{�s
r{c@sDeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)�MySubprocessProtocolcsbd|_d|_���|_���|_�fdd�td�D�|_ddd�|_d|_t	�
�t	�
�d�|_dS)Nr>csi|]}|����qSr)rB)�.0�fd�r+rr�
<dictcomp>��z1MySubprocessProtocol.__init__.<locals>.<dictcomp>�����)r@r?rBrC�	completed�range�disconnectsrY�
returncoder�Event�got_datarErr�rrF�s

�zMySubprocessProtocol.__init__cCrlrGrHrJrrrrL�rMz"MySubprocessProtocol._assert_statecCs&||_|�d�d|_|j�d�dSrNrPrRrrrrS�s
z$MySubprocessProtocol.connection_madecCs |�d�d|_|j�d�dSr|)rLr@r�rQr3rrrr`�s
z$MySubprocessProtocol.connection_lostcCs.|�d�|j||7<|j|��dSrU)rLrYr��set)r/rrYrrr�pipe_data_received�s
z'MySubprocessProtocol.pipe_data_receivedcCs6|�d�|r|j|�|�dS|j|�|�dSrU)rLr��
set_exceptionrQ)r/rr4rrr�pipe_connection_lost�s
z)MySubprocessProtocol.pipe_connection_lostcCs|�d�|j��|_dSrU)rLr?Zget_returncoder�r6rrr�process_exited�s
z#MySubprocessProtocol.process_exitedN)
r9r:r;rFrLrSr`r�r�r�rrrrr}�sr}cs�eZdZ�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 �e�eed!�d"�d#d$���Ze�eed�d �e�eed!�d"�d%d&���Zd�d(d)�Zd*d+�Zejd,d-��Zd'd.ifd/d0�Z	'	.d�d1d2�Z	.d�d3d4�Ze�e d.ud5�d6d7��Z!eje�e d.ud5�d8d9���Z"d:d;�Z#d<d=�Z$d>d?�Z%d@dA�Z&d�dBdC�Z'e�e d.ud5�dDdE��Z(dFdG�Z)e*�+dH�dIdJ��Z,dKdL�Z-dMdN�Z.dOdP�Z/e�ee0dQ�dR�dSdT��Z1dUdV�Z2ejdWdX��Z3e�ee0dY�dZ�d[d\��Z4d�d]d^�Z5d�d_d`�Z6d�dadb�Z7e�e d.ud5�dcdd��Z8eje�e d.ud5�dedf���Z9e�e d.ud5�dgdh��Z:eje�e d.ud5�didj���Z;e�e d.ud5�dkdl��Z<eje�e d.ud5�dmdn���Z=e�e d.ud5�dodp��Z>dqdr�Z?dsdt�Z@e�ejAdu�dvdw��ZBdxdy�ZCdzd{�ZDd|d}�ZEe�ejAdu�d~d��ZFd�d��ZGd�d��ZHe�eIjJd�kd��d�d���ZKe�eIjJd�kd��d�d���ZLe�eIjJd�kd��e�eeMd��d��d�d����ZNe�eIjJd�kd��d�d���ZOe�eIjJd�kd��d�d���ZPe�eIjJd�kd��e�eeMd��d��eQ�Rd�d��d�d�����ZSe�eIjJd�kd��e�eeMd��d��eQ�Rd�d��d�d�����ZTd�d��ZUd�d��ZVd�d��ZWd�d��ZXd�d��ZYd�d��ZZ�Z[S)��EventLoopTestsMixincs$t���|��|_|�|j�dSr)rb�setUp�create_event_loopr+r)r6rdrrr�s

zEventLoopTestsMixin.setUpcs4|j��st�|j�|��t��t���dSr)	r+�	is_closed�
test_utils�run_brieflyZ
doCleanupsr
�
gc_collectrb�tearDownr6rdrrr�s

zEventLoopTestsMixin.tearDowncs\dd����fdd�}��td����t�jj|��Wd�dS1s'wYdS)Nc�s�t�d�IdHdS�Nr)r�sleeprrrr�coro1s�zBEventLoopTestsMixin.test_run_until_complete_nesting.<locals>.coro1c�s$����j����j����dSr)�
assertTruer+�
is_runningr*r�r�r/rr�coro2s�zBEventLoopTestsMixin.test_run_until_complete_nesting.<locals>.coro2zcoroutine \S+ was never awaited)ZassertWarnsRegex�RuntimeWarning�assertRaises�RuntimeErrorr+r*)r/r�rr�r�test_run_until_complete_nestings��"�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/�t0�t1rrr�test_run_until_complete&s

,z+EventLoopTestsMixin.test_run_until_completecs(�fdd�}|�}��t�jj|�dS)Nc�s ��j��t�d�IdHdS)Nr�)r+�stoprr�rr6rr�cb.s�
z?EventLoopTestsMixin.test_run_until_complete_stopped.<locals>.cb)r�r�r+r*)r/r�Ztaskrr6r�test_run_until_complete_stopped,s
�z3EventLoopTestsMixin.test_run_until_complete_stoppedcs>g���fdd�}�j�d|d��j�����dg�dS)Ncs��|��j��dSr�ryr+r���arg��resultsr/rr�callback8�
z5EventLoopTestsMixin.test_call_later.<locals>.callbackr�zhello world)r+�
call_later�run_forever�assertEqual�r/r�rr�r�test_call_later5�

z#EventLoopTestsMixin.test_call_latercs>g���fdd�}�j�|dd��j�����dg�dS)Ncs��||f��j��dSrr�)Zarg1Zarg2r�rrr�Csz4EventLoopTestsMixin.test_call_soon.<locals>.callbackr%�world)r%r�)r+�	call_soonr�r�r�rr�r�test_call_soon@r�z"EventLoopTestsMixin.test_call_sooncs�g�t�����fdd�����fdd�}���tj|d�}|�����j��d��j��Wd�n1s<wY|����	�ddg�dS)Nc�(��|�t��dkr�j��dSdS�Nr��ryrWr+r�r�r�rrr�O�
�z?EventLoopTestsMixin.test_call_soon_threadsafe.<locals>.callbackcs�j��d����dSr$)r+�call_soon_threadsafe�releaser)r��lockr/rr�
run_in_threadTszDEventLoopTestsMixin.test_call_soon_threadsafe.<locals>.run_in_thread��targetr�r%)
�	threading�Lock�acquire�Thread�startr+r�r��joinr�)r/r��tr)r�r�r�r/r�test_call_soon_threadsafeKs�z-EventLoopTestsMixin.test_call_soon_threadsafecsLg���fdd�}�j�|d��j�|d��j�����ddg�dS)Ncr�r�r�r�r�rrr�er�zKEventLoopTestsMixin.test_call_soon_threadsafe_same_thread.<locals>.callbackr%r�)r+r�r�r�r�r�rr�r�%test_call_soon_threadsafe_same_threadbs
z9EventLoopTestsMixin.test_call_soon_threadsafe_same_threadcCsHdd�}|j�d|d�}|j�|�\}}|�|d�|�|t���dS)NcSs|t��fSr)r��	get_identr�rrr�runpsz5EventLoopTestsMixin.test_run_in_executor.<locals>.runZyo)r+�run_in_executorr*r�ZassertNotEqualr�r�)r/r��f2�resZ	thread_idrrr�test_run_in_executoros
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_soonzszJEventLoopTestsMixin.test_run_in_executor_cancel.<locals>.patched_call_sooncSst�d�dS)Ng�������?)r�r�rrrrr�~rz<EventLoopTestsMixin.test_run_in_executor_cancel.<locals>.rung�������?)r+r��cancelr*Zshutdown_default_executorr7r�r�r�r��assertFalse)r/r�r�r�rr�r�test_run_in_executor_cancelws�

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)
NFcsXz��d�}Wn
tyYdSw|r��|�dS���j���������dS�N�)�recv�BlockingIOError�extendr�r+�
remove_reader�filenor7�rY��
bytes_read�rr/rr�reader�s�z8EventLoopTestsMixin.test_reader_callback.<locals>.readersabcc�t��dkS)Nr��rWr�r�rr�<lambda>��z:EventLoopTestsMixin.test_reader_callback.<locals>.<lambda>sdefcr�)N�r�rr�rrr��r�sabcdef)�socket�
socketpair�setblocking�	bytearrayr+�
add_readerr�r�r1r��	run_untilr7r�r�r�)r/�wr�rr�r�test_reader_callback�s


z(EventLoopTestsMixin.test_reader_callbackcs�t��\}���d���fdd�}d}�j����||��j�����j��������	�j��������
�|�t|�d�}|�
���
||�dS)NFcs��|��j��dSr)r1r+r�r��r/r�rr�writer�r�z8EventLoopTestsMixin.test_writer_callback.<locals>.writersxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxr�)r�r�r�r+�
add_writerr�r�r��
remove_writerr�r7r�rWr�)r/r�r�rY�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�Nr�rr��caughtrr�
my_handler�sz?EventLoopTestsMixin.test_add_signal_handler.<locals>.my_handlerZboomr����c��Srrrrrrr���z=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/rrrr�test_add_signal_handler�sP�
����
��
���z+EventLoopTestsMixin.test_add_signal_handler�SIGALRMz
No SIGALRM�	setitimerzneed signal.setitimer()cs^d���fdd�}�j�tj|�t�tjdd��j�d�jj��j����	�d�dS)Nrcs�d7��j��dSr)r+r�r�rr/rrr�szLEventLoopTestsMixin.test_signal_handling_while_selecting.<locals>.my_handler�{�G�z�?�<r��
r+rrrr�ITIMER_REALr�r�r�r�rrrr�$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��rr/Z	some_argsrrrszAEventLoopTestsMixin.test_signal_handling_args.<locals>.my_handlerr�rr�rrrrr�test_signal_handling_args�s
z-EventLoopTestsMixin.test_signal_handling_argsTcCsv|j�|�\}}|�|tj�|�|tj�|�|j|�|r'|�|�	d��|j�|j
�|�|jd�|�
�dS)N�socknamer)r+r*�assertIsInstancer�	Transport�Protocol�assertIsr?�assertIsNotNone�get_extra_inforD�
assertGreaterrAr7)r/�connection_fut�check_sockname�tr�prrrr�_basetest_create_connectionsz/EventLoopTestsMixin._basetest_create_connectioncsVt���}�jj�fdd�g|j�R�}��|�Wd�dS1s$wYdS)Nc�t�jd�S�Nr��rar+rr6rrr�r�z<EventLoopTestsMixin.test_create_connection.<locals>.<lambda>)r��run_test_serverr+�create_connection�addressr,)r/�httpd�conn_futrr6r�test_create_connections

��"�z*EventLoopTestsMixin.test_create_connectioncsZt�}t���}�j��fdd�|j�}��||�Wd�dS1s&wYdS)Ncr-r.r/rr6rrr�'r�zAEventLoopTestsMixin.test_create_unix_connection.<locals>.<lambda>)r#r��run_test_unix_serverr+�create_unix_connectionr2r,)r/r)r3r4rr6r�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�cipherr�rr�r�Z
ssl_object�compression)r%r&r�r!rrW�strr r<r;Zgetpeercert)r/�clientr)r9r:r;Zsslobjrrr�check_ssl_extra_info*s<��



�
�
�
�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�rer9�lowerr?rDr'rAr7)r/r(r)r9r*r+rrr�_basetest_create_ssl_connectionJsz3EventLoopTestsMixin._basetest_create_ssl_connectionc		s|t��d�}��|||�ttd�rLtjjfdddd��fdd�}tjd|d��}|dd�}��|||���	|j
d	�Wd�n1sGwY��tj��(}|dd�}t�
����|||�Wd�n1snwYWd�n1s}wY��	|jjd
�dS)N�r@�Purpose)�cafile�capath�cadatacs	��|tjj�t��Sr)r�r@rD�SERVER_AUTHr��dummy_ssl_context)ZpurposerErFrGr6rr�_dummy_ssl_create_context^szREventLoopTestsMixin._test_create_ssl_connection.<locals>._dummy_ssl_create_contextzssl.create_default_context)�side_effectTr�ZCERTIFICATE_VERIFY_FAILED)r�rIrB�hasattrr@rDrHr�patchr�Z
call_countr��SSLError�disable_logger�	exception�reason)	r/r3r1r)r9r4rJ�m�cmrr6r�_test_create_ssl_connectionVs:�
��
��	

����z/EventLoopTestsMixin._test_create_ssl_connectionz
No ssl modulecsftjdd��#}tj�jj�fdd�g|j�R�}�j|||jd�Wd�dS1s,wYdS)NT�Zuse_sslcr-r.r/rr6rrr��r�z@EventLoopTestsMixin.test_create_ssl_connection.<locals>.<lambda>�r9)r�r0�	functools�partialr+r1r2rT)r/r3r1rr6r�test_create_ssl_connection{s
���"�z.EventLoopTestsMixin.test_create_ssl_connectioncsnt�}tjdd��#}tj�jj�fdd�|jdd�}�j||||jd�Wd�dS1s0wYdS)NTrUcr-r.r/rr6rrr��r�zEEventLoopTestsMixin.test_create_ssl_unix_connection.<locals>.<lambda>�	127.0.0.1)�server_hostnamerV)	r#r�r6rWrXr+r7r2rT)r/r)r3r1rr6r�test_create_ssl_unix_connection�s��"�z3EventLoopTestsMixin.test_create_ssl_unix_connectioncs�t���>}t��}�jj�fdd�g|j�Rd|jd|fi�}�j�|�\}}|j�	d�d}��
||�|��Wd�dS1sEwYdS)Ncr-r.r/rr6rrr��r�zGEventLoopTestsMixin.test_create_connection_local_addr.<locals>.<lambda>�
local_addrrr r�)r�r0r�find_unused_portr+r1r2r*r?r&r�r7)r/r3�port�fr*r+rKrr6r�!test_create_connection_local_addr�s

���
"�z5EventLoopTestsMixin.test_create_connection_local_addrc�t��}t����jj���fdd�}|�j_�jj�fdd�d|d�fd�}��t���j�|�Wd�dS1s>wYdS)Nc�sL�|�krtjtjdddftjtjdddfgS�||g|�Ri|��IdHS)Nr���::1rrr�rZr)r��AF_INET6�SOCK_STREAM�AF_INET��hostr_r��kwargs��getaddrinfo_orig�port2rr�getaddrinfo�s��z`EventLoopTestsMixin.test_create_connection_local_addr_skip_different_family.<locals>.getaddrinfocr-r.r/rr6rrr��r�z]EventLoopTestsMixin.test_create_connection_local_addr_skip_different_family.<locals>.<lambda>�	localhost�r]�rr^r+rpr1r��OSErrorr*�r/Zport1rpr`r�rnror/r�7test_create_connection_local_addr_skip_different_family�s

�"�zKEventLoopTestsMixin.test_create_connection_local_addr_skip_different_familycrb)Nc�s<�|�krtjtjdddfgS�||g|�Ri|��IdHS)Nrrcrd)r�rgrhrjrmrrrp�s�zYEventLoopTestsMixin.test_create_connection_local_addr_nomatch_family.<locals>.getaddrinfocr-r.r/rr6rrr��r�zVEventLoopTestsMixin.test_create_connection_local_addr_nomatch_family.<locals>.<lambda>rqrrrsrurrvr�0test_create_connection_local_addr_nomatch_family�s

�"�zDEventLoopTestsMixin.test_create_connection_local_addr_nomatch_familyc	s�t���K}�jj�fdd�g|j�Rd|ji�}��t��}�j�|�Wd�n1s.wY��|j	j
t
j���t
|j�|j	j�Wd�dS1sRwYdS)Ncr-r.r/rr6rrr��r�zNEventLoopTestsMixin.test_create_connection_local_addr_in_use.<locals>.<lambda>r])r�r0r+r1r2r�rtr*r�rP�errno�
EADDRINUSE�assertInr=�strerror)r/r3r`rSrr6r�(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)rbr`r�r�r3)rer+rrr`��zQEventLoopTestsMixin.test_connect_accepted_socket.<locals>.MyProto.connection_lostcst��|�|j���dSr)rbrZr?rcrX)re�expected_responserrrZ�r~zOEventLoopTestsMixin.test_connect_accepted_socket.<locals>.MyProto.data_received)r9r:r;r`rZrhr)rr+rdrra�srarfr�)�backlogs	test datasrogerc
sxz#t��}�dur��|�}|���|���|�d��|��WdSty;}ztd|�WYd}~dSd}~ww)N�cz8Failure in client thread in test_connect_accepted_socket)r�Zwrap_socket�connect�sendallr�r7�	Exception�print)Zcsockr4)rs�
client_ssl�message�responserrr>�s



���z@EventLoopTestsMixin.test_connect_accepted_socket.<locals>.clientT)r��daemonr�crrrr��protorrr��rzBEventLoopTestsMixin.test_connect_accepted_socket.<locals>.<lambda>rCr^)r+r<r��
create_server�getsocknamer�r�r��acceptr*�connect_accepted_socketr�r?r7r�join_threadr��is_aliver�r@rArW)	r/Z
server_sslr�raZlsockr>�thread�conn�_r)rsr�rr+r�r�r�r�test_connect_accepted_socket�s4

��

z0EventLoopTestsMixin.test_connect_accepted_socketcCsLtjdkrtjdkrt|jtj�rt�d��t	�
�}t	��}|�||�dS)Nr)r�rz=SSL not supported with proactor event loops before Python 3.5)
rr�version_info�
isinstancer+rZBaseProactorEventLoop�unittest�SkipTestr�Zsimple_server_sslcontextZsimple_client_sslcontextr�)r/Zserver_contextZclient_contextrrr� test_ssl_connect_accepted_socket
s

��z4EventLoopTestsMixin.test_ssl_connect_accepted_socketcCsft��}|�|j�|jjt|tjd�}|�t	d��|j�
|�Wd�dS1s,wYdS)N)Zssl_handshake_timeoutz1ssl_handshake_timeout is only meaningful with ssl)r��
addCleanupr7r+r�rar
ZLOOPBACK_TIMEOUT�assertRaisesRegexr
r*)r/�sock�cororrr�9test_connect_accepted_socket_ssl_timeout_for_plain_sockets��"�zMEventLoopTestsMixin.test_connect_accepted_socket_ssl_timeout_for_plain_socketzasyncio.base_events.socketc	s��fdd����fdd�}t|�}�tjkr"dd�|D�|��j_ndd�|D�|��j_|�j_t���j_	t���j_
�j��fdd	�|d
�}�j�|�}��
|j�dd�|jD�}��||�dS)
Nc�s<��tjkr�tjdd||ffgS�tjdd||ddffgS)Nr�rcr)r�rirh)rkr_r��kw)�familyrrrp%s�
zEEventLoopTestsMixin.create_server_multiple_hosts.<locals>.getaddrinfocs�j��|i|���Sr)r+�create_task)r��kwds)rpr/rr�getaddrinfo_task+szJEventLoopTestsMixin.create_server_multiple_hosts.<locals>.getaddrinfo_taskcSsg|]}|df�qS)�Pr�r~rkrrr�
<listcomp>1s�zDEventLoopTestsMixin.create_server_multiple_hosts.<locals>.<listcomp>cSsg|]}|dddf�qS)r�rrr�rrrr�4s�cs
t�j�Srr/rr6rrr�9�
zBEventLoopTestsMixin.create_server_multiple_hosts.<locals>.<lambda>r�cSsh|]}|��d�qS)r)�
getsockbyname)r~r�rrr�	<setcomp><szCEventLoopTestsMixin.create_server_multiple_hosts.<locals>.<setcomp>)r�r�rir�rKr+rpr�MockZ_start_serving�
_stop_servingr�r*r�r7�socketsr�)	r/r�ZhostsZ	mock_sockr�Zunique_hostsr`�serverZserver_hostsr)r�rpr/r�create_server_multiple_hosts#s$
��z0EventLoopTestsMixin.create_server_multiple_hostscC�|�tjgd��dS)N)�1.2.3.4z5.6.7.8r�)r�r�rir6rrr�&test_create_server_multiple_hosts_ipv4?��z:EventLoopTestsMixin.test_create_server_multiple_hosts_ipv4cCr�)N)rez::2re)r�r�rgr6rrr�&test_create_server_multiple_hosts_ipv6Cr�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)Ncrrrrr�rrr�Irz8EventLoopTestsMixin.test_create_server.<locals>.<lambda>�0.0.0.0rr�rZ�xxxrOc�
�jdkSr��rArr�rrr�Vr�r�r r9r^)rar+r�r*r�rWr�r�r�r�r�rCr@r�r�rAr%r?r&r7rD�r/r`r�r�rkr_r>rr�r�test_create_serverGs.


�
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)	Ncrrrrr�rrr�orzCEventLoopTestsMixin.test_create_server_reuse_port.<locals>.<lambda>r�rr�crrrrr�rrr�|rT)�
reuse_port)rar+r�r*r�rWr�r��
getsockoptr��
SOL_SOCKETr�r7r�r�r�)r/r`r�r�rr�r�test_create_server_reuse_portks6
�
��
�
��z1EventLoopTestsMixin.test_create_server_reuse_portcsDt���|��fdd��|jj|�fi|��}|j�|�}|�fS)Ncstj���o
t���Sr)r�path�exists�unlinkr�r�rrr��r�z7EventLoopTestsMixin._make_unix_server.<locals>.<lambda>)r�Zgen_unix_socket_pathr�r+�create_unix_serverr*)r/�factoryrlr`r�rr�r�_make_unix_server�s
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)
Nr�crrrrr�rrr��rz=EventLoopTestsMixin.test_create_unix_server.<locals>.<lambda>r�r�rOcr�r�r�rr�rrr��r�r�r^)rar+r�r�rWr�r��AF_UNIXr�r�r*rCr@r�r�rAr?r7rD)r/r�r�r>rr�r�test_create_unix_server�s


z+EventLoopTestsMixin.test_create_unix_serverr�zNo UNIX Socketsc	s�t|jd��t��}|�:|jj�fdd�d|d�}|�td��|j�|�Wd�n1s1wYWd�dSWd�dS1sIwYdS)Nr�crrrrr�rrr��rzOEventLoopTestsMixin.test_create_unix_server_path_socket_error.<locals>.<lambda>z/test�r�z3path and sock can not be specified at the same time)rar+r�r�r�r
r*)r/r�r`rr�r�)test_create_unix_server_path_socket_error�s���"�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_context�sz'EventLoopTestsMixin._create_ssl_contextc
CsX|�||�}|jj|dd|d�}|j�|�}|jd}|��\}}	|�|d�|||	fS)NrZrrC)r�r+r�r*r�r�r�)
r/r�r�r�r�r`r�r�rkr_rrr�_make_ssl_server�s

z$EventLoopTestsMixin._make_ssl_servercCs|�||�}|j||d�S)NrC)r�r�)r/r�r�r�r�rrr�_make_ssl_unix_server�rfz)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)Nr�crrrrr�rrr��rz<EventLoopTestsMixin.test_create_server_ssl.<locals>.<lambda>rCr�rOcr�r�r�rr�rrr��r�r�rVr^)rar+r�r��ONLYCERT�ONLYKEYr1r<rIr*rcrCr�r@r�rAr?r?r7rD)r/r�rkr_�f_cr>r+rr�r�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)Nr�crrrrr�rrr��rzAEventLoopTestsMixin.test_create_unix_server_ssl.<locals>.<lambda>rc�r@r[r�rOcr�r�r�rr�rrr��r�r�r^)rar+r�r�r�r�r7r<rIr*rcrCr�r@r�rAr?r7rD)r/r�r�r�r>r+rr�r�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���%|�tjd��|j�|�Wd�n1s^wYWd�n1smwYt�|j�Wd�n1s�wY|��j�|��dS)	Nr�crrrrr�rrr�
rzJEventLoopTestsMixin.test_create_server_ssl_verify_failed.<locals>.<lambda>�check_hostnameTrC�call_exception_handler�(?i)certificate.verify.failed)rar+r�r��SIGNED_CERTFILEr@r��PROTOCOL_TLS_CLIENTr�r��
CERT_REQUIRED�verify_moderLr�r1rrM�objectrOr�rNr*r��assertIsNoner?r7�r/r�rkr_�sslcontext_clientr�rr�r�$test_create_server_ssl_verify_failed	s2
�
�
�����
z8EventLoopTestsMixin.test_create_server_ssl_verify_failedc
s$t|jd��|��fdd�tj�\}}t�tj�}|jtj	O_tj
|_t|d�r-d|_
|jjt||dd�}tj�|jd��?t���%|�tjd	��|j�|�Wd�n1s]wYWd�n1slwYt�|j�Wd�n1s�wY|��j�|��dS)
Nr�crrrrr�rrr�+rzOEventLoopTestsMixin.test_create_unix_server_ssl_verify_failed.<locals>.<lambda>r�T�invalidr�r�r�)rar+r�r�r�r@r�r�r�r�r�r�rLr�r7rrMr�rOr�rNr*r�r�r?r7)r/r�r�r�r�rr�r�)test_create_unix_server_ssl_verify_failed&s4�

�
�����
z=EventLoopTestsMixin.test_create_unix_server_ssl_verify_failedc
s(t|jd��|��fdd�tj�\}}}t�tj�}|jtj	O_tj
|_|jtj
d�t|d�r5d|_|jjt|||d�}tj�|jd��9t���%|�tjd	��|j�|�Wd�n1sewYWd�n1stwYWd�n1s�wY|��j�|��dS)
Nr�crrrrr�rrr�HrzIEventLoopTestsMixin.test_create_server_ssl_match_failed.<locals>.<lambda>�rEr�TrCr�z=IP address mismatch, certificate is not valid for '127.0.0.1')rar+r�r�r�r@r�r�r�r�r�r��load_verify_locations�
SIGNING_CArLr�r1rrMr�rOr�ZCertificateErrorr*r�r?r7r�rr�r�#test_create_server_ssl_match_failedDs:
��
�
������
z7EventLoopTestsMixin.test_create_server_ssl_match_failedcs�t|jd��|��fdd�tj�\}}t�tj�}|jtj	O_tj
|_|jtj
d�t|d�r4d|_|jjt||dd�}|j�|�\}}|j��j��j��|��|��|j��j�dS)	Nr�crrrrr�rrr�grzJEventLoopTestsMixin.test_create_unix_server_ssl_verified.<locals>.<lambda>r�r�Trqr�)rar+r�r�r�r@r�r�r�r�r�r�r�r�rLr�r7r*rCr?r7rD)r/r�r�r�r�r>r+rr�r�$test_create_unix_server_ssl_verifiedbs(�

�
z8EventLoopTestsMixin.test_create_unix_server_ssl_verifiedcs�t|jd��|��fdd�tj�\}}}t�tj�}|jtj	O_tj
|_|jtj
d�t|d�r5d|_|jjt|||dd�}|j�|�\}}|j��j�|j|||ftjd	��j��|��|��|j��j�dS)
Nr�crrrrr�rrr��rzEEventLoopTestsMixin.test_create_server_ssl_verified.<locals>.<lambda>r�r�Trqr�)r9r:)rar+r�r�r�r@r�r�r�r�r�r�r�r�rLr�r1r*rCr?ZPEERCERTr?r7rD)r/r�rkr_r�r�r>r+rr�r�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)	Nc�eZdZ��fdd�Z�ZS)z@EventLoopTestsMixin.test_create_server_sock.<locals>.TestMyProtoc�t��|���|�dSr�rbrSrQrR)rer�rrrS�rfzPEventLoopTestsMixin.test_create_server_sock.<locals>.TestMyProto.connection_madergrr�rdr�TestMyProto��r��r�rr�rr�rZr�)
r+rBrar�r�r*r�r�r�r�r�r1r7)	r/r��sock_obr`r�r�rkr_r>rr�r�test_create_server_sock�s



z+EventLoopTestsMixin.test_create_server_sockcCs�t�d�}|jjt|d�}|j�|�}|jd}|��\}}|jjt||d�}|�t��}|j�|�Wd�n1s=wY|�	|j
jtj�|�
�dS)Nr�r�r�rkr_)r�r�r+rar*r�r�r�rtr�rPryrzr7)r/r�r`r�r�rkr_rSrrr�test_create_server_addr_in_use�s

�z2EventLoopTestsMixin.test_create_server_addr_in_usezIPv6 not supported or enabledc	
s.|j���G�fdd�dt�}d}	zt��}|jj|d|d�}|j�|�}Wn#tyJ}z|jtj	krE|d7}|�
d|�WYd}~q�d}~ww	t��}|�d|f�|�
d	�|j���}|j��|��|j���t�tj�}|�d
|f�|�
d	�|j���}|j��|��|��dS)Ncr�)zFEventLoopTestsMixin.test_create_server_dual_stack.<locals>.TestMyProtocr�rr�rR)re�f_protorrrS�rfzVEventLoopTestsMixin.test_create_server_dual_stack.<locals>.TestMyProto.connection_madergr�r�rdrr��r�r�rTr�r�rrZr�re)r+rBrarr^r�r*rtryrzZassertGreaterEqualr�r�r1r?r7rg)	r/r�Z	try_countr_r`r��exr>r�rr�r�test_create_server_dual_stack�s>
��




z1EventLoopTestsMixin.test_create_server_dual_stackcCs�|j�tdd�}|j�|�}|jd}|��\}}t��}|�d|f�|�d�|�	�|�	�t��}|�
t|jd|f�|�	�dS)Nr�rrZr�)r+r�rar*r�r�r�r�r1r7r��ConnectionRefusedErrorr�rrr�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.)rbrFr+)Z
inner_self)rer/rrrF�szXEventLoopTestsMixin._test_create_datagram_endpoint.<locals>.TestMyDatagramProto.__init__cs$t��||�|j�d||�dS)Nsresp:)rbrtr?�sendtorrrdrrrtrzzaEventLoopTestsMixin._test_create_datagram_endpoint.<locals>.TestMyDatagramProto.datagram_received)r9r:r;rFrtrhrr6rdr�TestMyDatagramProto�sr�)r]r�r rncr-r.�rjr+rr6rrr�r�zDEventLoopTestsMixin._test_create_datagram_endpoint.<locals>.<lambda>)Zremote_addrr�c��jSrr�r)r�rrr��r�crrr�r)r>rrr�r�r^)rjr+�create_datagram_endpointr*r&r��getnameinfo�NI_NUMERICHOST�NI_NUMERICSERVr!rr"r�r@r$r?r�r�r�rAr%r7rD)
r/r]r�r�r�Zs_transportr rkr_r?r)r>r/r�r�_test_create_datagram_endpoint�s@�
�
�
z2EventLoopTestsMixin._test_create_datagram_endpointcC�|�dtj�dS)Nrf)rr�rir6rrr�test_create_datagram_endpoint,sz1EventLoopTestsMixin.test_create_datagram_endpointcCr	)N)rer)rr�rgr6rrr�"test_create_datagram_endpoint_ipv6/sz6EventLoopTestsMixin.test_create_datagram_endpoint_ipv6cs�d}d}�j��jj|dtji��}|D]"\}}}}}ztj|||d�}|�d�|�|�WnYqn��d��jj�fdd�|d�}	�j�|	�\}
}��	|
t
j���	|t�|
�
��j�|j�dS)	Nrf�type)r�rr�FzCan not create socket.cr-r.rrr6rrr�Fr�zHEventLoopTestsMixin.test_create_datagram_endpoint_sock.<locals>.<lambda>r�)r+r*rpr��
SOCK_DGRAMr��bindZfailrr!rr"rjr7rD)r/r�Z
local_addressZinfosr�rr�Zcnamer2r`r*r+rr6r�"test_create_datagram_endpoint_sock3s4���

�z6EventLoopTestsMixin.test_create_datagram_endpoint_sockcCsf|��}t|tj�s|��|�d�|�d|j�|��|�d|j�|�|j	�|�|j
�dS)Nz#loop is not a BaseSelectorEventLoopr�r)r�r�rZBaseSelectorEventLoopr7ZskipTestr�Z
_internal_fdsr�Z_csockZ_ssockrErrr�test_internal_fdsMs
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)Nr��rbr�c��`��j��fdd���IdH\}}��|����|�j���ddg�j���d�j�dS)Ncrrrrr�rrr�crzEEventLoopTestsMixin.test_read_pipe.<locals>.connect.<locals>.<lambda>r>rOr�r+�connect_read_piper$r?r�r@rA�r��p��pipeobjr�r/rrr�as��z3EventLoopTestsMixin.test_read_pipe.<locals>.connect�1c�
�jdkSrr�rr�rrr�lr�z4EventLoopTestsMixin.test_read_pipe.<locals>.<lambda>r��2345cr�Nrr�rr�rrr�pr�r>rOr�r>rOr\r^�pipe)rxr+rr�io�openr*rcr�r�r�rAr@r7rDr%r?r&)r/�rpipe�wpiper�rrr�test_read_pipeYs$

�z"EventLoopTestsMixin.test_read_pipecs�|���t�d��t�d��t��\}}t�|dd��tj|dddd�������fdd�}��|��\}}���|�	d	t
|��|�	d	t
|��������d|_d|_dS)
Nr�rr�r�zutf-8)�encodingc�sF����fdd���IdH\}}���fdd���IdH\}}||fS)Ncrrrr��
read_protorrr��rzSEventLoopTestsMixin.test_unclosed_pipe_transport.<locals>.connect.<locals>.<lambda>crrrr��write_protorrr��r)r�connect_write_pipe)�read_transportr��write_transport�r+r&ZrpipeobjZwpipeobjr(rrr��s���zAEventLoopTestsMixin.test_unclosed_pipe_transport.<locals>.connectr )r�rxr{rrrr r*r7r{�reprZ_pipe)r/r!r"r�r*r+rr,r�test_unclosed_pipe_transport{s


z0EventLoopTestsMixin.test_unclosed_pipe_transport�openptyzneed os.openpty()cst�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)Nr�rrc�r)Ncrrrrr�rrr��rzKEventLoopTestsMixin.test_read_pty_output.<locals>.connect.<locals>.<lambda>r>rOrrr�Zmaster_read_objr�r/rrr��s��z9EventLoopTestsMixin.test_read_pty_output.<locals>.connectrcrrr�rr�rrr��rz:EventLoopTestsMixin.test_read_pty_output.<locals>.<lambda>r�rcrrr�rr�rrr��r�r>rOrrr)rxr+rr/rr r*rcr�r�r�rAr@r7r?rDr%r&)r/�master�slaver�rr0r�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�r�crrrrr�rrr��rz5EventLoopTestsMixin.test_write_pipe.<locals>.<lambda>rOrc�t��d�}||7}t|�Sr��rr�rW�rY�chunk)r!rrr���z3EventLoopTestsMixin.test_write_pipe.<locals>.readerc����dkSrrr�rYr�rrr��r�rcr:rrrr;rrr��r��12345rr^)rrrr r{r+r)r*r$r?r�r@rcr�r�r�r7r%r&rD)r/r"rr�r?rr)rYr�r�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)
NFr4r�r�crrrrr�rrr��rzIEventLoopTestsMixin.test_write_pipe_disconnect_on_close.<locals>.<lambda>rOrr^)r�r�r�rr �detachr{r+r)r*r$r?r�r@rc�	sock_recvr7rD)r/ZrsockZwsockrr�r?rrYrr�r�#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)Nr4rr�crrrrr�rrr�
rz4EventLoopTestsMixin.test_write_pty.<locals>.<lambda>rOrcr5r�r6r7�r1rrr�r9z2EventLoopTestsMixin.test_write_pty.<locals>.readercr:rrrr;rrr�r���timeoutrcr:rrrr;rrr�r�r<rr^)rr/rr r{r+r)r*r$r?r�r@rcr�r�r�r
�
SHORT_TIMEOUTr7r%r&rD)r/r2�slave_write_objr�r?rr)rYr1r�r�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)Nrrr�crrrrr%rrr�9rz<EventLoopTestsMixin.test_bidirectional_pty.<locals>.<lambda>r>rOr4crrrrr'rrr�Drcr5r�r6r7rArrr�Lr9z:EventLoopTestsMixin.test_bidirectional_pty.<locals>.readerrcr:rrrr;rrr�Rr�rB�acrrr�rr%rrr�Yr�r�rcr:rrrr;rrr�`r�r<sbcdecrrr�rr%rrr�gr�rrr^)rr/�dup�ttyZsetrawrr rxr+rr*r$r?r�r@rAr{r)r�rcr�r�r
rDr7rD)
r/Z
read_slaveZwrite_slaveZslave_read_objZread_connectr*rrEZ
write_connectr+r)rYr1r&r�r(r�test_bidirectional_pty,sz

��
��
��

�z*EventLoopTestsMixin.test_bidirectional_ptycs�t��\}}|�d��j��j�|d���t�dd�}|dur&��|j���fdd�}t	�
�}�j�|��}�j��t	�
�|}��|d���
|��d���tj�j�|durc��|j��j�|�|��|��dS)NFr��ovc�sj�z-z�j��j��IdHWntjyd}Ynwd}W�j��|SW�j��|S�j��w)N�	cancelled)r+r�r�r�CancelledErrorr�)r��r`r/rr�main�s��
�
�z:EventLoopTestsMixin.test_prompt_cancellation.<locals>.mainr�rL)r�r�r�r+r�r?�getattrr��pendingr��	monotonicr�Z
assertLessr��resultr�rrMr�r�r7)r/r�r�rKrOr�r��elapsedrrNr�test_prompt_cancellationxs&

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_once�s
z<EventLoopTestsMixin.test_timeout_rounding.<locals>._run_oncerc�s\��j}t�d�IdHt�d�IdHt�d�IdHt�d�IdHt�d�IdHdS)Nrg-C��6?g���ư>g:�0�yE>g�����|�=)r+rr�r�r6rr�wait�s�z7EventLoopTestsMixin.test_timeout_rounding.<locals>.wait�)Zclock_resolution�selector)	r+rXrVr*ZassertLessEqualZ_clock_resolution�	_selectorrer9)r/rXrYrrWr�test_timeout_rounding�s
��z)EventLoopTestsMixin.test_timeout_roundingcCsx|��}dd�}t��\}}|�|j�|�|j�|�||�|�||�|��|�|�|��|�|�	|��dS)NcSr.rrrrrrr��rzCEventLoopTestsMixin.test_remove_fds_after_closing.<locals>.<lambda>)
r�r�r�r�r7r�r�r�r�r��r/r+r�r�r�rrr�test_remove_fds_after_closing�sz1EventLoopTestsMixin.test_remove_fds_after_closingcCs�|��}dd�}t��\}}|�|j�|�|j�|��|�t��|�||�Wd�n1s4wY|�t��|�||�Wd�dS1sPwYdS)NcSr.rrrrrrr��rz@EventLoopTestsMixin.test_add_fds_after_closing.<locals>.<lambda>)	r�r�r�r�r7r�r�r�r�r^rrr�test_add_fds_after_closing�s�"�z.EventLoopTestsMixin.test_add_fds_after_closingcsR�fdd�}|�j�}��t���j�|�Wd�dS1s"wYdS)Nc�s��j��dSr)r+r7r�r6rr�
close_loop�s�zEEventLoopTestsMixin.test_close_running_event_loop.<locals>.close_loop)r+r�r�r*)r/rar�rr6r�test_close_running_event_loop�s

"�z1EventLoopTestsMixin.test_close_running_event_loopcCsB|j��dd�}dd�}|�}|�|j�|�t��
|j��Wd�n1s+wY|�t��|j��}|j�|�Wd�n1sKwY|�t��|j�|�Wd�n1sfwY|�t��|j�	|�Wd�n1s�wY|�t��|j�
d|�Wd�n1s�wY|�t��|j�|j��d|�Wd�n1s�wY|�t��|j�
|�Wd�n1s�wY|�t��|j�tj|�Wd�n1s�wY|�t��|j�d|���}t|�Wd�dS1�swYdS)Nc�s�dSrrrrrr�test�r'z,EventLoopTestsMixin.test_close.<locals>.testcS�dS�NFrrrrrr��rz0EventLoopTestsMixin.test_close.<locals>.<lambda>g�?g)r+r7r�r�r�r�rBr*r�r�r��call_atr�r�rr�SIGTERMr�r8�next)r/rc�funcr��fut�itrrr�
test_close�sD
�
�������
$�zEventLoopTestsMixin.test_close)T)TN)NNr)\r9r:r;r�r�r�r�r�r�r�r�r�r�r�r�r�r��
skipUnlessrLrrrrr,r5rZskip_unless_bind_unix_socketr8r?rBrT�skipIfr@rYr\rarwrxr}r�r�r�rrMr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�ZIPV6_ENABLEDr�r�rr
rrrrrr#r.rr3r=r@r
�requires_mac_verrFrJrUr]r_r`rbrlrhrrrdrr�s
		

+��



�!
�
�%
	

6


$
	










(0
�
 �
 �!�
%�
�
'�
F#r�c@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)$�SubprocessTestsMixincC�.tjdkr
|�|t�dS|�tj|�dS�Nr)rrr!r r�rrg�r/r�rrr�check_terminated��
z%SubprocessTestsMixin.check_terminatedcCrqrr)rrr!r r�rr�rsrrr�check_killedruz!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]wY|j�|j�|�|j�|�d|jd�dS)N�echo.pyrOr�Python The Winnerr�)rr�r��dirname�__file__r+�subprocess_execrWrXr}r�
executabler*r!rCr�r@�get_pipe_transportrcr�rYr�rOr7r�rvr�rY�r/�progr��transpr��stdinrrr�test_subprocess_exec
s$�



�z)SubprocessTestsMixin.test_subprocess_execcCs4tj�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�n1s�wY|j�|j�|�|j�dS)NrwrOrsPython r�s
The Winnerrx)rr�r�ryrzr+r{rWrXr}rr|r*r!rCr�r@r}rcr�rY�clearrYr�rOr7r�rvr�r~rrr�test_subprocess_interactives,�




�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)rD)r~r`rrr�	<genexpr>Es�z=SubprocessTestsMixin.test_subprocess_shell.<locals>.<genexpr>r�s
sPythonr�r�)r+�subprocess_shellrWrXr}r*r!rCr}r7r�r�r�r��allr��valuesrY�rstrip�r/r�r�r�rrr�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�rWrXr}r*r!r�r�r�r7r�rrr�test_subprocess_exitcodeJs�z-SubprocessTestsMixin.test_subprocess_exitcodecCs�|jjt�t|j�ddddd�}|j�|�\}}|�|t�|�|�d��|�|�d��|�|�d��|j�|j	�|�
d|j�|�|���dS)Nr�r�rr�r�r�)
r+r�rWrXr}r*r!r�r}r�r�r�r7r�rrr�"test_subprocess_close_after_finishUs�z7SubprocessTestsMixin.test_subprocess_close_after_finishcC�tj�tj�t�d�}|j�t�t	|j�t
j|�}|j�|�\}}|�
|t	�|j�|j�|��|j�|j�|�|j�|��dS�Nrw)rr�r�ryrzr+r{rWrXr}rr|r*r!rCrr�rvr�r7�r/rr�r�r�rrr�test_subprocess_killc��z)SubprocessTestsMixin.test_subprocess_killcCr�r�)rr�r�ryrzr+r{rWrXr}rr|r*r!rC�	terminater�rtr�r7r�rrr�test_subprocess_terminatesr�z.SubprocessTestsMixin.test_subprocess_terminaterzDon't have SIGHUPc
Cs�t�tjtj�}zRtj�tj�t�d�}|j�	t
�t|j�t
j|�}|j�|�\}}|�|t�|j�|j�|�tj�|j�|j�|�tj|j�|��Wt�tj|�dSt�tj|�wr�)r�SIGHUP�SIG_DFLrr�r�ryrzr+r{rWrXr}rr|r*r!rC�send_signalr�r�r�r7)r/Zold_handlerrr�r�r�rrr�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:testr�r�sERR:test)rr�r�ryrzr+r{rWrXr}rr|r*r!rCr}rcr�r7r�rYr�rr�r~rrr�test_subprocess_stderr�s�

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�)r�rr�r�r�sOUT:testERR:testr�)rr�r�ryrzr+r{rWrXr}rr|�
subprocess�STDOUTr*r!rCr}r%r�rcr�r�rYrr�r7r�r~rrr�)test_subprocess_stderr_redirect_to_stdout�s&
�

�z>SubprocessTestsMixin.test_subprocess_stderr_redirect_to_stdoutcCsZtj�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�n1s�wY|j�|j�|�|j�dS)Nzecho3.pyrr�r�r�r�r�rsERR:BrokenPipeErrorsERR:OSError)rr�r�ryrzr+r{rWrXr}rr|r*r!rCr}rcr�rYr�rYr7r�rr�rOr�rvr�)r/rr�r�r�r�r�rrr�#test_subprocess_close_client_stream�s2�






�z8SubprocessTestsMixin.test_subprocess_close_client_streamcCsf|jjt�t|j�dddddd�}|j�|�\}}|�|t�|j�|j�|�d|j	�|�
�dS)Nr�T)r�r�r��start_new_sessionr�r�r�rrr�"test_subprocess_wait_no_same_group�s�z7SubprocessTestsMixin.test_subprocess_wait_no_same_groupcs��fdd�}��t���j�|dd��Wd�n1swY��t���j�|dd��Wd�n1s=wY��t���j�|dd��Wd�dS1s\wYdS)Nc�s$��jjtjdfi|��IdHdS�N�pwd)r+r{r�SubprocessProtocol)r�r6rrr��s���zGSubprocessTestsMixin.test_subprocess_exec_invalid_args.<locals>.connectT��universal_newlines���bufsize��shell�r�r
r+r*�r/r�rr6r�!test_subprocess_exec_invalid_args�s��"�z6SubprocessTestsMixin.test_subprocess_exec_invalid_argscsd�fdd�	}��t���j�|ddg��Wd�n1s!wY��t���j�|dd��Wd�n1s?wY��t���j�|dd��Wd�n1s]wY��t���j�|d	d
��Wd�dS1s|wYdS)Nc�s,�|sd}�jjtj|fi|��IdHdSr�)r+r�rr�)�cmdr�r6rrr�s���zHSubprocessTestsMixin.test_subprocess_shell_invalid_args.<locals>.connectZlsz-lTr�r�r�Fr�rr�r�rr6r�"test_subprocess_shell_invalid_argss���"�z7SubprocessTestsMixin.test_subprocess_shell_invalid_argsN)r9r:r;rtrvr�r�r�r�r�r�r�r�rnrrr�r�r�r�r�r�r�rrrrrp�s$
"
rprc@�eZdZdd�ZdS)�SelectEventLoopTestscC�t��Sr)r�SelectorEventLoopr6rrrr���&SelectEventLoopTests.create_event_loopN�r9r:r;r�rrrrr�sr�c@s<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�ProactorEventLoopTestscCr�r)rZProactorEventLoopr6rrrr�$r�z(ProactorEventLoopTests.create_event_loopcC�
t�d���Nz(IocpEventLoop does not have add_reader()�r�r�r6rrrr�'�
z+ProactorEventLoopTests.test_reader_callbackcCr�r�r�r6rrr�test_reader_callback_cancel*r�z2ProactorEventLoopTests.test_reader_callback_cancelcCr��Nz(IocpEventLoop does not have add_writer()r�r6rrrr�-r�z+ProactorEventLoopTests.test_writer_callbackcCr�r�r�r6rrr�test_writer_callback_cancel0r�z2ProactorEventLoopTests.test_writer_callback_cancelcCr�r�r�r6rrrr_3r�z4ProactorEventLoopTests.test_remove_fds_after_closingN)	r9r:r;r�r�r�r�r�r_rrrrr� sr�cs(eZdZ�fdd�Z�fdd�Z�ZS)�UnixEventLoopTestsMixincs,t���t��}|�|j�t�|�dSr)rbr�r�SafeChildWatcher�attach_loopr+�set_child_watcher�r/Zwatcherrdrrr�9s
zUnixEventLoopTestsMixin.setUpcst�d�t���dSr)rr�rbr�r6rdrrr�?r�z UnixEventLoopTestsMixin.tearDown)r9r:r;r�r�rhrrrdrr�8sr��KqueueSelectorcs\eZdZdd�Ze�dd�e�ej	�
d�d��fdd���Ze�dd��fd	d
��Z�Z
S)�KqueueEventLoopTestscC�t�t���Sr)rr��	selectorsr�r6rrrr�Is�z&KqueueEventLoopTests.create_event_loopr�	Zopenbsdztest hangs on OpenBSDc�t���dSr)rbr3r6rdrrr3Osz)KqueueEventLoopTests.test_read_pty_outputcr�r)rbrFr6rdrrrFYsz#KqueueEventLoopTests.test_write_pty)r9r:r;r�r
ror�rnrrrr3rFrhrrrdrr�Es
�
r��
EpollSelectorc@r�)�EPollEventLoopTestscCr�r)rr�r�r�r6rrrr�brz%EPollEventLoopTests.create_event_loopNr�rrrrr�^�r��PollSelectorc@r�)�PollEventLoopTestscCr�r)rr�r�r�r6rrrr�jrz$PollEventLoopTests.create_event_loopNr�rrrrr�fr�r�c@r�)r�cCr�r)rr�r��SelectSelectorr6rrrr�rrr�Nr�rrrrr�nr�cOr.rr)r�rlrrr�noopvr2r�csheZdZ�fdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	e
�ee
jd�d�dd��Z�ZS)�HandleTestscs"t���t��|_d|jj_dSr�)rbr�rr�r+�	get_debug�return_valuer6rdrrr�|s

zHandleTests.setUpcCs`dd�}d}t�|||j�}|�|j|�|�|j|�|�|���|��|�	|���dS)NcW�|Srrr�rrrr��r2z)HandleTests.test_handle.<locals>.callbackr)
r�Handler+r$�	_callback�_argsr�rLr�r�)r/r�r��hrrr�test_handle�szHandleTests.test_handlecCs\dd�}t��|_t��|j_t�|d|j�}|��|jj�t�	d�tj
||jd��dS)NcSst��r)r
rrrrr��sz:HandleTests.test_callback_with_exception.<locals>.callbackrzException in callback.*)r�rP�handleZsource_traceback)rr�r+r�rr�Z_run�assert_called_withr�ZMockPattern�ANY�_source_traceback)r/r�r�rrr�test_callback_with_exception�s
�z(HandleTests.test_callback_with_exceptioncCs(t��}t�dd�d|j�}||d<dS)NcSr.rrrrrrr��rz1HandleTests.test_handle_weakref.<locals>.<lambda>rr�)�weakref�WeakValueDictionaryrr�r+)r/Zwdr�rrr�test_handle_weakref�szHandleTests.test_handle_weakrefcCs�d|jj_t�td|j�}t�t�\}}|�t	|�d||f�|�
�|�t	|�d�|�t��
t�
t�}Wd�n1sAwYt�|d|j�}|�t	|�d||f�t�tdd�}t�|d	|j�}d
t�|�|f}|�t	|�|�tjtdd�}t�|d|j�}d
t�|�|f}|�t	|�|�tjdkr�tj}t�|�}t�|�\}}t�|d|j�}d}d|}d|t�|�|f}|�t	|�|�dSdS)NFr�z<Handle noop(1, 2) at %s:%s>z<Handle cancelled>rz<Handle noop() at %s:%s>r�r�)r�z%^<Handle noop\(1, 2\)\(3\) at %s:%s>$)�x)r�r�z'^<Handle noop\(x=1\)\(2, 3\) at %s:%s>$)r��z*<function HandleTests.test_handle_repr .*>z%functools.partialmethod\(%s, , \)\(\)z^<Handle %s at %s:%s>$)r+r�r�rr�r�r��get_function_sourcer�r-r�ZassertWarns�DeprecationWarning�	coroutinerWrX�re�escapeZassertRegexrr�r��test_handle_repr�
partialmethod)r/r��filename�linenor�Zregex�methodZcb_regexrrrr��sZ

��
��
����

��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)NTr�r�z-<Handle noop(1, 2) at %s:%s created at %s:%s>z7<Handle cancelled noop(1, 2) at %s:%s created at %s:%s>)r+r�r�rzr�	_getframe�f_linenorr�r�r�r�r�r-r��r/Zcreate_filenameZ
create_linenor�r�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)Nr�rr��test_handle_source_traceback)rr�r�r!r��listr�rz)r�r�r6rr�check_source_traceback�s��zHHandleTests.test_handle_source_traceback.<locals>.check_source_tracebackr)	r�get_event_loop_policyr(�	set_debugr)r�r�r�r�)r/r+r�r�rr6rr��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-r9r�rZiscoroutiner�rZ_format_coroutiner;�
cr_running�cr_code)r/r�rrr�+test_coroutine_like_object_debug_formatting
	s&�z7HandleTests.test_coroutine_like_object_debug_formatting)r9r:r;r�r�r�r�r�r�r�r�rmrL�collections�abcrrhrrrdrr�zs
2�r�csLeZdZ�fdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	�Z
S)�
TimerTestscst���t��|_dSr)rbr�rr�r+r6rdrrr�1	r�zTimerTests.setUpcCs8t��}t�|dd�dt���}|�t|�t|��dS)NcSrdrerrrrrr�7	rz&TimerTests.test_hash.<locals>.<lambda>r)r�rRr�TimerHandlerr�r��hash�r/�whenr�rrr�	test_hash5	s
�zTimerTests.test_hashcCs4t��}t�|dd�dt���}|�||���dS)NcSrdrerrrrrr�=	rz&TimerTests.test_when.<locals>.<lambda>r)r�rRrrrr�r�r	rrrr�	test_when;	s
�zTimerTests.test_whencCs�dd�}d}t��}t�|||t���}|�|j|�|�|j|�|�	|�
��|��|�|�
��|�
|j�|�
|j�|�ttjd|||j�dS)NcWr�rrr�rrrr�B	r2z'TimerTests.test_timer.<locals>.callback)r�r�r�)r�rRrrrr�r$r�r�r�rLr�r�r�r�rIr+)r/r�r�r	r�rrr�
test_timerA	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+r�r�rrr�r�r�r�r-r�)r/r��srcrrr�test_timer_reprW	s


�
�zTimerTests.test_timer_reprcCs�d|jj_t}t��jd}t�dt	d|j�}t
�t	�\}}|�t
|�d||||f�|��|�t
|�d||||f�dS)NTr�r
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+r�r�rzrr�r�rrr�r�r�r�r-r�r�rrr�test_timer_repr_debuge	s 


��

��z TimerTests.test_timer_repr_debugcCs8dd�}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�n1s�wY|�
t��|dkWd�n	1�s
wY|�
t��|dkWd�n	1�s'wY|�
t��|dkWd�n	1�sAwY|�|dk�|�|dk�|�|tk�|�|tk�|�|tk�|�|tk�|�|tk�|�|tk�|�|tk�|�|tk�|�|tk�|�|tk�dS)NcWr�rrr�rrrr�{	r2z2TimerTests.test_timer_comparison.<locals>.callbackrg$@)r�rRrrr+r�r�r�r�r$�NotImplemented�__eq__�__ne__r�rr
rr)r/r�r	Zh1Zh2Zh3rrr�test_timer_comparisonz	sn
�
�
�
�z TimerTests.test_timer_comparison)r9r:r;r�r
rrrrrrhrrrdrr/	src@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)rr�r�AbstractEventLoopr��NotImplementedErrorr�r*r�r�r�r7r�r�rfr�r�r�Zset_default_executorr�r�r�r�rr	Zset_exception_handlerZdefault_exception_handlerr�r�r�)r/r`r+rrr�test_not_implemented�	s��������
�
�����
��
��
��������z+AbstractEventLoopTests.test_not_implementedcs,�fdd�}t��}|�|��|��dS)Nc�s$�t��}t��}��t��|�||�IdHWd�n1s"wY��t��|�dd�IdHWd�n1s@wY��t��|�d�IdHWd�n1s]wY��t��|�	|�IdHWd�n1szwY��t��|�
|�IdHWd�n1s�wY��t��|�|�IdHWd�n1s�wY��t��|�|d�IdHWd�n1s�wY��t��|�
|d�IdHWd�n1s�wY��t��|�|d�IdHWd�n	1�swY��t��|�||�IdHWd�n	1�s.wY��t��|�|�IdHWd�n	1�sLwY��t��|�||�IdHWd�n	1�skwY��t��|�||�IdHWd�n	1�s�wY��t��|�|tjj�IdHWd�n	1�s�wY��t��|�|tjj�IdHWd�n	1�s�wY��t��|�|tj�IdHWd�n	1�s�wY��t��|�|�IdHWd�dS1�swYdS)Nrq�)rqrr)rr�rrr�rr�rprr1r�rr?Zsock_recv_intoZsock_sendallZsock_connectZsock_acceptZ
sock_sendfile�sendfiler�sentinelrr)r�r{)r`r+r6rr�inner�	sl�����������������$�z@AbstractEventLoopTests.test_not_implemented_async.<locals>.inner)rr(r*r7)r/rr+rr6r�test_not_implemented_async�	s'z1AbstractEventLoopTests.test_not_implemented_asyncN)r9r:r;rrrrrrr�	s6rc@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_watcherr��r/�policyrrr�test_event_loop_policy!
s
�z"PolicyTests.test_event_loop_policycCsXt��}|�|jj�|��}|�|tj�|�|jj|�|�||���|�	�dSr)
r�DefaultEventLoopPolicyr��_localZ_loopr r!rr$r7�r/r"r+rrr�test_get_event_loop*
szPolicyTests.test_get_event_loopcCsft��}tjj|d|jd��}|��}|�|j�|�	|�Wd�n1s(wY|��dS)Nr))�wraps)
rr$rrMr�r)r r�r7r�)r/r"Zm_set_event_loopr+rrr�(test_get_event_loop_calls_set_event_loop4
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_noneE
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"r6rrr`M
sz1PolicyTests.test_get_event_loop_thread.<locals>.fr�)r�r�r�r�)r/Zm_current_threadr`�thrr6r�test_get_event_loop_threadJ
sz&PolicyTests.test_get_event_loop_threadcCs*t��}|��}|�|tj�|��dSr)rr$r(r!rr7r&rrr�test_new_event_loopU
szPolicyTests.test_new_event_loopcCsrt��}|��}|�|�|�t|jt��|��}|�|�|�||���|�	||���|�
�|�
�dSr)rr$r(r)r�rIr�r$r �assertIsNotr7)r/r"Zold_loopr+rrr�test_set_event_loop\
s

zPolicyTests.test_set_event_loopcCs*t��}|�|tj�|�|t���dSr)rr�r!rr$r!rrr�test_get_event_loop_policyj
sz&PolicyTests.test_get_event_loop_policycCsL|�ttjt��t��}t��}t�|�|�|t���|�||�dSr)	r�rIrrr�r�r$r$r.)r/�
old_policyr"rrr�test_set_event_loop_policyo
s
�
z&PolicyTests.test_set_event_loop_policyN)r9r:r;r#r'r)r*rrMr,r-r/r0r2rrrrr
s	


rcsZeZdZdZdZdZdZ�fdd�Z�fdd�Ze	j
dkr!dd�Zd	d
�Zdd�Z
�ZS)
�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�tjdkrft��}|�|j�t�|�dSdSrr)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_implrrbr�r(r+r)rrr�r�r�r�rdrrr��
s(


�zGetEventLoopTestsMixin.setUpc	s�z<tjdkrt�d�t���W|j��t�d�|j	t
_|jt
_
|jt
_|jt
_|j	t_|jt_
|jt_|jt_dS|j��t�d�|j	t
_|jt
_
|jt
_|jt
_|j	t_|jt_
|jt_|jt_wrr)rrrr�rbr�r+r7r)r5rr4r7r6r9r8r:r r6rdrrr��
s0




�

zGetEventLoopTestsMixin.tearDownrcs.t���fdd�}���j�|��d�dS)Nc�s,�tj��}�j�|t�IdH}|��|Sr)�
concurrent�futures�ProcessPoolExecutorr+r�r,�shutdown)�poolrSr6rrrO�
s�

�zDGetEventLoopTestsMixin.test_get_event_loop_new_process.<locals>.mainr%)r
Z*skip_if_broken_multiprocessing_synchronizer�r+r*)r/rOrr6r�test_get_event_loop_new_process�
s�z6GetEventLoopTestsMixin.test_get_event_loop_new_processc	sGdd�dt��G�fdd�dtj�}t��}z�t�|��t��������t��Wd�n1s6wYt�d������t��Wd�n1sTwY��	t
d��t��Wd�n1snwY��t�
�d���fdd�}��|��t��������t��Wd�n1s�wYt�d������t��Wd�n1s�wYWt�|��dur҈��nt�|��dur���ww��	t
d��t��Wd�n1s�wY��t�
�d�dS)Nc@seZdZdS)zRGetEventLoopTestsMixin.test_get_event_loop_returns_running_loop.<locals>.TestErrorN)r9r:r;rrrr�	TestError�
srEcseZdZ�fdd�ZdS)zOGetEventLoopTestsMixin.test_get_event_loop_returns_running_loop.<locals>.Policycs��rrr6�rErrr �
r2z^GetEventLoopTestsMixin.test_get_event_loop_returns_running_loop.<locals>.Policy.get_event_loopN)r9r:r;r rrFrr�Policy�
srG�
no runningc��6���t������t������t����dSr�r$rr r8r4r�r+r/rrri�
��zMGetEventLoopTestsMixin.test_get_event_loop_returns_running_loop.<locals>.func)r�rr$r�rr(r�r r)r�r�r8r$r4r*r7)r/rGr1rir)rEr+r/r�(test_get_event_loop_returns_running_loop�
sP
�

�
�

�

��
�
�
�
�z?GetEventLoopTestsMixin.test_get_event_loop_returns_running_loopc	s�t��}z�t�t���t������j�t��}��|j�t�d���	t
d��t��Wd�n1s:wY��	t
d��t��Wd�n1sTwY��t�
�d���fdd�}��|��t�����t����t�d���	t
d��t��Wd�n1s�wYWt�|��dur����nt�|��dur����ww��	t
d��t��Wd�n1s�wY��t�
�d�dS)Nz
no currentrHc�rIrrJrrKrrrirLzNGetEventLoopTestsMixin.test_get_event_loop_returns_running_loop2.<locals>.func)rr�rr$r(r�r7r r)r�r�r8r$r4r*)r/r1Zloop2rirrKr�)test_get_event_loop_returns_running_loop2�
sH

�
�


��
�
�
�
�z@GetEventLoopTestsMixin.test_get_event_loop_returns_running_loop2)r9r:r;r;r<r=r>r�r�rrrDrMrNrhrrrdrr3{
s
/r3c@�$eZdZejZejZejZ	ej
ZdS)�TestPyGetEventLoopN)r9r:r;rZ_py__get_running_loopr;Z_py__set_running_loopr<Z_py_get_running_loopr=Z_py_get_event_loopr>rrrrrP�

rPc@rO)�TestCGetEventLoopN)r9r:r;rZ_c__get_running_loopr;Z_c__set_running_loopr<Z_c_get_running_loopr=Z_c_get_event_loopr>rrrrrR*rQrRc@r�)�
TestServercsbt��}|�|j�t|��|�|��fdd�dd��}|�|��|�|��|�|�	��dS)Ncrrrrr�rrr�8rz*TestServer.test_get_loop.<locals>.<lambda>r�r)
rr(r�r7rar*r�r��get_loop�wait_closed)r/r+r�rr�r�
test_get_loop4szTestServer.test_get_loopN)r9r:r;rVrrrrrS2srSc@s$eZdZdd�Zdd�Zdd�ZdS)�TestAbstractServercC�<|�t��t����Wd�dS1swYdSr)r�rr�AbstractServerr7r6rrrrl@�"�zTestAbstractServer.test_closecCsVt��}|�|j�|�t��|�t���	��Wd�dS1s$wYdSr)
rr(r�r7r�rr*rrYrUrErrr�test_wait_closedDs
"�z#TestAbstractServer.test_wait_closedcCrXr)r�rrrYrTr6rrrrVKrZz TestAbstractServer.test_get_loopN)r9r:r;rlr[rVrrrrrW>srW�__main__)L�collections.abcr�concurrent.futuresr?rWrrrr�rr�r@�ImportErrorr�rr�r�ryr�rr�rIrrrrrZtest.test_asyncior	r�rcr
Ztest.supportrrr
rrrr#r,r-r#r<raZDatagramProtocolrjrxZBaseProtocolr{r�r}r�rpZTestCaser�r�r�r�rLr�r�r�r�r�rrrr3rPZ_asynciorRrSrWr9rOrrrr�<module>s��
	& $- ������6f\"�
�