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.7/test/test_asyncio/__pycache__/test_events.cpython-37.opt-2.pyc
B

��gu��@s�ddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
yddlZWnek
rldZYnXddl
Z
ddlZddlZddlZddlZddlZddlZddlmZddlZejdkr�ddlZddlZddlmZddlmZddlmZddlmZddlmZdd	lmZdd
lmZ ddl!m"Z"dd
�Z#dd�Z$Gdd�d�Z%Gdd�dej&�Z'Gdd�de'�Z(Gdd�dej)�Z*Gdd�dej&�Z+Gdd�dej,�Z-Gdd�dej.�Z/Gdd�d�Z0Gd d!�d!�Z1Gd"d#�d#�Z2Gd$d%�d%e2�Z3Gd&d'�d'e2�Z4ejdk�rFGd(d)�d)e0e4e3e j5�Z6Gd*d+�d+e0e4e3e1e j5�Z7n�ddl8Z8Gd,d-�d-e0e4e3�Z9e:e8d.��r�Gd/d0�d0e9e1e j5�Z;e:e8d1��r�Gd2d3�d3e9e1e j5�Z<e:e8d4��r�Gd5d6�d6e9e1e j5�Z=Gd7d)�d)e9e1e j5�Z6d8d9�Z>Gd:d;�d;e j5�Z?Gd<d=�d=ej5�Z@Gd>d?�d?ej5�ZAGd@dA�dAej5�ZBGdBdC�dCej5�ZCGdDdE�dE�ZDGdFdG�dGeDej5�ZEyddlFZFWnek
�r�YnXGdHdI�dIeDej5�ZGGdJdK�dKej5�ZHGdLdM�dMej5�ZIeJdNk�r�e�K�dS)O�N)�mock�win32)�base_events)�	constants)�
coroutines)�events)�proactor_events)�selector_events)�utils)�supportcCsFtj�d�rdStjdkrdSt��d}ttt|�d���}|dkS)NZaixT�darwinFr�.)�
�)�sys�platform�
startswithZmac_ver�tuple�map�int�split)�version�r�9/usr/local/lib/python3.7/test/test_asyncio/test_events.py�broken_unix_getsockname(s
rcCs&dd�}t��}t�|�|�|��S)Nc�sdS)N�hellorrrrr�doit4sz8_test_get_event_loop_new_process__sub_proc.<locals>.doit)�asyncio�new_event_loop�set_event_loop�run_until_complete)r�looprrr�*_test_get_event_loop_new_process__sub_proc3s
r"c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�CoroLikecCsdS)Nr)�self�vrrr�send=sz
CoroLike.sendcGsdS)Nr)r$�excrrr�throw@szCoroLike.throwcCsdS)Nr)r$rrr�closeCszCoroLike.closecCsdS)Nr)r$rrr�	__await__FszCoroLike.__await__N)�__name__�
__module__�__qualname__r&r(r)r*rrrrr#<sr#c@s>eZdZdZdZddd�Zdd�Zdd�Zdd	�Zd
d�Z	dS)
�MyBaseProtoNcCs:d|_d|_d|_|dk	r6tj|d�|_tj|d�|_dS)N�INITIALr)r!)�	transport�state�nbytesr�Future�	connected�done)r$r!rrr�__init__NszMyBaseProto.__init__cCs"||_d|_|jr|j�d�dS)N�	CONNECTED)r0r1r4�
set_result)r$r0rrr�connection_madeVszMyBaseProto.connection_madecCs|jt|�7_dS)N)r2�len)r$�datarrr�
data_received]szMyBaseProto.data_receivedcCs
d|_dS)N�EOF)r1)r$rrr�eof_receivedaszMyBaseProto.eof_receivedcCsd|_|jr|j�d�dS)N�CLOSED)r1r5r8)r$r'rrr�connection_losteszMyBaseProto.connection_lost)N)
r+r,r-r4r5r6r9r<r>r@rrrrr.Js
r.cseZdZ�fdd�Z�ZS)�MyProtocst��|�|�d�dS)Ns%GET / HTTP/1.0
Host: example.com

)�superr9�write)r$r0)�	__class__rrr9mszMyProto.connection_made)r+r,r-r9�
__classcell__rr)rDrrAlsrAc@s:eZdZdZddd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�MyDatagramProtoNcCs&d|_d|_|dk	r"tj|d�|_dS)Nr/r)r!)r1r2rr3r5)r$r!rrrr6uszMyDatagramProto.__init__cCs||_d|_dS)N�INITIALIZED)r0r1)r$r0rrrr9{szMyDatagramProto.connection_madecCs|jt|�7_dS)N)r2r:)r$r;�addrrrr�datagram_received�sz!MyDatagramProto.datagram_receivedcCsdS)Nr)r$r'rrr�error_received�szMyDatagramProto.error_receivedcCsd|_|jr|j�d�dS)Nr?)r1r5r8)r$r'rrrr@�szMyDatagramProto.connection_lost)N)	r+r,r-r5r6r9rIrJr@rrrrrFrs
rFc@s:eZdZdZddd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�MyReadPipeProtoNcCs.dg|_d|_d|_|dk	r*tj|d�|_dS)Nr/r)r!)r1r2r0rr3r5)r$r!rrrr6�s
zMyReadPipeProto.__init__cCs||_|j�d�dS)Nr7)r0r1�append)r$r0rrrr9�szMyReadPipeProto.connection_madecCs|jt|�7_dS)N)r2r:)r$r;rrrr<�szMyReadPipeProto.data_receivedcCs|j�d�dS)Nr=)r1rL)r$rrrr>�szMyReadPipeProto.eof_receivedcCs8d|jkr|j�d�|j�d�|jr4|j�d�dS)Nr=r?)r1rLr5r8)r$r'rrrr@�s

zMyReadPipeProto.connection_lost)N)	r+r,r-r5r6r9r<r>r@rrrrrK�s
rKc@s*eZdZdZddd�Zdd�Zdd�ZdS)	�MyWritePipeProtoNcCs&d|_d|_|dk	r"tj|d�|_dS)Nr/)r!)r1r0rr3r5)r$r!rrrr6�szMyWritePipeProto.__init__cCs||_d|_dS)Nr7)r0r1)r$r0rrrr9�sz MyWritePipeProto.connection_madecCsd|_|jr|j�d�dS)Nr?)r1r5r8)r$r'rrrr@�sz MyWritePipeProto.connection_lost)N)r+r,r-r5r6r9r@rrrrrM�s
rMc@s<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�MySubprocessProtocolcsrd|_d|_tj�d�|_tj�d�|_�fdd�td�D�|_ddd�|_d|_	tj
�d�tj
�d�d�|_dS)Nr/)r!csi|]}tj�d�|�qS))r!)rr3)�.0�fd)r!rr�
<dictcomp>�sz1MySubprocessProtocol.__init__.<locals>.<dictcomp>��)��)r1r0rr3r4�	completed�range�disconnectsr;�
returncodeZEvent�got_data)r$r!r)r!rr6�s
zMySubprocessProtocol.__init__cCs||_d|_|j�d�dS)Nr7)r0r1r4r8)r$r0rrrr9�sz$MySubprocessProtocol.connection_madecCsd|_|j�d�dS)Nr?)r1rVr8)r$r'rrrr@�sz$MySubprocessProtocol.connection_lostcCs$|j||7<|j|��dS)N)r;rZ�set)r$rPr;rrr�pipe_data_received�sz'MySubprocessProtocol.pipe_data_receivedcCs*|r|j|�|�n|j|�|�dS)N)rXZ
set_exceptionr8)r$rPr'rrr�pipe_connection_lost�sz)MySubprocessProtocol.pipe_connection_lostcCs|j��|_dS)N)r0Zget_returncoderY)r$rrr�process_exited�sz#MySubprocessProtocol.process_exitedN)	r+r,r-r6r9r@r\r]r^rrrrrN�srNcsPeZdZ�fdd�Z�fdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zejd!d"��Zd#d$�Zd%d&�Ze�eed'�d(�d)d*��Ze�eed+�d,�d-d.��Ze�eed+�d,�d/d0��Zd�d2d3�Zd4d5�Z ejd6d7��Z!d8d9�Z"d1d:ifd;d<�Z#d�d=d>�Z$d�d?d@�Z%e�&e'd:kdA�dBdC��Z(eje�&e'd:kdA�dDdE���Z)dFdG�Z*dHdI�Z+d�dJdK�Z,e�&e'd:kdA�dLdM��Z-dNdO�Z.e/�0dP�dQdR��Z1dSdT�Z2dUdV�Z3dWdX�Z4e�ee5dY�dZ�d[d\��Z6d]d^�Z7ejd_d`��Z8e�ee5da�db�dcdd��Z9d�dedf�Z:d�dgdh�Z;d�didj�Z<e�&e'd:kdA�dkdl��Z=eje�&e'd:kdA�dmdn���Z>e�&e'd:kdA�dodp��Z?eje�&e'd:kdA�dqdr���Z@e�&e'd:kdA�dsdt��ZAeje�&e'd:kdA�dudv���ZBe�&e'd:kdA�dwdx��ZCdydz�ZDd{d|�ZEe�ejFd}�d~d��ZGd�d��ZHd�d��ZId�d��ZJd�d��ZKe�eLjMd�kd��d�d���ZNe�eLjMd�kd��d�d���ZOe�eLjMd�kd��d�d���ZPe�eLjMd�kd��d�d���ZQe�eLjMd�kd��d�d���ZRe�eLjMd�kd��e�Sd�d��d�d����ZTe�eLjMd�kd��e�Sd�d��d�d����ZUd�d��ZVd�d��ZWd�d��ZXd�d��ZYd�d��ZZd�d��Z[�Z\S)��EventLoopTestsMixincs$t���|��|_|�|j�dS)N)rB�setUp�create_event_loopr!r)r$)rDrrr`�s

zEventLoopTestsMixin.setUpcs4|j��st�|j�|��t��t���dS)N)	r!�	is_closed�
test_utils�run_brieflyZ
doCleanupsrZ
gc_collectrB�tearDown)r$)rDrrre�s

zEventLoopTestsMixin.tearDowncs:tjdd���tj��fdd��}��t�jj|��dS)Ncss
dVdS)Nrrrrr�coro1�szBEventLoopTestsMixin.test_run_until_complete_nesting.<locals>.coro1cs"���j����j����dS)N)�
assertTruer!�
is_runningr r)rfr$rr�coro2szBEventLoopTestsMixin.test_run_until_complete_nesting.<locals>.coro2)r�	coroutine�assertRaises�RuntimeErrorr!r )r$rir)rfr$r�test_run_until_complete_nesting�sz3EventLoopTestsMixin.test_run_until_complete_nestingcCsX|j��}|j�tjd|jd��|j��}|�d||koFdkn||�dS)Ng�������?)r!g{�G�z�?g�������?)r!�timer r�sleeprg)r$�t0�t1rrr�test_run_until_completes

z+EventLoopTestsMixin.test_run_until_completecs(�fdd�}|�}��t�jj|�dS)Nc�s$�j��tjd�jd�IdHdS)Ng�������?)r!)r!�stoprror)r$rr�cbs
z?EventLoopTestsMixin.test_run_until_complete_stopped.<locals>.cb)rkrlr!r )r$rtZtaskr)r$r�test_run_until_complete_stoppedsz3EventLoopTestsMixin.test_run_until_complete_stoppedcsvg���fdd�}�j�d|d�t��}�j��t��}���dg���d||koddkn||�dS)Ncs��|��j��dS)N)rLr!rs)�arg)�resultsr$rr�callbacks
z5EventLoopTestsMixin.test_call_later.<locals>.callbackg�������?zhello worldg{�G�z�?g�������?)r!�
call_laterrn�	monotonic�run_forever�assertEqualrg)r$rxrprqr)rwr$r�test_call_laters
z#EventLoopTestsMixin.test_call_latercs>g���fdd�}�j�|dd��j�����dg�dS)Ncs��||f��j��dS)N)rLr!rs)Zarg1Zarg2)rwr$rrrx,sz4EventLoopTestsMixin.test_call_soon.<locals>.callbackr�world)rr~)r!�	call_soonr{r|)r$rxr)rwr$r�test_call_soon)s

z"EventLoopTestsMixin.test_call_soonc	s�g�t�����fdd�����fdd�}���tj|d�}|�����j��d��j��WdQRX|����	�ddg�dS)Ncs$��|�t��dkr �j��dS)NrU)rLr:r!rs)rv)rwr$rrrx8s
z?EventLoopTestsMixin.test_call_soon_threadsafe.<locals>.callbackcs�j��d����dS)Nr)r!�call_soon_threadsafe�releaser)rx�lockr$rr�
run_in_thread=szDEventLoopTestsMixin.test_call_soon_threadsafe.<locals>.run_in_thread)�targetr~r)
�	threadingZLock�acquire�Thread�startr!rr{�joinr|)r$r��tr)rxr�rwr$r�test_call_soon_threadsafe4sz-EventLoopTestsMixin.test_call_soon_threadsafecsLg���fdd�}�j�|d��j�|d��j�����ddg�dS)Ncs$��|�t��dkr �j��dS)NrU)rLr:r!rs)rv)rwr$rrrxNs
zKEventLoopTestsMixin.test_call_soon_threadsafe_same_thread.<locals>.callbackrr~)r!r�rr{r|)r$rxr)rwr$r�%test_call_soon_threadsafe_same_threadKs
z9EventLoopTestsMixin.test_call_soon_threadsafe_same_threadcCsHdd�}|j�d|d�}|j�|�\}}|�|d�|�|t���dS)NcSs|t��fS)N)r��	get_ident)rvrrr�runYsz5EventLoopTestsMixin.test_run_in_executor.<locals>.runZyo)r!�run_in_executorr r|ZassertNotEqualr�r�)r$r��f2�resZ	thread_idrrr�test_run_in_executorXs
z(EventLoopTestsMixin.test_run_in_executorcs`d��fdd�}dd�}|j�d|�}|��|j��||j_||j_t�d�|���dS)NFcsd�dS)NTr)�args)�calledrr�patched_call_sooncszJEventLoopTestsMixin.test_run_in_executor_cancel.<locals>.patched_call_sooncSst�d�dS)Ng�������?)rnrorrrrr�gsz<EventLoopTestsMixin.test_run_in_executor_cancel.<locals>.rung�������?)	r!r��cancelr)rr�rnro�assertFalse)r$r�r�r�r)r�r�test_run_in_executor_cancel`s

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)
NFcsVy��d�}Wntk
r"dSX|r4��|�n���j���������dS)Ni)�recv�BlockingIOError�extendrgr!�
remove_reader�filenor))r;)�
bytes_read�rr$rr�readerwsz8EventLoopTestsMixin.test_reader_callback.<locals>.readersabccst��dkS)NrR)r:r)r�rr�<lambda>�rSz:EventLoopTestsMixin.test_reader_callback.<locals>.<lambda>sdefcst��dkS)N�)r:r)r�rrr��rSsabcdef)�socket�
socketpair�setblocking�	bytearrayr!�
add_readerr�rr&rc�	run_untilr)rsr{r|)r$�wr�r)r�r�r$r�test_reader_callbackrs


z(EventLoopTestsMixin.test_reader_callbackcs�t��\}���d���fdd�}d}�j����||��j�����j��������	�j��������
�|�t|�d�}|�
���
||�dS)NFcs��|��j��dS)N)r&r!rs)r;)r$r�rr�writer�s
z8EventLoopTestsMixin.test_writer_callback.<locals>.writersxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxrU)r�r�r�r!�
add_writerr�r{rg�
remove_writerr�r)r�r:r|)r$r�r�r;�readr)r$r�r�test_writer_callback�s

z(EventLoopTestsMixin.test_writer_callbackc	Cs�t|jtj��s|j�d�|�d�|�t��|j�|j�	||j
��WdQRX|�t��|j�|j�|d��WdQRX|�t��|j�|j�|d��WdQRX|�t��|j�|j�
|t���WdQRX|�t��|j�|j�|��WdQRX|�d�|j�|j�	||j
��|j�|j�|d��|j�|j�|d��}|j�|j�|d��|��|�|�d��dS)NTsGET / HTTP/1.0

iFsHTTP/1.0 200 OK)�
isinstancer!r�BaseProactorEventLoop�	set_debugr�rk�
ValueErrorr �sock_connect�address�sock_sendall�	sock_recv�sock_recv_intor��sock_acceptr)rgr)r$�httpd�sockr;rrr�_basetest_sock_client_ops�s:

z-EventLoopTestsMixin._basetest_sock_client_opsc	Cs�|�d�|j�|j�||j��|j�|j�|d��td�}t|��B}|j�|j�||dd���}|j�|j�|||d���WdQRX|�	�|�
|�d��dS)NFsGET / HTTP/1.0

isHTTP/1.0 200 OK)r�r!r r�r�r�r��
memoryviewr�r)rgr)r$r�r�r;�bufr2rrr�_basetest_sock_recv_into�s

"z,EventLoopTestsMixin._basetest_sock_recv_intoc	Cs@t���.}t��}|�||�t��}|�||�WdQRXdS)N)rc�run_test_serverr�r�r�)r$r�r�rrr�test_sock_client_ops�s

z(EventLoopTestsMixin.test_sock_client_opsc	CsHt���6}t�tj�}|�||�t�tj�}|�||�WdQRXdS)N)rc�run_test_unix_serverr��AF_UNIXr�r�)r$r�r�rrr�test_unix_sock_client_ops�s

z-EventLoopTestsMixin.test_unix_sock_client_opsc	Csxd}zt��}|�d�|��}Wd|��Xt��}|�d�|�t��|j�|j�	||��WdQRX|��dS)N)z	127.0.0.1rF)
r��bind�getsocknamer)r�rk�ConnectionRefusedErrorr!r r�)r$r��sr�rrr�test_sock_client_fail�s


z)EventLoopTestsMixin.test_sock_client_failcCs�t��}|�d�|�d�|�d�t��}|�|���|j�|�}|j�|�\}}|�	|�
�d�|�	||���|�	|��|���|��|��|��dS)NF)z	127.0.0.1rrTr)
r�r�r��listen�connectr�r!r�r r|Z
gettimeoutZgetpeernamer))r$Zlistener�client�f�connrHrrr�test_sock_accept�s


z$EventLoopTestsMixin.test_sock_accept�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)NrTrr)�caughtrr�
my_handlersz?EventLoopTestsMixin.test_add_signal_handler.<locals>.my_handlerZboomrT���cs�S)Nrr)r�rrr�+rSz=EventLoopTestsMixin.test_add_signal_handler.<locals>.<lambda>)rk�	TypeErrorr!�add_signal_handler�remove_signal_handlerr��signal�NSIGrlr�r��SIGINT�os�kill�getpidrcr�rgr|�	getsignal�default_int_handler)r$r�r)r�r�test_add_signal_handlers<z+EventLoopTestsMixin.test_add_signal_handler�SIGALRMz
No SIGALRMcs^d���fdd�}�j�tj|�t�tjdd��j�d�jj��j����	�d�dS)Nrcs�d7��j��dS)NrT)r!rsr)r�r$rrr�9szLEventLoopTestsMixin.test_signal_handling_while_selecting.<locals>.my_handlerg{�G�z�?�<rT)
r!r�r�r��	setitimer�ITIMER_REALryrsr{r|)r$r�r)r�r$r�$test_signal_handling_while_selecting4s
z8EventLoopTestsMixin.test_signal_handling_while_selectingcsjd�d����fdd�}�jjtj|f���t�tjdd��j�d�jj��j����	�d�dS)N)�*rcs"�d7���|���j��dS)NrT)r|r!rs)r�)r�r$�	some_argsrrr�JszAEventLoopTestsMixin.test_signal_handling_args.<locals>.my_handlerg�������?r�rT)
r!r�r�r�r�r�ryrsr{r|)r$r�r)r�r$r�r�test_signal_handling_argsEs
z-EventLoopTestsMixin.test_signal_handling_argsTcCsv|j�|�\}}|�|tj�|�|tj�|�|j|�|rN|�|�	d��|j�|j
�|�|jd�|�
�dS)N�socknamer)r!r �assertIsInstancer�	Transport�Protocol�assertIsr0�assertIsNotNone�get_extra_infor5�
assertGreaterr2r))r$�connection_fut�check_sockname�tr�prrrr�_basetest_create_connectionWsz/EventLoopTestsMixin._basetest_create_connectionc	s>t���,}�jj�fdd�f|j��}��|�WdQRXdS)Ncst�jd�S)N)r!)rAr!r)r$rrr�erSz<EventLoopTestsMixin.test_create_connection.<locals>.<lambda>)rcr�r!�create_connectionr�r�)r$r��conn_futr)r$r�test_create_connectionbs
z*EventLoopTestsMixin.test_create_connectionc	sDt�}t���*}�j��fdd�|j�}��||�WdQRXdS)Ncst�jd�S)N)r!)rAr!r)r$rrr�prSzAEventLoopTestsMixin.test_create_unix_connection.<locals>.<lambda>)rrcr�r!�create_unix_connectionr�r�)r$r�r�r�r)r$r�test_create_unix_connectionhs

z/EventLoopTestsMixin.test_create_unix_connectionc	s�t����}d}�j��jj|jdtji��}xZ|D]R\}}}}}y4tj|||d�}|�d��j��j�	||��WnYq2XPq2W�jj
�fdd�|d�}	�j�|	�\}
}��|
tj
���|tj��j�|j���|jd�|
��WdQRXdS)N�type)�familyr��protoFcst�jd�S)N)r!)rAr!r)r$rrr��rSzAEventLoopTestsMixin.test_create_connection_sock.<locals>.<lambda>)r�r)rcr�r!r �getaddrinfor�r��SOCK_STREAMr�r�r�r�rr�r�r5r�r2r))r$r�r��infosr�r�r��cnamer�r�r�r�r)r$r�test_create_connection_sockss,

z/EventLoopTestsMixin.test_create_connection_sockNcCs|r|�|�d��|r,|�||�d��n|�|�d��|�||�d��|�d�}|�|t�|�t|�d|�|�|dt�|�|dt�|�|dt�|�d	�}|�|�|�|��|�d
��|�|�	�|�d��|�|�
�|�d��|�|��|�d
��dS)Nr��peername�peercert�cipherrRrrTrUZ
ssl_object�compression)r�r�r|r�rr:�strrrrZgetpeercert)r$r�r�rrrZsslobjrrr�check_ssl_extra_info�s0






z(EventLoopTestsMixin.check_ssl_extra_infocCsx|j�|�\}}|�|tj�|�|tj�|�d|jj�	�k�|�
|||�|j�|j�|�|j
d�|��dS)N�sslr)r!r r�rr�r�rgrDr+�lowerrr5r�r2r))r$r�r�rr�r�rrr�_basetest_create_ssl_connection�sz3EventLoopTestsMixin._basetest_create_ssl_connectionc	
s�|t��d�}��|||�ttd�r�tjjfdddd��fdd�}tjd|d��,}|dd�}��|||���	|j
d	�WdQRX��tj��2}|dd�}t�
����|||�WdQRXWdQRX��	|jjd
�dS)N)r	�Purpose)�cafile�capath�cadatacs��|tjj�t��S)N)r|r	r�SERVER_AUTHrc�dummy_ssl_context)Zpurposer
rr)r$rr�_dummy_ssl_create_context�szREventLoopTestsMixin._test_create_ssl_connection.<locals>._dummy_ssl_create_contextzssl.create_default_context)�side_effectTrTZCERTIFICATE_VERIFY_FAILED)rcrr�hasattrr	rrr�patchr|Z
call_countrk�SSLError�disable_logger�	exception�reason)	r$r�r�r�rr�r�m�cmr)r$r�_test_create_ssl_connection�s&
	



z/EventLoopTestsMixin._test_create_ssl_connectionz
No ssl modulec	sNtjdd��8}tj�jj�fdd�f|j��}�j|||jd�WdQRXdS)NT)�use_sslcst�jd�S)N)r!)rAr!r)r$rrr��rSz@EventLoopTestsMixin.test_create_ssl_connection.<locals>.<lambda>)r)rcr��	functools�partialr!r�r�r)r$r�r�r)r$r�test_create_ssl_connection�s
z.EventLoopTestsMixin.test_create_ssl_connectionc	sXt�}tjdd��:}tj�jj�fdd�|jdd�}�j||||jd�WdQRXdS)NT)rcst�jd�S)N)r!)rAr!r)r$rrr��rSzEEventLoopTestsMixin.test_create_ssl_unix_connection.<locals>.<lambda>z	127.0.0.1)�server_hostname)r)	rrcr�rrr!r�r�r)r$r�r�r�r)r$r�test_create_ssl_unix_connection�sz3EventLoopTestsMixin.test_create_ssl_unix_connectionc	s�t���n}t��}�jj�fdd�f|j�d|jd|fi�}�j�|�\}}|j�	d�d}��
||�|��WdQRXdS)Ncst�jd�S)N)r!)rAr!r)r$rrr��rSzGEventLoopTestsMixin.test_create_connection_local_addr.<locals>.<lambda>�
local_addrrr�rT)rcr�r�find_unused_portr!r�r�r r0r�r|r))r$r��portr�r�r��expectedr)r$r�!test_create_connection_local_addr�s
z5EventLoopTestsMixin.test_create_connection_local_addrc
s�t���t}�jj�fdd�f|j�d|ji�}��t��}�j�|�WdQRX��|j	j
t
j���t
|j�|j	j�WdQRXdS)Ncst�jd�S)N)r!)rAr!r)r$rrr�	rSzNEventLoopTestsMixin.test_create_connection_local_addr_in_use.<locals>.<lambda>r#)rcr�r!r�r�rk�OSErrorr r|r�errno�
EADDRINUSE�assertInr�strerror)r$r�r�rr)r$r�(test_create_connection_local_addr_in_uses
z<EventLoopTestsMixin.test_create_connection_local_addr_in_usec	s|j�G��fdd�dt�}t��}|�d�|�d�|���d�d�d�����fdd�}tj|d	d
�}|��|�	�\}}|�d����_��
�j�fdd
�||d������j
��|��tj|dd�|�|���|��jd�|��jt���|����dS)Ncs,eZdZ��fdd�Z��fdd�Z�ZS)zAEventLoopTestsMixin.test_connect_accepted_socket.<locals>.MyProtocst��|����j�dS)N)rBr@rrs)r$r')rDr!rrr@szQEventLoopTestsMixin.test_connect_accepted_socket.<locals>.MyProto.connection_lostcst��|�|j���dS)N)rBr<r0rC)r$r;)rD�expected_responserrr<szOEventLoopTestsMixin.test_connect_accepted_socket.<locals>.MyProto.data_received)r+r,r-r@r<rEr)r.r!)rDrrAsrA)z	127.0.0.1rrTs	test datasrogerc
svyDt��}�dk	r��|�}|���|���|�d��|��Wn,tk
rp}ztd|�Wdd}~XYnXdS)N�cz8Failure in client thread in test_connect_accepted_socket)r�Zwrap_socketr��sendallr�r)�	Exception�print)Zcsockr')rH�
client_ssl�message�responserrr�&s



z@EventLoopTestsMixin.test_connect_accepted_socket.<locals>.clientT)r�Zdaemon)r!cs�S)Nrr)r�rrr�=rSzBEventLoopTestsMixin.test_connect_accepted_socket.<locals>.<lambda>)r	)�timeoutr?)r!r.r�r�r�r�r�r�r�Zacceptr �connect_accepted_socketr{r0r)rZjoin_threadr�Zis_aliver|r1r2r:)	r$Z
server_sslr3rAZlsockr�Zthreadr��_r)rHr3r.r!r4r�r5r�test_connect_accepted_sockets4




z0EventLoopTestsMixin.test_connect_accepted_socketcCsLtjdkr,tjdkr,t|jtj�r,t�d��t	�
�}t	��}|�||�dS)Nr)rRrz=SSL not supported with proactor event loops before Python 3.5)
rr�version_infor�r!rr��unittest�SkipTestrc�simple_server_sslcontext�simple_client_sslcontextr9)r$Zserver_contextZclient_contextrrr� test_ssl_connect_accepted_socketHs

z4EventLoopTestsMixin.test_ssl_connect_accepted_socketc	CsNt��}|�|j�|jjt|dd�}|�td��|j�|�WdQRXdS)NrT)Zssl_handshake_timeoutz1ssl_handshake_timeout is only meaningful with ssl)	r��
addCleanupr)r!r7rA�assertRaisesRegexr�r )r$r��cororrr�9test_connect_accepted_socket_ssl_timeout_for_plain_socketWszMEventLoopTestsMixin.test_connect_accepted_socket_ssl_timeout_for_plain_socketzasyncio.base_events.socketc	s�tj�fdd�����fdd�}t|�}�tjkrJdd�|D�|��j_ndd�|D�|��j_|�j_t	�
��j_t	�
��j_�j�
�fdd	�|d
�}�j�|�}��|j�dd�|jD�}��||�dS)
Ncs>�tjkr �tjdd||ffgS�tjdd||ddffgSdS)Nr��r)r��AF_INETr�)�hostr%r��kw)r�rrr�cs
zEEventLoopTestsMixin.create_server_multiple_hosts.<locals>.getaddrinfocstj�||��jd�S)N)r!)r�Taskr!)r��kwds)r�r$rr�getaddrinfo_taskjszJEventLoopTestsMixin.create_server_multiple_hosts.<locals>.getaddrinfo_taskcSsg|]}|df�qS)�Pr)rOrFrrr�
<listcomp>qszDEventLoopTestsMixin.create_server_multiple_hosts.<locals>.<listcomp>cSsg|]}|dddf�qS)rKrr)rOrFrrrrLtscs
t�j�S)N)rAr!r)r$rrr�xrSzBEventLoopTestsMixin.create_server_multiple_hosts.<locals>.<lambda>rKcSsh|]}|��d�qS)r)�
getsockbyname)rOr�rrr�	<setcomp>{szCEventLoopTestsMixin.create_server_multiple_hosts.<locals>.<setcomp>)rrjr[r�rErMrr!r�r�MockZ_start_serving�
_stop_serving�
create_serverr r@r)�socketsr|)	r$r�ZhostsZ	mock_sockrJZunique_hostsr��serverZserver_hostsr)r�r�r$r�create_server_multiple_hostsas
z0EventLoopTestsMixin.create_server_multiple_hostscCs|�tjdddg�dS)Nz1.2.3.4z5.6.7.8)rTr�rE)r$rrr�&test_create_server_multiple_hosts_ipv4~sz:EventLoopTestsMixin.test_create_server_multiple_hosts_ipv4cCs|�tjdddg�dS)Nz::1z::2)rTr��AF_INET6)r$rrr�&test_create_server_multiple_hosts_ipv6�sz: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�S)Nrr)r�rrr��rSz8EventLoopTestsMixin.test_create_server.<locals>.<lambda>z0.0.0.0rrTz	127.0.0.1sxxxr7cs
�jdkS)Nr)r2r)r�rrr��rSrRr�rr?)rAr!rQr r|r:rRr�r�r�r0r4r1rcr�r2r�r0r�r)r5)r$r�rSr�rFr%r�r)r�r�test_create_server�s,



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�S)Nrr)r�rrr��rSzCEventLoopTestsMixin.test_create_server_reuse_port.<locals>.<lambda>z0.0.0.0rrTcs�S)Nrr)r�rrr��rST)Z
reuse_port)rAr!rQr r|r:rRr�Z
getsockoptr��
SOL_SOCKETrYr)rcrdrg)r$r�rSr�r)r�r�test_create_server_reuse_port�s*



z1EventLoopTestsMixin.test_create_server_reuse_portcs@t���|��fdd��|jj|�f|�}|j�|�}|�fS)Ncstj���ot���S)N)r��path�exists�unlinkr)r\rrr��rSz7EventLoopTestsMixin._make_unix_server.<locals>.<lambda>)rcZgen_unix_socket_pathr@r!�create_unix_serverr )r$�factory�kwargsr�rSr)r\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)
N)r!cs�S)Nrr)r�rrr��rSz=EventLoopTestsMixin.test_create_unix_server.<locals>.<lambda>rTsxxxr7cs
�jdkS)Nr)r2r)r�rrr��rSrRr?)rAr!rbr|r:rRr�r�r�r0r r4r1rcr�r2r0r)r5)r$rSr\r�r)r�r�test_create_unix_server�s


z+EventLoopTestsMixin.test_create_unix_serverr�zNo UNIX Socketsc
sft|jd��t��}|�D|jj�fdd�d|d�}|�td��|j�|�WdQRXWdQRXdS)N)r!cs�S)Nrr)r�rrr��rSzOEventLoopTestsMixin.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_rAr�r )r$r�r�r)r�r�)test_create_unix_server_path_socket_error�sz=EventLoopTestsMixin.test_create_unix_server_path_socket_errorcCs,t�tj�}|jtjO_|�||�|S)N)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)Nz	127.0.0.1r)r	)rkr!rQr rRr�r|)
r$r`rhrirjr�rSr�rFr%rrr�_make_ssl_server�s
z$EventLoopTestsMixin._make_ssl_servercCs|�||�}|j||d�S)N)r	)rkrb)r$r`rhrirjrrr�_make_ssl_unix_servers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)N)r!cs�S)Nrr)r�rrr�
rSz<EventLoopTestsMixin.test_create_server_ssl.<locals>.<lambda>)r	sxxxr7cs
�jdkS)Nr)r2r)r�rrr�rSrR)rr?)rAr!rlrc�ONLYCERT�ONLYKEYr�r.rr rCr4r|r1r�r2rr0r)r5)r$rSrFr%�f_cr�r�r)r�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)N)r!cs�S)Nrr)r�rrr�.rSzAEventLoopTestsMixin.test_create_unix_server_ssl.<locals>.<lambda>rD)r	r!sxxxr7cs
�jdkS)Nr)r2r)r�rrr�9rSrRr?)rAr!rmrcrnror�r.rr rCr4r|r1r�r2r0r)r5)r$rSr\rpr�r�r)r�r�test_create_unix_server_ssl)s"


z/EventLoopTestsMixin.test_create_unix_server_sslcs�t|jd��|��fdd�tj�\}}}t�tj�}|jtj	O_tj
|_t|d�r\d|_
|jjt|||d�}tj�|jd��Lt���,|�tjd��|j�|�WdQRXWdQRXt�|j�WdQRX|��j�|��dS)	N)r!cs�S)Nrr)r�rrr�LrSzJEventLoopTestsMixin.test_create_server_ssl_verify_failed.<locals>.<lambda>�check_hostnameT)r	�call_exception_handlerz(?i)certificate.verify.failed)rAr!rlrc�SIGNED_CERTFILEr	re�PROTOCOL_TLS_CLIENTrfrg�
CERT_REQUIRED�verify_moderrsr�rr�objectrrArr rd�assertIsNoner0r))r$rSrFr%�sslcontext_clientrpr)r�r�$test_create_server_ssl_verify_failedHs$

 z8EventLoopTestsMixin.test_create_server_ssl_verify_failedcs�t|jd��|��fdd�tj�\}}t�tj�}|jtj	O_tj
|_t|d�rZd|_
|jjt||dd�}tj�|jd��Lt���,|�tjd	��|j�|�WdQRXWdQRXt�|j�WdQRX|��j�|��dS)
N)r!cs�S)Nrr)r�rrr�jrSzOEventLoopTestsMixin.test_create_unix_server_ssl_verify_failed.<locals>.<lambda>rsTZinvalid)r	r!rtz(?i)certificate.verify.failed)rAr!rmrcrur	rervrfrgrwrxrrsr�rrryrrArr rdrzr0r))r$rSr\r{rpr)r�r�)test_create_unix_server_ssl_verify_failedes&


 z=EventLoopTestsMixin.test_create_unix_server_ssl_verify_failedcs�t|jd��|��fdd�tj�\}}}t�tj�}|jtj	O_tj
|_|jtj
d�t|d�rjd|_|jjt|||d�}tj�|jd��@t���,|�tjd	��|j�|�WdQRXWdQRXWdQRX|��j�|��dS)
N)r!cs�S)Nrr)r�rrr��rSzIEventLoopTestsMixin.test_create_server_ssl_match_failed.<locals>.<lambda>)r
rsT)r	rtz=IP address mismatch, certificate is not valid for '127.0.0.1')rAr!rlrcrur	rervrfrgrwrx�load_verify_locations�
SIGNING_CArrsr�rrryrrAZCertificateErrorr rzr0r))r$rSrFr%r{rpr)r�r�#test_create_server_ssl_match_failed�s(


*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�dS)	N)r!cs�S)Nrr)r�rrr��rSzJEventLoopTestsMixin.test_create_unix_server_ssl_verified.<locals>.<lambda>)r
rsT�	localhost)r	r!)rAr!rmrcrur	rervrfrgrwrxr~rrrsr�r r0r)r5)r$rSr\r{rpr�r�r)r�r�$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|||ftjd	��j��|��|��|j��j�dS)
N)r!cs�S)Nrr)r�rrr��rSzEEventLoopTestsMixin.test_create_server_ssl_verified.<locals>.<lambda>)r
rsTr�)r	r!)rr)rAr!rlrcrur	rervrfrgrwrxr~rrrsr�r rZPEERCERTr0r)r5)r$rSrFr%r{rpr�r�r)r�r�test_create_server_ssl_verified�s&


z3EventLoopTestsMixin.test_create_server_ssl_verifiedc	s�tj|jd��G�fdd�dt�}tjtjd�}|�tjtjd�|�	d�|jj
||d�}|j�|�}|jd}|�
||�|��\}}|�|d	�t��}|�d
|f�|�d�|��|��dS)N)r!cseZdZ��fdd�Z�ZS)z@EventLoopTestsMixin.test_create_server_sock.<locals>.TestMyProtocst��|���|�dS)N)rBr9r8)r$r0)rDr�rrr9�szPEventLoopTestsMixin.test_create_server_sock.<locals>.TestMyProto.connection_made)r+r,r-r9rEr)r�)rDr�TestMyProto�sr�)r�rT)z0.0.0.0r)r�rz0.0.0.0z	127.0.0.1sxxx)rr3r!rAr�r��
setsockoptrZ�SO_REUSEADDRr�rQr rRr�r�r|r�r&r))	r$r��sock_obr�rSr�rFr%r�r)r�r�test_create_server_sock�s 


z+EventLoopTestsMixin.test_create_server_sockc	Cs�tjtjd�}|�tjtjd�|�d�|jjt|d�}|j�	|�}|j
d}|��\}}|jjt||d�}|�t
��}|j�	|�WdQRX|�|jjtj�|��dS)N)r�rT)z0.0.0.0r)r�r)rFr%)r�r�r�rZr�r�r!rQrAr rRr�rkr(r|rr)r*r))r$r�r�rSr�rFr%rrrr�test_create_server_addr_in_use�s

z2EventLoopTestsMixin.test_create_server_addr_in_usezIPv6 not supported or enabledc	
s<tj|jd��G�fdd�dt�}d}xzy*t��}|jj|d|d�}|j�|�}WnHtk
r�}z*|j	t	j
kr�|d7}|�d|�w(n�Wdd}~XYq(XPq(Wt��}|�
d|f�|�d	�|j���}|j��|��tj|jd��t�tj�}|�
d
|f�|�d	�|j���}|j��|��|��dS)N)r!cseZdZ��fdd�Z�ZS)zFEventLoopTestsMixin.test_create_server_dual_stack.<locals>.TestMyProtocst��|���|�dS)N)rBr9r8)r$r0)rD�f_protorrr9szVEventLoopTestsMixin.test_create_server_dual_stack.<locals>.TestMyProto.connection_made)r+r,r-r9rEr)r�)rDrr�sr�r)rFr%rTrz	127.0.0.1sxxxz::1)rr3r!rArr$rQr r(r)r*ZassertGreaterEqualr�r�r&r0r)rV)	r$r�Z	try_countr%r�rSZexr�r�r)r�r�test_create_server_dual_stacks:



z1EventLoopTestsMixin.test_create_server_dual_stackcCs�|j�tdd�}|j�|�}|jd}|��\}}t��}|�d|f�|�d�|�	�|�	�t��}|�
t|jd|f�|�	�dS)Nz0.0.0.0rz	127.0.0.1sxxx)r!rQrAr rRr�r�r�r&r)rkr�)r$r�rSr�rFr%r�rrr�test_server_close+s

z%EventLoopTestsMixin.test_server_closecsnG�fdd�dt�}�jj|dd�}�j�|�\}�|�d�\}}��|tj����|���d�j	���
�j|��jj�fdd�||fd	�}�j�|�\}���|tj����t���d�j	���
�j|�|�d
�t
��j�fdd����d�j�t
��j�fd
d����d�j���|�d��|���j��j���d�j	��j��dS)Ncs*eZdZ��fdd�Z�fdd�Z�ZS)zNEventLoopTestsMixin.test_create_datagram_endpoint.<locals>.TestMyDatagramProtocst�j�jd�dS)N)r!)rBr6r!)Z
inner_self)rDr$rrr6?szWEventLoopTestsMixin.test_create_datagram_endpoint.<locals>.TestMyDatagramProto.__init__cs$t��||�|j�d||�dS)Nsresp:)rBrIr0�sendto)r$r;rH)rDrrrIBsz`EventLoopTestsMixin.test_create_datagram_endpoint.<locals>.TestMyDatagramProto.datagram_received)r+r,r-r6rIrEr)r$)rDr�TestMyDatagramProto>sr�)z	127.0.0.1r)r#r�rGcst�jd�S)N)r!)rFr!r)r$rrr�QrSzCEventLoopTestsMixin.test_create_datagram_endpoint.<locals>.<lambda>)Zremote_addrsxxxcs�jS)N)r2r)rSrrr�[rSrRcs�jS)N)r2r)r�rrr�]rS�r?)rFr!�create_datagram_endpointr r�r�rr�r|r1r�r0r�rcr�r2r�r)r5)r$r�rBZs_transportrFr%r0r)r�r$rSr�test_create_datagram_endpoint=s6


z1EventLoopTestsMixin.test_create_datagram_endpointcs�tjdkr"t�jtj�r"t�d��d}d}�j��jj	|dt
ji��}xN|D]F\}}}}}y(t
j
|||d�}|�d�|�
|�WnYqLXPqLW�jj�fdd�|d	�}	�j�|	�\}
}��|
tj���|t�|
���j�|j�dS)
Nrz.UDP is not supported with proactor event loops)z	127.0.0.1rr�)r�r�r�Fcst�jd�S)N)r!)rFr!r)r$rrr��rSzHEventLoopTestsMixin.test_create_datagram_endpoint_sock.<locals>.<lambda>)r�)rrr�r!rr�r;r<r r�r�Z
SOCK_DGRAMr�r�r�r�rr�rFr)r5)r$r�Z
local_addressrr�r�r�rr�r�r�r�r)r$r�"test_create_datagram_endpoint_sockks0

z6EventLoopTestsMixin.test_create_datagram_endpoint_sockcCsf|��}t|tj�s&|��|�d�|�d|j�|��|�d|j�|�|j	�|�|j
�dS)Nz#loop is not a BaseSelectorEventLooprTr)rar�r	ZBaseSelectorEventLoopr)�skipTestr|Z
_internal_fdsrzZ_csockZ_ssock)r$r!rrr�test_internal_fds�s
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���
dd
ddg�j����j�d��dS)N)r!�rbic�s^�j��fdd���IdH\}}��|����|�j���ddg�j���d�j�dS)Ncs�S)Nrr)r�rrr��rSzEEventLoopTestsMixin.test_read_pipe.<locals>.connect.<locals>.<lambda>r/r7r)r!�connect_read_piper�r0r|r1r2)r��p)�pipeobjr�r$rrr��sz3EventLoopTestsMixin.test_read_pipe.<locals>.connect�1cs
�jdkS)NrT)r2r)r�rrr��rSz4EventLoopTestsMixin.test_read_pipe.<locals>.<lambda>rTs2345cs
�jdkS)Nr)r2r)r�rrr��rSr/r7rr=r?�pipe)rKr!r�r��io�openr rCrcr�r|r2r1r)r5r�r0r�)r$�rpipe�wpiper�r)r�r�r$r�test_read_pipe�s"
z"EventLoopTestsMixin.test_read_pipecs�|���t�d��t�d��t��\}}t�|dd��t�|dd�������fdd�}��|��\}}���|�	dt
|��|�	dt
|��������d|_d|_dS)N)r!r�ir�c�sD���fdd���IdH\}}���fdd���IdH\}}||fS)Ncs�S)Nrr)�
read_protorrr��rSzSEventLoopTestsMixin.test_unclosed_pipe_transport.<locals>.connect.<locals>.<lambda>cs�S)Nrr)�write_protorrr��rS)r��connect_write_pipe)�read_transportr8�write_transport)r!r��rpipeobj�wpipeobjr�rrr��s
zAEventLoopTestsMixin.test_unclosed_pipe_transport.<locals>.connectr�)rarKrMr�r�r�r�r r)r+�reprZ_pipe)r$r�r�r�r�r�r)r!r�r�r�r�r�test_unclosed_pipe_transport�s

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���
dd
ddg�j����j�d��dS)N)r!r�rc�s^�j��fdd���IdH\}}��|����|�j���ddg�j���d�j�dS)Ncs�S)Nrr)r�rrr��rSzKEventLoopTestsMixin.test_read_pty_output.<locals>.connect.<locals>.<lambda>r/r7r)r!r�r�r0r|r1r2)r�r�)�master_read_objr�r$rrr��sz9EventLoopTestsMixin.test_read_pty_output.<locals>.connectr�cs�jS)N)r2r)r�rrr��rSz:EventLoopTestsMixin.test_read_pty_output.<locals>.<lambda>rTs2345cs
�jdkS)Nr)r2r)r�rrr��rSr/r7rr=r?r�)rKr!r��openptyr�r�r rCrcr�r|r2r1r)r0r5r�r�)r$�master�slaver�r)r�r�r$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�wbi)r!cs�S)Nrr)r�rrr�rSz5EventLoopTestsMixin.test_write_pipe.<locals>.<lambda>r7r�cst��d�}||7}t|�S)Ni)r�r�r:)r;�chunk)r�rrr�
sz3EventLoopTestsMixin.test_write_pipe.<locals>.readercs���dkS)NrTrr)r;r�rrr�rSs2345cs���dkS)Nrrr)r;r�rrr�rSs12345r�r?)r�r�r�r�rMr!r�r r�r0r|r1rCr�rcr�r)r�r�r5)r$r�r�r�r0r�r)r;r�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)
NFr�i)r!cs�S)Nrr)r�rrr�,rSzIEventLoopTestsMixin.test_write_pipe_disconnect_on_close.<locals>.<lambda>r7r�r?)r�r�r�r�r��detachrMr!r�r r�r0r|r1rCr�r)r5)r$ZrsockZwsockr�r�r0r�r;r)r�r�#test_write_pipe_disconnect_on_close$s

z7EventLoopTestsMixin.test_write_pipe_disconnect_on_closerr�cs>t��\�}t�|dd�}t|jd��|j��fdd�|�}|j�|�\}}|�|��|�|�j	�|�
d�j�|�d�t
���fdd	��tj|j��fd
d�dd�|�
d��|�d
�tj|j��fdd�dd�|�
d��|�
d�j�t���|��j	�d���j	��|j��j�|�
d�j�dS)Nr�r)r!cs�S)Nrr)r�rrr�ErSz4EventLoopTestsMixin.test_write_pty.<locals>.<lambda>r7r�cst��d�}||7}t|�S)Ni)r�r�r:)r;r�)r�rrr�Nsz2EventLoopTestsMixin.test_write_pty.<locals>.readercs���dkS)NrTrr)r;r�rrr�SrSr)r6s2345cs���dkS)Nrrr)r;r�rrr�XrSs12345r�r?)r�r�r�r�rMr!r�r r�r0r|r1rCr�rcr�r)r�r�r5)r$r��slave_write_objr�r0r�r)r;r�r�r�r�test_write_pty;s0



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�dd�|�
d��|�
ddg�j�|�
d�j�t��d�tj|j�fdd�dd�|�
ddg�j�|�
d�j�|�
d�j�|	�d�tj|j��fdd�dd�|�
d��|�
ddg�j�|�
d�j�t��d�tj|j�fdd�dd�|�
ddg�j�|�
d�j�|�
d�j�t���|��|j�
�j�|�
ddddg�j�|	��|j�
�j�|�
d�j�dS)Nr�r)r!cs�S)Nrr)r�rrr�srSz<EventLoopTestsMixin.test_bidirectional_pty.<locals>.<lambda>r/r7r�cs�S)Nrr)r�rrr�~rScst��d�}||7}t|�S)Ni)r�r�r:)r;r�)r�rrr��sz:EventLoopTestsMixin.test_bidirectional_pty.<locals>.readerr�cs���dkS)NrTrr)r;r�rrr��rSr)r6�acs
�jdkS)NrT)r2r)r�rrr��rSrTs2345cs���dkS)Nrrr)r;r�rrr��rSs12345sbcdecs
�jdkS)Nr)r2r)r�rrr��rSrr=r?)r�r��dup�ttyZsetrawr�r�rKr!r�r r�r0r|r1r2rMr�r�rCrcr�r)r5)
r$Z
read_slaveZwrite_slaveZslave_read_objZread_connectr�r�r�Z
write_connectr�r)r;r�r�r�r�r�test_bidirectional_ptygsh




z*EventLoopTestsMixin.test_bidirectional_ptycs�t��\}}|�d��j��j�|d���t�dd�}|dk	rL��|j���fdd�}t	�
�}tj|��jd�}�j�
�t	�
�|}��|d���|��d���tj�j�|dk	rʈ�|j��j�|�|��|��dS)	NFrT�ovc�sRz@y�j��j��IdHWntjk
r8d}YnXd}Wd�j��X|S)N�	cancelled)r!rr�r�CancelledErrorrs)r�)r�r$rr�main�s
z:EventLoopTestsMixin.test_prompt_cancellation.<locals>.main)r!g�������?r�)r�r�r�r!�create_taskr��getattrrgZpendingrnrzrrHr{Z
assertLessr|�resultrkr�r�rPr))r$r�r�r�r�r�r��elapsedr)r�r$r�test_prompt_cancellation�s&

z,EventLoopTestsMixin.test_prompt_cancellationcsh��fdd�}�jj�d�j_|�j_�fdd�}�j�|�����jjd�jj�jjjjd��dS)Ncs�jjd7_��dS)NrT)r!�_run_once_counterr)�
orig_run_oncer$rr�	_run_once�sz<EventLoopTestsMixin.test_timeout_rounding.<locals>._run_oncerc�sn�j}tjd|d�IdHtjd|d�IdHtjd|d�IdHtjd|d�IdHtjd|d�IdHdS)Ng{�G�z�?)r!g-C��6?g���ư>g:�0�yE>g�����|�=)r!rro)r!)r$rr�wait�sz7EventLoopTestsMixin.test_timeout_rounding.<locals>.wait�)Zclock_resolutionZselector)	r!r�r�r ZassertLessEqualZ_clock_resolutionZ	_selectorrDr+)r$r�r�r)r�r$r�test_timeout_rounding�sz)EventLoopTestsMixin.test_timeout_roundingcCsx|��}dd�}t��\}}|�|j�|�|j�|�||�|�||�|��|�|�|��|�|�	|��dS)NcSsdS)Nrrrrrr��rSzCEventLoopTestsMixin.test_remove_fds_after_closing.<locals>.<lambda>)
rar�r�r@r)r�r�r�r�r�)r$r!rxr�r�rrr�test_remove_fds_after_closing�sz1EventLoopTestsMixin.test_remove_fds_after_closingc	Cs�|��}dd�}t��\}}|�|j�|�|j�|��|�t��|�||�WdQRX|�t��|�||�WdQRXdS)NcSsdS)Nrrrrrr��rSz@EventLoopTestsMixin.test_add_fds_after_closing.<locals>.<lambda>)	rar�r�r@r)rkrlr�r�)r$r!rxr�r�rrr�test_add_fds_after_closing�sz.EventLoopTestsMixin.test_add_fds_after_closingc	sBtj�fdd��}|�j�}��t���j�|�WdQRXdS)Ncs�j��dS)N)r!r))r!)r$rr�
close_loopszEEventLoopTestsMixin.test_close_running_event_loop.<locals>.close_loop)rrjr!rkrlr )r$r�rBr)r$r�test_close_running_event_loops
z1EventLoopTestsMixin.test_close_running_event_loopc	Cs�|j��tjdd��}dd�}|�}|�|j�|�t��|j��WdQRX|�t�� tj|jd�}|j�	|�WdQRX|�t��|j�
|�WdQRX|�t��|j�|�WdQRX|�t��|j�d|�WdQRX|�t��|j�
|j��d|�WdQRX|�t��|j�|�WdQRX|�t��|j�tj|�WdQRX|�t�� |j�d|���}t|�WdQRXdS)NcSsdS)Nrrrrr�testsz,EventLoopTestsMixin.test_close.<locals>.testcSsdS)NFrrrrrr�rSz0EventLoopTestsMixin.test_close.<locals>.<lambda>)r!g�?g)r!r)rrjr@rkrlr{r3r rr�ry�call_atrnr�r�r��SIGTERMr�r*�next)r$r��funcrB�fut�itrrr�
test_closes2
"zEventLoopTestsMixin.test_close)T)TN)TN)NN)N)N)N)]r+r,r-r`rermrrrur}r�r�r�r�r�r�r�r�r�r�rZskip_unless_bind_unix_socketr�r�r�r;�
skipUnlessrr�r�r�r�r�r�r�rrrr�skipIfr	r r"r'r-r9r?rCrrrTrUrWrXr�r[rbrcrdrkrlrmrqrrr|r}r�r�r�r�r�ZIPV6_ENABLEDr�r�r�r�r�rrr�r�r�r�r��requires_mac_verr�r�r�r�r�r�r�r�rErr)rDrr_�s�		
$,
 

$


8
$	


 ).!!"&(E#	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)$�SubprocessTestsMixincCs,tjdkr|�|t�n|�tj|�dS)Nr)rrr�rr|r�r�)r$rYrrr�check_terminated6s
z%SubprocessTestsMixin.check_terminatedcCs,tjdkr|�|t�n|�tj|�dS)Nr)rrr�rr|r�r�)r$rYrrr�check_killed=s
z!SubprocessTestsMixin.check_killedc	Cs�tj�tj�t�d�}|j�t�t	|j�t
j|�}|j�|�\}}|�
|t	�|j�|j�|�d|j�|�d�}|�d�|j�|jd���t���|��WdQRX|j�|j�|�|j�|�d|jd�dS)Nzecho.pyr7rsPython The WinnerrT)r�r\r��dirname�__file__r!�subprocess_execrrrNr�
executabler r�r4r|r1�get_pipe_transportrCrZr�rcrr)rVr�rYr;)r$�progr��transpr��stdinrrr�test_subprocess_execDs 



z)SubprocessTestsMixin.test_subprocess_execc	Cs tj�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���|��WdQRX|j�|j�|�|j�dS)Nzecho.pyr7rsPython rTs
The WinnersPython The Winner)r�r\r�r�r�r!r�rrrNrr�r r�r4r|r1r�rCrZr��clearr;rcrr)rVr�rY)r$r�r�r�r�r�rrr�test_subprocess_interactiveXs(




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|]}|��VqdS)N)r5)rOr�rrr�	<genexpr>}sz=SubprocessTestsMixin.test_subprocess_shell.<locals>.<genexpr>rTs
sPythonrUrS)r!�subprocess_shellrrrNr r�r4r�r)rVr|rYrg�allrX�valuesr;�rstrip)r$r�r�r�rrr�test_subprocess_shellrsz*SubprocessTestsMixin.test_subprocess_shellcCsd|jjt�t|j�ddddd�}|j�|�\}}|�|t�|j�|j�|�d|j	�|�
�dS)Nzexit 7)r��stdout�stderr�)r!r�rrrNr r�rVr|rYr))r$r�r�r�rrr�test_subprocess_exitcode�sz-SubprocessTestsMixin.test_subprocess_exitcodecCs�|jjt�t|j�ddddd�}|j�|�\}}|�|t�|�|�d��|�|�d��|�|�d��|j�|j	�|�
d|j�|�|���dS)Nzexit 7)r�r�r�rrTrUr�)
r!r�rrrNr r�rzr�rVr|rYr))r$r�r�r�rrr�"test_subprocess_close_after_finish�sz7SubprocessTestsMixin.test_subprocess_close_after_finishcCs�tj�tj�t�d�}|j�t�t	|j�t
j|�}|j�|�\}}|�
|t	�|j�|j�|��|j�|j�|�|j�|��dS)Nzecho.py)r�r\r�r�r�r!r�rrrNrr�r r�r4r�rVr�rYr))r$r�r�r�r�rrr�test_subprocess_kill�s
z)SubprocessTestsMixin.test_subprocess_killcCs�tj�tj�t�d�}|j�t�t	|j�t
j|�}|j�|�\}}|�
|t	�|j�|j�|��|j�|j�|�|j�|��dS)Nzecho.py)r�r\r�r�r�r!r�rrrNrr�r r�r4Z	terminaterVr�rYr))r$r�r�r�r�rrr�test_subprocess_terminate�s
z.SubprocessTestsMixin.test_subprocess_terminaterzDon't have SIGHUPc
Cs�t�tjtj�}z�tj�tj�t�d�}|j�	t
�t|j�t
j|�}|j�|�\}}|�|t�|j�|j�|�tj�|j�|j�|�tj|j�|��Wdt�tj|�XdS)Nzecho.py)r��SIGHUP�SIG_DFLr�r\r�r�r�r!r�rrrNrr�r r�r4Zsend_signalrVr|rYr))r$Zold_handlerr�r�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)Nzecho2.pyrstestsOUT:testrTrUsERR:test)r�r\r�r�r�r!r�rrrNrr�r r�r4r�rCrVr)r|r;rgrrY)r$r�r�r�r�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)	Nzecho2.py)r�rrTrUstestsOUT:testERR:testrS)r�r\r�r�r�r!r�rrrNrr��
subprocessZSTDOUTr r�r4r�r�rzrCrVrgr;rr|r)rY)r$r�r�r�r�r�rrr�)test_subprocess_stderr_redirect_to_stdout�s"

z>SubprocessTestsMixin.test_subprocess_stderr_redirect_to_stdoutc	CsFtj�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���|��WdQRX|j�|j�|�|j�dS)Nzecho3.pyrrTstestsOUT:testsxxxrUrsERR:BrokenPipeErrorsERR:OSError)r�r\r�r�r�r!r�rrrNrr�r r�r4r�rCrZr�r|r;r)rXrrcrrVr�rY)r$r�r�r�r�r�r�rrr�#test_subprocess_close_client_stream�s.






z8SubprocessTestsMixin.test_subprocess_close_client_streamccs`|jjt�t|j�dddddd�}|j�|�V\}}|�|t�|j�|j�|�d|j	�dS)Nzexit 7T)r�r�r�Zstart_new_sessionr�)
r!r�rrrNr r�rVr|rY)r$r�r8r�rrr�"test_subprocess_wait_no_same_groupsz7SubprocessTestsMixin.test_subprocess_wait_no_same_groupc	s��fdd�}��t���j�|dd��WdQRX��t���j�|dd��WdQRX��t���j�|dd��WdQRXdS)Nc�s�jjtjdf|�IdHdS)N�pwd)r!r�r�SubprocessProtocol)rI)r$rrr�'szGSubprocessTestsMixin.test_subprocess_exec_invalid_args.<locals>.connectT)�universal_newlinesi)�bufsize)�shell)rkr�r!r )r$r�r)r$r�!test_subprocess_exec_invalid_args%sz6SubprocessTestsMixin.test_subprocess_exec_invalid_argsc	s�d�fdd�	}��t���j�|ddg��WdQRX��t���j�|dd��WdQRX��t���j�|dd��WdQRX��t���j�|d	d
��WdQRXdS)Nc�s&|sd}�jjtj|f|�IdHdS)Nr�)r!r�rr�)�cmdrI)r$rrr�5s
zHSubprocessTestsMixin.test_subprocess_shell_invalid_args.<locals>.connectZlsz-lT)r�i)r�F)r�)N)rkr�r!r )r$r�r)r$r�"test_subprocess_shell_invalid_args3sz7SubprocessTestsMixin.test_subprocess_shell_invalid_argsN)r+r,r-r�r�r�r�r�r�r�r�r�r;r�rrr�r�r�r�r�r�rrrrrr�4s 

!r�csPeZdZddZdZe�fdd��Ze�fdd��Z�fdd	�Zd
d�Z	�Z
S)�SendfileBasesSendfileBaseDatai ic	s2ttjd��}|�|j�WdQRXt���dS)Nr�)r�r�TESTFNrC�DATArB�
setUpClass)�cls�fp)rDrrrNszSendfileBase.setUpClasscst�tj�t���dS)N)rr^rrB�
tearDownClass)r)rDrrrTszSendfileBase.tearDownClasscs*ttjd�|_|�|jj�t���dS)Nr�)r�rr�filer@r)rBr`)r$)rDrrr`YszSendfileBase.setUpcCs|j�|�S)N)r!r )r$rBrrr�run_loop^szSendfileBase.run_loop)r+r,r-r�BUF_SIZE�classmethodrrr`r
rErr)rDrrFsrcs�eZdZGdd�dej�Ze�fdd��Ze�fdd��Zddd	�Z	d
d�Z
dd
d�Zdd�Zdd�Z
dd�Zdd�Zdd�Z�ZS)�SockSendfileMixinc@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)zSockSendfileMixin.MyProtocCs(d|_d|_t�|_|��|_d|_dS)NF)�started�closedr�r;�
create_futurer�r0)r$r!rrrr6fs

z"SockSendfileMixin.MyProto.__init__cCsd|_||_dS)NT)rr0)r$r0rrrr9msz)SockSendfileMixin.MyProto.connection_madecCs|j�|�dS)N)r;r�)r$r;rrrr<qsz'SockSendfileMixin.MyProto.data_receivedcCsd|_|j�d�dS)NT)rr�r8)r$r'rrrr@tsz)SockSendfileMixin.MyProto.connection_lostc�s|jIdHdS)N)r�)r$rrr�wait_closedxsz%SockSendfileMixin.MyProto.wait_closedN)r+r,r-r6r9r<r@rrrrrrAds
rAcstj|_dt_t���dS)Ni@)r�!SENDFILE_FALLBACK_READBUFFER_SIZE�_SockSendfileMixin__old_bufsizerBr)r)rDrrr{szSockSendfileMixin.setUpClasscs|jt_t���dS)N)rrrrBr)r)rDrrr�szSockSendfileMixin.tearDownClassTcCs.t�tjtj�}|�d�|r*|�|j�|S)NF)r�rEr�r�r@r))r$�cleanupr�rrr�make_socket�s

zSockSendfileMixin.make_socketcCs|�tjtj|j�dS)N)r�r�rZZ	SO_RCVBUFr)r$r�rrr�reduce_receive_buffer_size�sz,SockSendfileMixin.reduce_receive_buffer_sizeNcCs.|�tjtj|j�|dk	r*|j|jd�dS)N)Zhigh)r�r�rZZ	SO_SNDBUFrZset_write_buffer_limits)r$r�r0rrr�reduce_send_buffer_size�sz)SockSendfileMixin.reduce_send_buffer_sizecs����j��t��}�jdd�}|�tj|f����jj�fdd�|d�����	|����}���j�
|d|f����|����fdd�}��|�|�fS)	NF)rcs�S)Nrr)r�rrr��rSz8SockSendfileMixin.prepare_socksendfile.<locals>.<lambda>)r�z	127.0.0.1cs<�jdk	r"�j�����������������dS)N)r0r)r
rr)r�r$rSrrr�s


z7SockSendfileMixin.prepare_socksendfile.<locals>.cleanup)
rAr!rr$rr��HOSTr
rQrr�rr@)r$r%�srv_sockr�rr)r�r$rSr�prepare_socksendfile�s




z&SockSendfileMixin.prepare_socksendfilecCsv|��\}}|�|j�||j��}|��|�|���|�|t|j	��|�|j
|j	�|�|j��t|j	��dS)N)rr
r!�
sock_sendfiler	r)rr|r:rr;�tell)r$r�r��retrrr�test_sock_sendfile_success�sz,SockSendfileMixin.test_sock_sendfile_successcCsv|��\}}|�|j�||jdd��}|��|�|���|�|j|j	dd��|�|j�
�d�|�|d�dS)Ni�i�i�)rr
r!rr	r)rr|r;rr)r$r�r�rrrr�(test_sock_sendfile_with_offset_and_count�s
z:SockSendfileMixin.test_sock_sendfile_with_offset_and_countc	Csp|��\}}t���}|�|j�||dd��}WdQRX|��|�|���|�|d�|�|j	�
�d�dS)Nr)r�tempfileZ
TemporaryFiler
r!rr)rr|r	r)r$r�r�r�rrrr�test_sock_sendfile_zero_size�s
z.SockSendfileMixin.test_sock_sendfile_zero_sizecCs�dd}|��\}}|�|j�||��|�|j�||j��}|�|j�||��|��|�|���|�|t	|j
��||j
|}|�|j|�|�|j��t	|j
��dS)Nsmix_regular_sendi)
rr
r!r�rr	r)rr|r:rr;r)r$r�r�r�rr&rrr�(test_sock_sendfile_mix_with_regular_send�sz:SockSendfileMixin.test_sock_sendfile_mix_with_regular_send)T)N)r+r,r-rr�rArrrrrrrrrr!r"rErr)rDrr
bs



r
c@s�eZdZGdd�de�Zddd�dd�Ze�ej	dkd	�d
d��Z
dd
�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Ze�eed&�d'�d(d)��Zd*d+�Zd,S)-�
SendfileMixincs*eZdZd�fdd�	Z�fdd�Z�ZS)zSendfileMixin.MySendfileProtoNrcst��|�t�|_||_dS)N)rBr6r�r;�close_after)r$r!r$)rDrrr6�sz&SendfileMixin.MySendfileProto.__init__cs8|j�|�t��|�|jr4|j|jkr4|j��dS)N)r;r�rBr<r$r2r0r))r$r;)rDrrr<�sz+SendfileMixin.MySendfileProto.data_received)Nr)r+r,r-r6r<rErr)rDr�MySendfileProto�sr%Fr)�is_sslr$cs$t��}�j�j|d��|r<ts*��d�t��}t��}nd}d}t	�	t	j
t	j�}|�tj
|f����jj�fdd�||d�����|�|r�tj
}nd}t	�	t	j
t	j�}|�tj
|f��j�jd�����jj�fdd�|||d��\}	}
�j||	d	�����fd
d�}��|���fS)N)r!r$z
No ssl modulecs�S)Nrr)�	srv_protorrr�	rSz0SendfileMixin.prepare_sendfile.<locals>.<lambda>)r�r	)r!cs�S)Nrr)�	cli_protorrr�	rS)r�r	r!)r0csF�j���j�����j����j����������dS)N)r0r)r
r5rr)r(r$rSr'rrr	s

z/SendfileMixin.prepare_sendfile.<locals>.cleanup)rr$r%r!r	r�rcr=r>r�rEr�r�rr
rQrr�r�rr@)r$r&r$r%Zsrv_ctxZcli_ctxrr!Zcli_sockr�r�rr)r(r$rSr'r�prepare_sendfile�s8




	
zSendfileMixin.prepare_sendfilerzUDP sockets are not supportedc	sx���jj�fdd�tjd��\}}zD��td�����j�|�j��WdQRX��	d�j�
��Wd|��XdS)Ncst�jd�S)N)r!)rFr!r)r$rrr�'	rSz;SendfileMixin.test_sendfile_not_supported.<locals>.<lambda>)r�z
not supportedr)r
r!r�r�rErArl�sendfiler	r|rr))r$r�r�r)r$r�test_sendfile_not_supported#	s
z)SendfileMixin.test_sendfile_not_supportedcCs�|��\}}|�|j�|j|j��}|j��|�|j�|�|t	|j
��|�|jt	|j
��|�|j|j
�|�|j�
�t	|j
��dS)N)r)r
r!r*r0r	r)r5r|r:rr2r;r)r$r'r(rrrr�
test_sendfile2	s
zSendfileMixin.test_sendfilecs����\}}�fdd�}|�j_���j�|j�j��}|j����|j���	|t
�j����	|jt
�j����	|j
�j���	�j��t
�j��dS)Ncstj��j||||�S)N)r�
BaseEventLoop�_sendfile_nativer!)r�r	�offset�count)r$rr�sendfile_native@	szCSendfileMixin.test_sendfile_force_fallback.<locals>.sendfile_native)r)r!r.r
r*r0r	r)r5r|r:rr2r;r)r$r'r(r1rr)r$r�test_sendfile_force_fallback=	s
z*SendfileMixin.test_sendfile_force_fallbackc	s�tjdkr"t�jtj�r"��d����\}}�fdd�}|�j_��	t
jd��"���jj
|j�jdd��WdQRX|j����|j���|jd����j��d�dS)	NrzFails on proactor event loopcstj��j||||�S)N)rr-r.r!)r�r	r/r0)r$rrr1V	szMSendfileMixin.test_sendfile_force_unsupported_native.<locals>.sendfile_nativez
not supportedF)�fallbackr)rrr�r!r�ProactorEventLoopr�r)r.rArZSendfileNotAvailableErrorr
r*r0r	r)r5r|r2r)r$r'r(r1r)r$r�&test_sendfile_force_unsupported_nativeP	s


z4SendfileMixin.test_sendfile_force_unsupported_nativecCs�|jdd�\}}|�|j�|j|j��}|j��|�|j�|�|t	|j
��|�|jt	|j
��|�|j|j
�|�|j�
�t	|j
��dS)NT)r&)r)r
r!r*r0r	r)r5r|r:rr2r;r)r$r'r(rrrr�test_sendfile_sslh	s
zSendfileMixin.test_sendfile_sslc	Csv|��\}}|j��|�td��|�|j�|j|j��WdQRX|�|j	�|�
|jd�|�
|j��d�dS)Nz
is closingr)
r)r0r)rArlr
r!r*r	r5r|r2r)r$r'r(rrr� test_sendfile_for_closing_transps	s
"z.SendfileMixin.test_sendfile_for_closing_transpcCs�|��\}}dd}dd}|j�|�|�|j�|j|j��}|j�|�|j��|�|j�|�	|t
|j��|�	|j||j|�|�	|j�
�t
|j��dS)NsPREFIX__is--SUFFIX)r)r0rCr
r!r*r	r)r5r|r:rr;r)r$r'r(�PREFIX�SUFFIXrrrr�test_sendfile_pre_and_post_data|	s
z-SendfileMixin.test_sendfile_pre_and_post_datacCs�|jdd�\}}dd}dd}|j�|�|�|j�|j|j��}|j�|�|j��|�|j�|�	|t
|j��|�	|j||j|�|�	|j�
�t
|j��dS)NT)r&szxcvbnmis
0987654321)r)r0rCr
r!r*r	r)r5r|r:rr;r)r$r'r(r8r9rrrr�#test_sendfile_ssl_pre_and_post_data�	s
z1SendfileMixin.test_sendfile_ssl_pre_and_post_datacCs�|��\}}|�|j�|j|jdd��}|j��|�|j�|�|d�|�|j	d�|�|j
|jdd��|�|j��d�dS)Ni��diL)
r)r
r!r*r0r	r)r5r|r2r;rr)r$r'r(rrrr�test_sendfile_partial�	s
z#SendfileMixin.test_sendfile_partialcCs�|jdd�\}}|�|j�|j|jdd��}|j��|�|j�|�|d�|�|j	d�|�|j
|jdd��|�|j��d�dS)NT)r&i�r<iL)
r)r
r!r*r0r	r)r5r|r2r;rr)r$r'r(rrrr�test_sendfile_ssl_partial�	s
z'SendfileMixin.test_sendfile_ssl_partialcCs�|jt|j�d�\}}|�|j�|j|j��}|j��|�|j	�|�
|t|j��|�
|jt|j��|�
|j|j�|�
|j�
�t|j��dS)N)r$)r)r:rr
r!r*r0r	r)r5r|r2r;r)r$r'r(rrrr�(test_sendfile_close_peer_after_receiving�	s
z6SendfileMixin.test_sendfile_close_peer_after_receivingcCs�|jdt|j�d�\}}|�|j�|j|j��}|�|j�|�	|t|j��|�	|j
t|j��|�	|j|j�|�	|j��t|j��dS)NT)r&r$)
r)r:rr
r!r*r0r	r5r|r2r;r)r$r'r(rrrr�,test_sendfile_ssl_close_peer_after_receiving�	sz:SendfileMixin.test_sendfile_ssl_close_peer_after_receivingc	Cs�|jdd�\}}|�t��|�|j�|j|j��WdQRX|�|j�|�	d|j
koht|j�kn|j
�|�	d|j�
�ko�t|j�kn|j�
��|�	|j���dS)Ni)r$)r)rk�ConnectionErrorr
r!r*r0r	r5rgr2r:rr�
is_closing)r$r'r(rrr�3test_sendfile_close_peer_in_the_middle_of_receiving�	s"&zASendfileMixin.test_sendfile_close_peer_in_the_middle_of_receivingc	s��fdd�}|�j_�jdd�\}}��t�����j�|j�j��WdQRX��|j	���
d|jko|t�j
�kn|j���
d�j��ko�t�j
�kn�j���dS)Ncstj��j||||�S)N)rr-r.r!)r�r	r/r0)r$rrr1�	szcSendfileMixin.test_sendfile_fallback_close_peer_in_the_middle_of_receiving.<locals>.sendfile_nativei)r$)r!r.r)rkrAr
r*r0r	r5rgr2r:rr)r$r1r'r(r)r$r�<test_sendfile_fallback_close_peer_in_the_middle_of_receiving�	s"&zJSendfileMixin.test_sendfile_fallback_close_peer_in_the_middle_of_receivingr*z"Don't have native sendfile supportc	s����\}��j������fdd�}�j�|��}������td���j�d�WdQRX��|�}��	|t
�j��dS)Nc�s"��d��j��j�j�IdHS)N)r8r!r*r0r	r)r(r�r$rrrB�	s
z=SendfileMixin.test_sendfile_prevents_bare_write.<locals>.corozsendfile is in progresssdata)r)r!rr�r
rArlr0rCr|r:r)r$r'rBr�rr)r(r�r$r�!test_sendfile_prevents_bare_write�	s


z/SendfileMixin.test_sendfile_prevents_bare_writec	CsTt��}dd�|j_tjj|_|�t	d�� |j
�|j
j|ddd��WdQRXdS)NcSsdS)NFrrrrrr��	rSzPSendfileMixin.test_sendfile_no_fallback_for_fallback_transport.<locals>.<lambda>zfallback is disabledF)r3)
rrOrBrrZ
_SendfileModeZFALLBACKZ_sendfile_compatiblerArlr!r r*)r$r0rrr�0test_sendfile_no_fallback_for_fallback_transport�	s
z>SendfileMixin.test_sendfile_no_fallback_for_fallback_transportN)r+r,r-r.r%r)r;r�rrr+r,r2r5r6r7r:r;r=r>r?r@rCrDrr�rErFrrrrr#�s&+	
r#c@seZdZdd�ZdS)�SelectEventLoopTestscCst��S)N)r�SelectorEventLoop)r$rrrra
sz&SelectEventLoopTests.create_event_loopN)r+r,r-rarrrrrG
srGc@sDeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)�ProactorEventLoopTestscCst��S)N)rr4)r$rrrra
sz(ProactorEventLoopTests.create_event_loopcCst�d��dS)Nz(IocpEventLoop does not have add_reader())r;r<)r$rrrr�
sz+ProactorEventLoopTests.test_reader_callbackcCst�d��dS)Nz(IocpEventLoop does not have add_reader())r;r<)r$rrr�test_reader_callback_cancel
sz2ProactorEventLoopTests.test_reader_callback_cancelcCst�d��dS)Nz(IocpEventLoop does not have add_writer())r;r<)r$rrrr�
sz+ProactorEventLoopTests.test_writer_callbackcCst�d��dS)Nz(IocpEventLoop does not have add_writer())r;r<)r$rrr�test_writer_callback_cancel
sz2ProactorEventLoopTests.test_writer_callback_cancelcCst�d��dS)Nz6IocpEventLoop does not have create_datagram_endpoint())r;r<)r$rrrr� 
sz4ProactorEventLoopTests.test_create_datagram_endpointcCst�d��dS)Nz(IocpEventLoop does not have add_reader())r;r<)r$rrrr�$
sz4ProactorEventLoopTests.test_remove_fds_after_closingN)
r+r,r-rar�rJr�rKr�r�rrrrrI
srIcs(eZdZ�fdd�Z�fdd�Z�ZS)�UnixEventLoopTestsMixincs,t���t��}|�|j�t�|�dS)N)rBr`r�SafeChildWatcher�attach_loopr!�set_child_watcher)r$�watcher)rDrrr`,
s
zUnixEventLoopTestsMixin.setUpcst�d�t���dS)N)rrOrBre)r$)rDrrre2
s
z UnixEventLoopTestsMixin.tearDown)r+r,r-r`rerErr)rDrrL)
srL�KqueueSelectorcs\eZdZdd�Ze�dd�e�ej	�
d�d��fdd���Ze�dd��fd	d
��Z�Z
S)�KqueueEventLoopTestscCst�t���S)N)rrH�	selectorsrQ)r$rrrra<
sz&KqueueEventLoopTests.create_event_loopr�	Zopenbsdztest hangs on OpenBSDcst���dS)N)rBr�)r$)rDrrr�B
sz)KqueueEventLoopTests.test_read_pty_outputcst���dS)N)rBr�)r$)rDrrr�L
sz#KqueueEventLoopTests.test_write_pty)r+r,r-rarr�r;r�rrrr�r�rErr)rDrrR8
s

rR�
EpollSelectorc@seZdZdd�ZdS)�EPollEventLoopTestscCst�t���S)N)rrHrSrU)r$rrrraU
sz%EPollEventLoopTests.create_event_loopN)r+r,r-rarrrrrVQ
srV�PollSelectorc@seZdZdd�ZdS)�PollEventLoopTestscCst�t���S)N)rrHrSrW)r$rrrra]
sz$PollEventLoopTests.create_event_loopN)r+r,r-rarrrrrXY
srXc@seZdZdd�ZdS)rGcCst�t���S)N)rrHrSZSelectSelector)r$rrrrae
sz&SelectEventLoopTests.create_event_loopN)r+r,r-rarrrrrGa
scOsdS)Nr)r�rarrr�noopi
srYcsheZdZ�fdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	e
�ee
jd�d�dd��Z�ZS)�HandleTestscs"t���t��|_d|jj_dS)NT)rBr`rrOr!�	get_debug�return_value)r$)rDrrr`o
s

zHandleTests.setUpcCs`dd�}d}t�|||j�}|�|j|�|�|j|�|�|���|��|�	|���dS)NcWs|S)Nr)r�rrrrxu
sz)HandleTests.test_handle.<locals>.callbackr)
r�Handler!r��	_callback�_argsr�r�r�rg)r$rxr��hrrr�test_handlet
szHandleTests.test_handlecCs\dd�}t��|_t��|j_t�|d|j�}|��|jj�t�	d�tj
||jd��dS)NcSs
t��dS)N)r�rrrrrx�
sz:HandleTests.test_callback_with_exception.<locals>.callbackrzException in callback.*)r4rZhandleZsource_traceback)rrOr!rtrr]Z_run�assert_called_withrcZMockPattern�ANY�_source_traceback)r$rxr`rrr�test_callback_with_exception�
s
z(HandleTests.test_callback_with_exceptioncCs(t��}t�dd�d|j�}||d<dS)NcSsdS)Nrrrrrr��
rSz1HandleTests.test_handle_weakref.<locals>.<lambda>rr`)�weakrefZWeakValueDictionaryrr]r!)r$Zwdr`rrr�test_handle_weakref�
szHandleTests.test_handle_weakrefcCsxd|jj_t�td|j�}t�t�\}}|�t	|�d||f�|�
�|�t	|�d�t�t�}t�|d|j�}|�t	|�d||f�t�
tdd�}t�|d	|j�}d
t�|�|f}|�t	|�|�tj
tdd�}t�|d|j�}d
t�|�|f}|�t	|�|�tjdk�rttj}t�|�}t�|�\}}t�|d|j�}d}d|}d|t�|�|f}|�t	|�|�dS)NF)rTrUz<Handle noop(1, 2) at %s:%s>z<Handle cancelled>rz<Handle noop() at %s:%s>rTrU)rRz%^<Handle noop\(1, 2\)\(3\) at %s:%s>$)�x)rUrRz'^<Handle noop\(x=1\)\(2, 3\) at %s:%s>$)rR�z*<function HandleTests.test_handle_repr .*>z%functools.partialmethod\(%s, , \)\(\)z^<Handle %s at %s:%s>$)r!r[r\rr]rYrc�get_function_sourcer|r�r�rjrr�re�escapeZassertRegexrr:rZ�test_handle_repr�
partialmethod)r$r`�filename�linenortZregex�methodZcb_regexrrrrm�
sD





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)NTrT)rTrUz-<Handle noop(1, 2) at %s:%s created at %s:%s>z7<Handle cancelled noop(1, 2) at %s:%s created at %s:%s>)r!r[r\r�r�	_getframe�f_linenorr]rYrcrjr|r�r�)r$�create_filename�
create_linenor`rorprrr�test_handle_repr_debug�
s$

z"HandleTests.test_handle_repr_debugcs|t����}|�d���|��fdd�}|�t�}||�|�t�}||�|�dt�}||�|�dt�}||�dS)NTcsBt�d�jd}��|jt���|jddd�t|df�dS)NrTr�rR�test_handle_source_traceback)rrrrsr�rd�listr|r�)r`rp)r$rr�check_source_traceback�
szHHandleTests.test_handle_source_traceback.<locals>.check_source_tracebackr)	r�get_event_loop_policyrr�rrrYr�ry)r$r!ryr`r)r$rrw�
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#r+rgrZiscoroutiner|rZ_format_coroutiner-�
cr_running�cr_code)r$rBrrr�+test_coroutine_like_object_debug_formatting�
s$z7HandleTests.test_coroutine_like_object_debug_formatting)r+r,r-r`rarergrmrvrwr;r�r�collections�abcr~rErr)rDrrZm
s
1rZcsLeZdZ�fdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	�Z
S)�
TimerTestscst���t��|_dS)N)rBr`rrOr!)r$)rDrrr`#s
zTimerTests.setUpcCs8t��}t�|dd�dt���}|�t|�t|��dS)NcSsdS)NFrrrrrr�)rSz&TimerTests.test_hash.<locals>.<lambda>r)rnrzr�TimerHandlerrOr|�hash)r$�whenr`rrr�	test_hash's
zTimerTests.test_hashcCs4t��}t�|dd�dt���}|�||���dS)NcSsdS)NFrrrrrr�/rSz&TimerTests.test_when.<locals>.<lambda>r)rnrzrr�rrOr|r�)r$r�r`rrr�	test_when-s
zTimerTests.test_whencCs�dd�}d}t��}t�|||t���}|�|j|�|�|j|�|�	|�
��|��|�|�
��|�
|j�|�
|j�|�ttjd|||j�dS)NcWs|S)Nr)r�rrrrx4sz'TimerTests.test_timer.<locals>.callback)rTrUrR)rnrzrr�rrOr�r^r_r�r�r�rgrzrk�AssertionErrorr!)r$rxr�r�r`rrr�
test_timer3s
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\rr�rYrcrjr|r�r�)r$r`�srcrrr�test_timer_reprIs




zTimerTests.test_timer_reprcCs�d|jj_t}t��jd}t�dt	d|j�}t
�t	�\}}|�t
|�d||||f�|��|�t
|�d||||f�dS)NTrTr�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\r�rrrrsrr�rYrcrjr|r�r�)r$rtrur`rorprrr�test_timer_repr_debugWs


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
|�|��dS)NcWs|S)Nr)r�rrrrxmsz2TimerTests.test_timer_comparison.<locals>.callbackrg$@)
rnrzrr�r!r�rgr�r]r��NotImplemented�__eq__�__ne__)r$rxr�Zh1Zh2Zh3rrr�test_timer_comparisonls>z TimerTests.test_timer_comparison)r+r,r-r`r�r�r�r�r�r�rErr)rDrr�!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|�dS)NrT)rrOr�AbstractEventLooprk�NotImplementedErrorr{r rsrhrbr)r�ryr�rrnr�Zset_default_executorr�r�r�r�r�r�Zset_exception_handlerZdefault_exception_handlerrtr[r�)r$r�r!rrr�test_not_implemented�sh






z+AbstractEventLoopTests.test_not_implementedcs,�fdd�}t��}|�|��|��dS)Nc	�s�t��}t��}��t��|�||�IdHWdQRX��t��|�dd�IdHWdQRX��t��|�d�IdHWdQRX��t��|�	|�IdHWdQRX��t��|�
|�IdHWdQRX��t��|�|�IdHWdQRX��t��|�|d�IdHWdQRX��t��|�
|d�IdHWdQRX��t��|�|d�IdHWdQRX��t��|�||�IdHWdQRX��t��|�|�IdHWdQRX��t��|�||�IdHWdQRX��t��|�||�IdHWdQRX��t��|�|tjj�IdHWdQRX��t��|�|tjj�IdHWdQRX��t��|�|tj�IdHWdQRX��t��|�|�IdHWdQRXdS)Nr�i�)r�i�r)rrOrr�rkr�r�r�Zgetnameinfor�rQr�r�r�r�r�r�rr*r��sentinelr�r�r�r�)r�r!)r$rr�inner�sH  z@AbstractEventLoopTests.test_not_implemented_async.<locals>.inner)rrr r))r$r�r!r)r$r�test_not_implemented_async�s'z1AbstractEventLoopTests.test_not_implemented_asyncN)r+r,r-r�r�rrrrr��s6r�c@seZdZdd�ZdS)�ProtocolsAbsTestscCs�t��}t��}|�|�|��|�|�|��|�|�|��|�|���t�	�}|�|�|��|�|�|��|�|�
|��|�|�||��t��}|�|�|��|�|�|��|�|�
d|��|�|�d|��|�|���dS)NrT)rrOrr�rzr9r@r<r>�DatagramProtocolrJrIr�r\r]r^)r$r�r�Zdp�sprrr�
test_empty�s"zProtocolsAbsTests.test_emptyN)r+r,r-r�rrrrr��sr�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��dS)N)
r�AbstractEventLoopPolicyrkr��get_event_looprryrZget_child_watcherrO)r$�policyrrr�test_event_loop_policys
z"PolicyTests.test_event_loop_policycCsXt��}|�|jj�|��}|�|tj�|�|jj|�|�||���|�	�dS)N)
r�DefaultEventLoopPolicyrz�_localZ_loopr�r�r�r�r))r$r�r!rrr�test_get_event_loopszPolicyTests.test_get_event_loopc	CsFt��}tjj|d|jd��}|��}|�|�WdQRX|��dS)Nr)�wraps)	rr�rrryrr�rbr))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�dS)N)rr�rrkrlr�)r$r�rrr�"test_get_event_loop_after_set_none9s
z.PolicyTests.test_get_event_loop_after_set_nonez'asyncio.events.threading.current_threadcs,�fdd�}tj|d�}|��|��dS)Ncst��}��t|j�dS)N)rr�rkrlr�)r�)r$rrr�Asz1PolicyTests.test_get_event_loop_thread.<locals>.f)r�)r�r�r�r�)r$Zm_current_threadr��thr)r$r�test_get_event_loop_thread>sz&PolicyTests.test_get_event_loop_threadcCs*t��}|��}|�|tj�|��dS)N)rr�rr�r�r))r$r�r!rrr�test_new_event_loopIszPolicyTests.test_new_event_loopcCsht��}|��}|�t|jt��|��}|�|�|�||���|�	||���|�
�|�
�dS)N)rr�r�rkr�rryrr��assertIsNotr))r$r�Zold_loopr!rrr�test_set_event_loopPs
zPolicyTests.test_set_event_loopcCs*t��}|�|tj�|�|t���dS)N)rrzr�r�r�)r$r�rrr�test_get_event_loop_policy]sz&PolicyTests.test_get_event_loop_policycCsL|�ttjt��t��}t��}t�|�|�|t���|�||�dS)N)	rkr�r�set_event_loop_policyryrzr�r�r�)r$�
old_policyr�rrr�test_set_event_loop_policybs
z&PolicyTests.test_set_event_loop_policyN)r+r,r-r�r�r�r�rrr�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�|�dS)Nr)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`rr!rrrrMrNrO)r$rP)rDrrr`us&


zGetEventLoopTestsMixin.setUpc	s~z"tjdkrt�d�t���Wd|j��t�d�|j	t
_|jt
_
|jt
_|jt
_|j	t_|jt_
|jt_|jt_XdS)Nr)rrrrOrBrer!r)rr�rr�r�r�r�r�r�r�)r$)rDrrre�s



zGetEventLoopTestsMixin.tearDownrcs0t�d��fdd�}���j�|��d�dS)Nzmultiprocessing.synchronizec�s*tj��}�j�|t�IdH}|��|S)N)�
concurrentZfutures�ProcessPoolExecutorr!r�r"Zshutdown)Zpoolr�)r$rrr��s

zDGetEventLoopTestsMixin.test_get_event_loop_new_process.<locals>.mainr)r�
import_moduler|r!r )r$r�r)r$r�test_get_event_loop_new_process�s

z6GetEventLoopTestsMixin.test_get_event_loop_new_processc	s�Gdd�dt��G�fdd�dtj�}t��}�zt�|��t��������t��WdQRXt�d������t��WdQRX��	t
d����t��d�WdQRX��t�
�d���fdd�}��|��t��������t��WdQRXt�d������t��WdQRXWdt�|��dk	�rN���X��	t
d����t��d�WdQRX��t�
�d�dS)Nc@seZdZdS)zRGetEventLoopTestsMixin.test_get_event_loop_returns_running_loop.<locals>.TestErrorN)r+r,r-rrrr�	TestError�sr�cseZdZ�fdd�ZdS)zOGetEventLoopTestsMixin.test_get_event_loop_returns_running_loop.<locals>.Policycs��dS)Nr)r$)r�rrr��sz^GetEventLoopTestsMixin.test_get_event_loop_returns_running_loop.<locals>.Policy.get_event_loopN)r+r,r-r�r)r�rr�Policy�sr�z
no runningc�s4��t������t������t����dS)N)r�rr�r�r�r)r!r$rrr��szMGetEventLoopTestsMixin.test_get_event_loop_returns_running_loop.<locals>.func)r1rr�rzr�rrkr�rrArlr�r�r�r r))r$r�r�r�r)r�r!r$r�(test_get_event_loop_returns_running_loop�s8





z?GetEventLoopTestsMixin.test_get_event_loop_returns_running_loop)r+r,r-r�r�r�r�r`rerrr�r�rErr)rDrr�ns
r�c@s$eZdZejZejZejZ	ej
ZdS)�TestPyGetEventLoopN)r+r,r-rZ_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)r+r,r-rZ_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�S)Nrr)r�rrr�
rSz*TestServer.test_get_loop.<locals>.<lambda>z0.0.0.0r)
rrr@r)rAr rQr|�get_loopr)r$r!rSr)r�r�
test_get_loop�szTestServer.test_get_loopN)r+r,r-r�rrrrr��sr�c@s$eZdZdd�Zdd�Zdd�ZdS)�TestAbstractServerc	Cs&|�t��t����WdQRXdS)N)rkr�r�AbstractServerr))r$rrrr�
szTestAbstractServer.test_closec	Cs@t��}|�|j�|�t��|�t���	��WdQRXdS)N)
rrr@r)rkr�r rr�r)r$r!rrr�test_wait_closed
sz#TestAbstractServer.test_wait_closedc	Cs&|�t��t����WdQRXdS)N)rkr�rr�r�)r$rrrr�
sz TestAbstractServer.test_get_loopN)r+r,r-r�r�r�rrrrr�	
sr��__main__)LZcollections.abcr�concurrent.futuresr�rr�r�rrkr�r�r	�ImportErrorr�rr r�rnr)r;rrfr�rrrrrrr	Ztest.test_asyncior
rcr�rrr"r#r�r.rAr�rFrKZBaseProtocolrMr�rNr_r�rr
r#ZTestCaserGrIrSrLrrRrVrXrYrZr�r�r�r�r�r�Z_asyncior�r�r�r+r�rrrr�<module>s�

	" )T
5tf[y