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.pyc
B

��gu��@s�dZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZyddlZWne
k
rpdZYnXddlZddlZddlZddlZddlZddlZddlZddlmZddlZejdkr�ddlZddlZddlmZddlmZddlmZddlmZdd	lmZdd
lmZddlm Z!ddl"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/�Z0Gdd �d �Z1Gd!d"�d"�Z2Gd#d$�d$�Z3Gd%d&�d&e3�Z4Gd'd(�d(e3�Z5ejdk�rJGd)d*�d*e1e5e4e!j6�Z7Gd+d,�d,e1e5e4e2e!j6�Z8n�ddl9Z9Gd-d.�d.e1e5e4�Z:e;e9d/��r�Gd0d1�d1e:e2e!j6�Z<e;e9d2��r�Gd3d4�d4e:e2e!j6�Z=e;e9d5��r�Gd6d7�d7e:e2e!j6�Z>Gd8d*�d*e:e2e!j6�Z7d9d:�Z?Gd;d<�d<e!j6�Z@Gd=d>�d>ej6�ZAGd?d@�d@ej6�ZBGdAdB�dBej6�ZCGdCdD�dDej6�ZDGdEdF�dF�ZEGdGdH�dHeEej6�ZFyddlGZGWne
k
�r�YnXGdIdJ�dJeEej6�ZHGdKdL�dLej6�ZIGdMdN�dNej6�ZJeKdOk�r�e�L�dS)PzTests for events.py.�N)�mock�win32)�base_events)�	constants)�
coroutines)�events)�proactor_events)�selector_events)�utils)�supportcCsFtj�d�rdStjdkrdSt��d}ttt|�d���}|dkS)z4Return True if the platform is Mac OS 10.4 or older.ZaixT�darwinFr�.)�
�)�sys�platform�
startswithZmac_ver�tuple�map�int�split)�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__cCs6||_|jdkst|j��d|_|jr2|j�d�dS)Nr/�	CONNECTED)r0r1�AssertionErrorr4�
set_result)r$r0rrr�connection_madeVs
zMyBaseProto.connection_madecCs*|jdkst|j��|jt|�7_dS)Nr7)r1r8r2�len)r$�datarrr�
data_received]szMyBaseProto.data_receivedcCs|jdkst|j��d|_dS)Nr7�EOF)r1r8)r$rrr�eof_receivedaszMyBaseProto.eof_receivedcCs0|jdkst|j��d|_|jr,|j�d�dS)N)r7r>�CLOSED)r1r8r5r9)r$r'rrr�connection_losteszMyBaseProto.connection_lost)N)
r+r,r-r4r5r6r:r=r?rArrrrr.Js
r.cseZdZ�fdd�Z�ZS)�MyProtocst��|�|�d�dS)Ns%GET / HTTP/1.0
Host: example.com

)�superr:�write)r$r0)�	__class__rrr:mszMyProto.connection_made)r+r,r-r:�
__classcell__rr)rErrBlsrBc@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$||_|jdkst|j��d|_dS)Nr/�INITIALIZED)r0r1r8)r$r0rrrr:{szMyDatagramProto.connection_madecCs*|jdkst|j��|jt|�7_dS)NrH)r1r8r2r;)r$r<�addrrrr�datagram_received�sz!MyDatagramProto.datagram_receivedcCs|jdkst|j��dS)NrH)r1r8)r$r'rrr�error_received�szMyDatagramProto.error_receivedcCs0|jdkst|j��d|_|jr,|j�d�dS)NrHr@)r1r8r5r9)r$r'rrrrA�szMyDatagramProto.connection_lost)N)	r+r,r-r5r6r:rJrKrArrrrrGrs
rGc@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,||_|jdgkst|j��|j�d�dS)Nr/r7)r0r1r8�append)r$r0rrrr:�szMyReadPipeProto.connection_madecCs.|jddgkst|j��|jt|�7_dS)Nr/r7)r1r8r2r;)r$r<rrrr=�szMyReadPipeProto.data_receivedcCs(|jddgkst|j��|j�d�dS)Nr/r7r>)r1r8rM)r$rrrr?�szMyReadPipeProto.eof_receivedcCsRd|jkr|j�d�|jdddgks0t|j��|j�d�|jrN|j�d�dS)Nr>r/r7r@)r1rMr8r5r9)r$r'rrrrA�s
zMyReadPipeProto.connection_lost)N)	r+r,r-r5r6r:r=r?rArrrrrL�s
rLc@s*eZdZdZddd�Zdd�Zdd�ZdS)	�MyWritePipeProtoNcCs&d|_d|_|dk	r"tj|d�|_dS)Nr/)r!)r1r0rr3r5)r$r!rrrr6�szMyWritePipeProto.__init__cCs$||_|jdkst|j��d|_dS)Nr/r7)r0r1r8)r$r0rrrr:�sz MyWritePipeProto.connection_madecCs0|jdkst|j��d|_|jr,|j�d�dS)Nr7r@)r1r8r5r9)r$r'rrrrA�sz MyWritePipeProto.connection_lost)N)r+r,r-r5r6r:rArrrrrN�s
rNc@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__cCs0||_|jdkst|j��d|_|j�d�dS)Nr/r7)r0r1r8r4r9)r$r0rrrr:�sz$MySubprocessProtocol.connection_madecCs*|jdkst|j��d|_|j�d�dS)Nr7r@)r1r8rWr9)r$r'rrrrA�sz$MySubprocessProtocol.connection_lostcCs8|jdkst|j��|j||7<|j|��dS)Nr7)r1r8r<r[�set)r$rQr<rrr�pipe_data_received�sz'MySubprocessProtocol.pipe_data_receivedcCs>|jdkst|j��|r*|j|�|�n|j|�|�dS)Nr7)r1r8rYZ
set_exceptionr9)r$rQr'rrr�pipe_connection_lost�sz)MySubprocessProtocol.pipe_connection_lostcCs$|jdkst|j��|j��|_dS)Nr7)r1r8r0Zget_returncoderZ)r$rrr�process_exited�sz#MySubprocessProtocol.process_exitedN)	r+r,r-r6r:rAr]r^r_rrrrrO�srOcsPeZdZ�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)rC�setUp�create_event_loopr!r)r$)rErrra�s

zEventLoopTestsMixin.setUpcs4|j��st�|j�|��t��t���dS)N)	r!�	is_closed�
test_utils�run_brieflyZ
doCleanupsrZ
gc_collectrC�tearDown)r$)rErrrf�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)rgr$rr�coro2szBEventLoopTestsMixin.test_run_until_complete_nesting.<locals>.coro2)r�	coroutine�assertRaises�RuntimeErrorr!r )r$rjr)rgr$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�sleeprh)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!�stoprrpr)r$rr�cbs
z?EventLoopTestsMixin.test_run_until_complete_stopped.<locals>.cb)rlrmr!r )r$ruZtaskr)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)rMr!rt)�arg)�resultsr$rr�callbacks
z5EventLoopTestsMixin.test_call_later.<locals>.callbackg�������?zhello worldg{�G�z�?g�������?)r!�
call_laterro�	monotonic�run_forever�assertEqualrh)r$ryrqrrr)rxr$r�test_call_laters
z#EventLoopTestsMixin.test_call_latercs>g���fdd�}�j�|dd��j�����dg�dS)Ncs��||f��j��dS)N)rMr!rt)Zarg1Zarg2)rxr$rrry,sz4EventLoopTestsMixin.test_call_soon.<locals>.callbackr�world)rr)r!�	call_soonr|r})r$ryr)rxr$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)NrV)rMr;r!rt)rw)rxr$rrry8s
z?EventLoopTestsMixin.test_call_soon_threadsafe.<locals>.callbackcs�j��d����dS)Nr)r!�call_soon_threadsafe�releaser)ry�lockr$rr�
run_in_thread=szDEventLoopTestsMixin.test_call_soon_threadsafe.<locals>.run_in_thread)�targetrr)
�	threadingZLock�acquire�Thread�startr!r�r|�joinr})r$r��tr)ryr�rxr$r�test_call_soon_threadsafe4sz-EventLoopTestsMixin.test_call_soon_threadsafecsLg���fdd�}�j�|d��j�|d��j�����ddg�dS)Ncs$��|�t��dkr �j��dS)NrV)rMr;r!rt)rw)rxr$rrryNs
zKEventLoopTestsMixin.test_call_soon_threadsafe_same_thread.<locals>.callbackrr)r!r�r�r|r})r$ryr)rxr$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)rwrrr�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�������?)rorprrrrr�gsz<EventLoopTestsMixin.test_run_in_executor_cancel.<locals>.rung�������?)	r!r��cancelr)r�r�rorp�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�extendrhr!�
remove_reader�filenor))r<)�
bytes_read�rr$rr�readerwsz8EventLoopTestsMixin.test_reader_callback.<locals>.readersabccst��dkS)NrS)r;r)r�rr�<lambda>�rTz:EventLoopTestsMixin.test_reader_callback.<locals>.<lambda>sdefcst��dkS)N�)r;r)r�rrr��rTsabcdef)�socket�
socketpair�setblocking�	bytearrayr!�
add_readerr�r�r&rd�	run_untilr)rtr|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!rt)r<)r$r�rr�writer�s
z8EventLoopTestsMixin.test_writer_callback.<locals>.writersxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxrV)r�r�r�r!�
add_writerr�r|rh�
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�rl�
ValueErrorr �sock_connect�address�sock_sendall�	sock_recv�sock_recv_intor��sock_acceptr)rhr)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)rhr)r$r�r�r<�bufr2rrr�_basetest_sock_recv_into�s

"z,EventLoopTestsMixin._basetest_sock_recv_intoc	Cs@t���.}t��}|�||�t��}|�||�WdQRXdS)N)rd�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)rd�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�rl�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.1rrUr)
r�r�r��listen�connectr�r!r�r r}Z
gettimeoutZgetpeernamer))r$Zlistener�client�f�connrIrrr�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)NrUrr)�caughtrr�
my_handlersz?EventLoopTestsMixin.test_add_signal_handler.<locals>.my_handlerZboomrU���cs�S)Nrr)r�rrr�+rTz=EventLoopTestsMixin.test_add_signal_handler.<locals>.<lambda>)rl�	TypeErrorr!�add_signal_handler�remove_signal_handlerr��signal�NSIGrmr�r��SIGINT�os�kill�getpidrdr�rhr}�	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)NrU)r!rtr)r�r$rrr�9szLEventLoopTestsMixin.test_signal_handling_while_selecting.<locals>.my_handlerg{�G�z�?�<rU)
r!r�r�r��	setitimer�ITIMER_REALrzrtr|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)NrU)r}r!rt)r�)r�r$�	some_argsrrr�JszAEventLoopTestsMixin.test_signal_handling_args.<locals>.my_handlerg�������?r�rU)
r!r�r�r�r�r�rzrtr|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!)rBr!r)r$rrr�erTz<EventLoopTestsMixin.test_create_connection.<locals>.<lambda>)rdr�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!)rBr!r)r$rrr�prTzAEventLoopTestsMixin.test_create_unix_connection.<locals>.<lambda>)rrdr�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��}xf|D]R\}}}}}y4tj|||d�}|�d��j��j�	||��WnYq2XPq2Wds�t
d���jj�fdd�|d�}	�j�|	�\}
}��|
t
j���|t
j��j�|j���|jd�|
��WdQRXdS)	N�type)�familyr��protoFzCan not create socket.cst�jd�S)N)r!)rBr!r)r$rrr��rTzAEventLoopTestsMixin.test_create_connection_sock.<locals>.<lambda>)r�r)rdr�r!r �getaddrinfor�r��SOCK_STREAMr�r�r8r�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�cipherrSrrUrVZ
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�rhrEr+�lowerr	r5r�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)z�
                A ssl.create_default_context() replacement that doesn't enable
                cert validation.
                )r}r
r
�SERVER_AUTHrd�dummy_ssl_context)Zpurposerrr)r$rr�_dummy_ssl_create_context�szREventLoopTestsMixin._test_create_ssl_connection.<locals>._dummy_ssl_create_contextzssl.create_default_context)�side_effectTrUZCERTIFICATE_VERIFY_FAILED)rdrr�hasattrr
r
rr�patchr}Z
call_countrl�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!)rBr!r)r$rrr��rTz@EventLoopTestsMixin.test_create_ssl_connection.<locals>.<lambda>)r)rdr��	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!)rBr!r)r$rrr��rTzEEventLoopTestsMixin.test_create_ssl_unix_connection.<locals>.<lambda>z	127.0.0.1)�server_hostname)r)	rrdr�rr r!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!)rBr!r)r$rrr��rTzGEventLoopTestsMixin.test_create_connection_local_addr.<locals>.<lambda>�
local_addrrr�rU)rdr�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!)rBr!r)r$rrr�	rTzNEventLoopTestsMixin.test_create_connection_local_addr_in_use.<locals>.<lambda>r$)rdr�r!r�r�rl�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)rCrAr�rt)r$r')rEr!rrrAszQEventLoopTestsMixin.test_connect_accepted_socket.<locals>.MyProto.connection_lostcst��|�|j���dS)N)rCr=r0rD)r$r<)rE�expected_responserrr=szOEventLoopTestsMixin.test_connect_accepted_socket.<locals>.MyProto.data_received)r+r,r-rAr=rFr)r/r!)rErrBsrB)z	127.0.0.1rrUs	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')rI�
client_ssl�message�responserrr�&s



z@EventLoopTestsMixin.test_connect_accepted_socket.<locals>.clientT)r�Zdaemon)r!cs�S)Nrr)r�rrr�=rTzBEventLoopTestsMixin.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_sslr4rBZlsockr�Zthreadr��_r)rIr4r/r!r5r�r6r�test_connect_accepted_sockets4




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

z4EventLoopTestsMixin.test_ssl_connect_accepted_socketc	CsNt��}|�|j�|jjt|dd�}|�td��|j�|�WdQRXdS)NrU)Zssl_handshake_timeoutz1ssl_handshake_timeout is only meaningful with ssl)	r��
addCleanupr)r!r8rB�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)rPrGrrr�
<listcomp>qszDEventLoopTestsMixin.create_server_multiple_hosts.<locals>.<listcomp>cSsg|]}|dddf�qS)rLrr)rPrGrrrrMtscs
t�j�S)N)rBr!r)r$rrr�xrTzBEventLoopTestsMixin.create_server_multiple_hosts.<locals>.<lambda>rLcSsh|]}|��d�qS)r)�
getsockbyname)rPr�rrr�	<setcomp>{szCEventLoopTestsMixin.create_server_multiple_hosts.<locals>.<setcomp>)rrkr\r�rFrNrr!r�r�MockZ_start_serving�
_stop_serving�
create_serverr rAr)�socketsr})	r$r�ZhostsZ	mock_sockrKZ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)rUr�rF)r$rrr�&test_create_server_multiple_hosts_ipv4~sz:EventLoopTestsMixin.test_create_server_multiple_hosts_ipv4cCs|�tjdddg�dS)Nz::1z::2)rUr��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��rTz8EventLoopTestsMixin.test_create_server.<locals>.<lambda>z0.0.0.0rrUz	127.0.0.1sxxxr7cs
�jdkS)Nr)r2r)r�rrr��rTrSr�rr@)rBr!rRr r}r;rSr�r�r�r1r4r1rdr�r2r�r0r�r)r5)r$r�rTr�rGr&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��rTzCEventLoopTestsMixin.test_create_server_reuse_port.<locals>.<lambda>z0.0.0.0rrUcs�S)Nrr)r�rrr��rTT)Z
reuse_port)rBr!rRr r}r;rSr�Z
getsockoptr��
SOL_SOCKETrZr)rdrerh)r$r�rTr�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��rTz7EventLoopTestsMixin._make_unix_server.<locals>.<lambda>)rdZgen_unix_socket_pathrAr!�create_unix_serverr )r$�factory�kwargsr�rTr)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��rTz=EventLoopTestsMixin.test_create_unix_server.<locals>.<lambda>rUsxxxr7cs
�jdkS)Nr)r2r)r�rrr��rTrSr@)rBr!rcr}r;rSr�r�r�r1r r4r1rdr�r2r0r)r5)r$rTr]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��rTzOEventLoopTestsMixin.test_create_unix_server_path_socket_error.<locals>.<lambda>z/test)r�z3path and sock can not be specified at the same time)rBr!r�r`rBr�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
)rlr!rRr rSr�r})
r$rarirjrkr�rTr�rGr&rrr�_make_ssl_server�s
z$EventLoopTestsMixin._make_ssl_servercCs|�||�}|j||d�S)N)r
)rlrc)r$rarirjrkrrr�_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�
rTz<EventLoopTestsMixin.test_create_server_ssl.<locals>.<lambda>)r
sxxxr7cs
�jdkS)Nr)r2r)r�rrr�rTrS)rr@)rBr!rmrd�ONLYCERT�ONLYKEYr�r.rr rDr4r}r1r�r2r	r0r)r5)r$rTrGr&�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�.rTzAEventLoopTestsMixin.test_create_unix_server_ssl.<locals>.<lambda>rE)r
r"sxxxr7cs
�jdkS)Nr)r2r)r�rrr�9rTrSr@)rBr!rnrdrorpr�r.rr rDr4r}r1r�r2r0r)r5)r$rTr]rqr�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�LrTzJEventLoopTestsMixin.test_create_server_ssl_verify_failed.<locals>.<lambda>�check_hostnameT)r
�call_exception_handlerz(?i)certificate.verify.failed)rBr!rmrd�SIGNED_CERTFILEr
rf�PROTOCOL_TLS_CLIENTrgrh�
CERT_REQUIRED�verify_moderrtr�rr�objectrrBrr re�assertIsNoner0r))r$rTrGr&�sslcontext_clientrqr)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�jrTzOEventLoopTestsMixin.test_create_unix_server_ssl_verify_failed.<locals>.<lambda>rtTZinvalid)r
r"ruz(?i)certificate.verify.failed)rBr!rnrdrvr
rfrwrgrhrxryrrtr�rrrzrrBrr rer{r0r))r$rTr]r|rqr)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��rTzIEventLoopTestsMixin.test_create_server_ssl_match_failed.<locals>.<lambda>)rrtT)r
ruz=IP address mismatch, certificate is not valid for '127.0.0.1')rBr!rmrdrvr
rfrwrgrhrxry�load_verify_locations�
SIGNING_CArrtr�rrrzrrBZCertificateErrorr r{r0r))r$rTrGr&r|rqr)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��rTzJEventLoopTestsMixin.test_create_unix_server_ssl_verified.<locals>.<lambda>)rrtT�	localhost)r
r")rBr!rnrdrvr
rfrwrgrhrxryrr�rrtr�r r0r)r5)r$rTr]r|rqr�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��rTzEEventLoopTestsMixin.test_create_server_ssl_verified.<locals>.<lambda>)rrtTr�)r
r")rr)rBr!rmrdrvr
rfrwrgrhrxryrr�rrtr�r r	ZPEERCERTr0r)r5)r$rTrGr&r|rqr�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)rCr:r9)r$r0)rEr�rrr:�szPEventLoopTestsMixin.test_create_server_sock.<locals>.TestMyProto.connection_made)r+r,r-r:rFr)r�)rEr�TestMyProto�sr�)r�rU)z0.0.0.0r)r�rz0.0.0.0z	127.0.0.1sxxx)rr3r!rBr�r�
setsockoptr[�SO_REUSEADDRr�rRr rSr�r�r}r�r&r))	r$r��sock_obr�rTr�rGr&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�rU)z0.0.0.0r)r�r)rGr&)r�rr�r[r�r�r!rRrBr rSr�rlr)r}rr*r+r))r$r�r�rTr�rGr&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)rCr:r9)r$r0)rE�f_protorrr:szVEventLoopTestsMixin.test_create_server_dual_stack.<locals>.TestMyProto.connection_made)r+r,r-r:rFr)r�)rErr�sr�r)rGr&rUrz	127.0.0.1sxxxz::1)rr3r!rBrr%rRr r)r*r+ZassertGreaterEqualr�r�r&r0r)rW)	r$r�Z	try_countr&r�rTZexr�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!rRrBr rSr�r�r�r&r)rlr�)r$r�rTr�rGr&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!)rCr6r!)Z
inner_self)rEr$rrr6?szWEventLoopTestsMixin.test_create_datagram_endpoint.<locals>.TestMyDatagramProto.__init__cs$t��||�|j�d||�dS)Nsresp:)rCrJr0�sendto)r$r<rI)rErrrJBsz`EventLoopTestsMixin.test_create_datagram_endpoint.<locals>.TestMyDatagramProto.datagram_received)r+r,r-r6rJrFr)r$)rEr�TestMyDatagramProto>sr�)z	127.0.0.1r)r$r�rHcst�jd�S)N)r!)rGr!r)r$rrr�QrTzCEventLoopTestsMixin.test_create_datagram_endpoint.<locals>.<lambda>)Zremote_addrsxxxcs�jS)N)r2r)rTrrr�[rTrScs�jS)N)r2r)r�rrr�]rT�r@)rGr!�create_datagram_endpointr r�r�rr�r}r1r�r0r�rdr�r2r�r)r5)r$r�rCZs_transportrGr&r0r)r�r$rTr�test_create_datagram_endpoint=s6


z1EventLoopTestsMixin.test_create_datagram_endpointcs�tjdkr"t�jtj�r"t�d��d}d}�j��jj	|dt
ji��}xZ|D]F\}}}}}y(t
j
|||d�}|�d�|�
|�WnYqLXPqLWds�td���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�FzCan not create socket.cst�jd�S)N)r!)rGr!r)r$rrr��rTzHEventLoopTestsMixin.test_create_datagram_endpoint_sock.<locals>.<lambda>)r�)rrr�r!rr�r<r=r r�r�Z
SOCK_DGRAMr�r�r8r�r�rr�rGr)r5)r$r�Z
local_addressrr�r�r�rr�r�r�r�r)r$r�"test_create_datagram_endpoint_sockks2

z6EventLoopTestsMixin.test_create_datagram_endpoint_sockcCsf|��}t|tj�s&|��|�d�|�d|j�|��|�d|j�|�|j	�|�|j
�dS)Nz#loop is not a BaseSelectorEventLooprUr)rbr�r	ZBaseSelectorEventLoopr)�skipTestr}Z
_internal_fdsr{Z_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��rTzEEventLoopTestsMixin.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)NrU)r2r)r�rrr��rTz4EventLoopTestsMixin.test_read_pipe.<locals>.<lambda>rUs2345cs
�jdkS)Nr)r2r)r�rrr��rTr/r7rr>r@�pipe)rLr!r�r��io�openr rDrdr�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��rTzSEventLoopTestsMixin.test_unclosed_pipe_transport.<locals>.connect.<locals>.<lambda>cs�S)Nrr)�write_protorrr��rT)r��connect_write_pipe)�read_transportr9�write_transport)r!r��rpipeobj�wpipeobjr�rrr��s
zAEventLoopTestsMixin.test_unclosed_pipe_transport.<locals>.connectr�)rbrLrNr�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��rTzKEventLoopTestsMixin.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��rTz:EventLoopTestsMixin.test_read_pty_output.<locals>.<lambda>rUs2345cs
�jdkS)Nr)r2r)r�rrr��rTr/r7rr>r@r�)rLr!r��openptyr�r�r rDrdr�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�rTz5EventLoopTestsMixin.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)NrUrr)r<r�rrr�rTs2345cs���dkS)Nrrr)r<r�rrr�rTs12345r�r@)r�r�r�r�rNr!r�r r�r0r}r1rDr�rdr�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�,rTzIEventLoopTestsMixin.test_write_pipe_disconnect_on_close.<locals>.<lambda>r7r�r@)r�r�r�r�r��detachrNr!r�r r�r0r}r1rDr�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�ErTz4EventLoopTestsMixin.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)NrUrr)r<r�rrr�SrTr)r7s2345cs���dkS)Nrrr)r<r�rrr�XrTs12345r�r@)r�r�r�r�rNr!r�r r�r0r}r1rDr�rdr�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�srTz<EventLoopTestsMixin.test_bidirectional_pty.<locals>.<lambda>r/r7r�cs�S)Nrr)r�rrr�~rTcst��d�}||7}t|�S)Ni)r�r�r;)r<r�)r�rrr��sz:EventLoopTestsMixin.test_bidirectional_pty.<locals>.readerr�cs���dkS)NrUrr)r<r�rrr��rTr)r7�acs
�jdkS)NrU)r2r)r�rrr��rTrUs2345cs���dkS)Nrrr)r<r�rrr��rTs12345sbcdecs
�jdkS)Nr)r2r)r�rrr��rTrr>r@)r�r��dup�ttyZsetrawr�r�rLr!r�r r�r0r}r1r2rNr�r�rDrdr�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)	NFrU�ovc�sRz@y�j��j��IdHWntjk
r8d}YnXd}Wd�j��X|S)N�	cancelled)r!r�r�r�CancelledErrorrt)r�)r�r$rr�main�s
z:EventLoopTestsMixin.test_prompt_cancellation.<locals>.main)r!g�������?r�)r�r�r�r!�create_taskr��getattrrhZpendingror{rrIr|Z
assertLessr}�resultrlr�r�rQr))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)NrU)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!rrp)r!)r$rr�wait�sz7EventLoopTestsMixin.test_timeout_rounding.<locals>.wait�)Zclock_resolutionZselector)	r!r�r�r ZassertLessEqualZ_clock_resolutionZ	_selectorrEr+)r$r�r�r)r�r$r�test_timeout_rounding�sz)EventLoopTestsMixin.test_timeout_roundingcCsx|��}dd�}t��\}}|�|j�|�|j�|�||�|�||�|��|�|�|��|�|�	|��dS)NcSsdS)Nrrrrrr��rTzCEventLoopTestsMixin.test_remove_fds_after_closing.<locals>.<lambda>)
rbr�r�rAr)r�r�r�r�r�)r$r!ryr�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��rTz@EventLoopTestsMixin.test_add_fds_after_closing.<locals>.<lambda>)	rbr�r�rAr)rlrmr�r�)r$r!ryr�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)rrkr!rlrmr )r$r�rCr)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�rTz0EventLoopTestsMixin.test_close.<locals>.<lambda>)r!g�?g)r!r)rrkrArlrmr|r3r r�r�rz�call_atror�r�r��SIGTERMr�r*�next)r$r��funcrC�fut�itrrr�
test_closes2
"zEventLoopTestsMixin.test_close)T)TN)TN)NN)N)N)N)]r+r,r-rarfrnrsrvr~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�rr	rr�skipIfr
r!r#r(r.r:r@rDrrrUrVrXrYr�r\rcrdrerlrmrnrrrsr}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�rFrr)rErr`�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$rZrrr�check_terminated6s
z%SubprocessTestsMixin.check_terminatedcCs,tjdkr|�|t�n|�tj|�dS)Nr)rrr�rr}r�r�)r$rZrrr�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 WinnerrU)r�r]r��dirname�__file__r!�subprocess_execrr rOr�
executabler r�r4r}r1�get_pipe_transportrDr[r�rdrr)rWr�rZr<)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 rUs
The WinnersPython The Winner)r�r]r�r�r�r!r�rr rOrr�r r�r4r}r1r�rDr[r��clearr<rdrr)rWr�rZ)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)rPr�rrr�	<genexpr>}sz=SubprocessTestsMixin.test_subprocess_shell.<locals>.<genexpr>rUs
sPythonrVrT)r!�subprocess_shellrr rOr r�r4r�r)rWr}rZrh�allrY�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�rr rOr r�rWr}rZr))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�rrUrVr�)
r!r�rr rOr r�r{r�rWr}rZr))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�rr rOrr�r r�r4r�rWr�rZr))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�rr rOrr�r r�r4Z	terminaterWr�rZr))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�rr rOrr�r r�r4Zsend_signalrWr}rZr))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:testrUrVsERR:test)r�r]r�r�r�r!r�rr rOrr�r r�r4r�rDrWr)r}r<rhrrZ)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�rrUrVstestsOUT:testERR:testrT)r�r]r�r�r�r!r�rr rOrr��
subprocessZSTDOUTr r�r4r�r�r{rDrWrhr<rr}r)rZ)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.pyrrUstestsOUT:testsxxxrVrsERR:BrokenPipeErrorsERR:OSError)r�r]r�r�r�r!r�rr rOrr�r r�r4r�rDr[r�r}r<r)rYrrdrrWr�rZ)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�rr rOr r�rWr}rZ)r$r�r9r�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)rJ)r$rrr�'szGSubprocessTestsMixin.test_subprocess_exec_invalid_args.<locals>.connectT)�universal_newlinesi)�bufsize)�shell)rlr�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�)�cmdrJ)r$rrr�5s
zHSubprocessTestsMixin.test_subprocess_shell_invalid_args.<locals>.connectZlsz-lT)r�i)r�F)r�)N)rlr�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�rrrrrrr�4s 

!r�csPeZdZddZdZe�fdd��Ze�fdd��Z�fdd	�Zd
d�Z	�Z
S)�SendfileBasesSendfileBaseDatai ic	s2ttjd��}|�|j�WdQRXt���dS)Nr�)r�r�TESTFNrD�DATArC�
setUpClass)�cls�fp)rErrrNszSendfileBase.setUpClasscst�tj�t���dS)N)rr_rrC�
tearDownClass)r)rErrr	TszSendfileBase.tearDownClasscs*ttjd�|_|�|jj�t���dS)Nr�)r�rr�filerAr)rCra)r$)rErrraYszSendfileBase.setUpcCs|j�|�S)N)r!r )r$rCrrr�run_loop^szSendfileBase.run_loop)r+r,r-r�BUF_SIZE�classmethodrr	rarrFrr)rErrFs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$r0rrrr:msz)SockSendfileMixin.MyProto.connection_madecCs|j�|�dS)N)r<r�)r$r<rrrr=qsz'SockSendfileMixin.MyProto.data_receivedcCsd|_|j�d�dS)NT)rr�r9)r$r'rrrrAtsz)SockSendfileMixin.MyProto.connection_lostc�s|jIdHdS)N)r�)r$rrr�wait_closedxsz%SockSendfileMixin.MyProto.wait_closedN)r+r,r-r6r:r=rArrrrrrBds
rBcstj|_dt_t���dS)Ni@)r�!SENDFILE_FALLBACK_READBUFFER_SIZE�_SockSendfileMixin__old_bufsizerCr)r)rErrr{szSockSendfileMixin.setUpClasscs|jt_t���dS)N)rrrrCr	)r)rErrr	�szSockSendfileMixin.tearDownClassTcCs.t�tjtj�}|�d�|r*|�|j�|S)NF)r�rFrr�rAr))r$�cleanupr�rrr�make_socket�s

zSockSendfileMixin.make_socketcCs|�tjtj|j�dS)N)r�r�r[Z	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�r[Z	SO_SNDBUFrZset_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��rTz8SockSendfileMixin.prepare_socksendfile.<locals>.<lambda>)r�z	127.0.0.1cs<�jdk	r"�j�����������������dS)N)r0r)rrr)r�r$rTrrr�s


z7SockSendfileMixin.prepare_socksendfile.<locals>.cleanup)
rBr!rr%rr��HOSTrrRrr�rrA)r$r&�srv_sockr�rr)r�r$rTr�prepare_socksendfile�s




z&SockSendfileMixin.prepare_socksendfilecCsv|��\}}|�|j�||j��}|��|�|���|�|t|j	��|�|j
|j	�|�|j��t|j	��dS)N)rrr!�
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�)rrr!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
TemporaryFilerr!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)
rrr!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�rBr
rr	rrrrrr r"r#rFrr)rErrbs



rc@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)rCr6r�r<�close_after)r$r!r%)rErrr6�sz&SendfileMixin.MySendfileProto.__init__cs8|j�|�t��|�|jr4|j|jkr4|j��dS)N)r<r�rCr=r%r2r0r))r$r<)rErrr=�sz+SendfileMixin.MySendfileProto.data_received)Nr)r+r,r-r6r=rFrr)rEr�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�	rTz0SendfileMixin.prepare_sendfile.<locals>.<lambda>)r�r
)r!cs�S)Nrr)�	cli_protorrr�	rT)r�r
r")r0csF�j���j�����j����j����������dS)N)r0r)rr5rr)r)r$rTr(rrr	s

z/SendfileMixin.prepare_sendfile.<locals>.cleanup)rr%r&r!r
r�rdr>r?r�rFrr�rrrRrr�r�rrA)r$r'r%r&Zsrv_ctxZcli_ctxrr"Zcli_sockr�r�rr)r)r$rTr(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!)rGr!r)r$rrr�'	rTz;SendfileMixin.test_sendfile_not_supported.<locals>.<lambda>)r�z
not supportedr)rr!r�r�rFrBrm�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*rr!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/rr+r0r
r)r5r}r;rr2r<r)r$r(r)r2rr)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
r0r1)r$rrr2V	szMSendfileMixin.test_sendfile_force_unsupported_native.<locals>.sendfile_nativez
not supportedF)�fallbackr)rrr�r!r�ProactorEventLoopr�r*r/rBrZSendfileNotAvailableErrorrr+r0r
r)r5r}r2r)r$r(r)r2r)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*rr!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)rBrmrr!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*r0rDrr!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*r0rDrr!r+r
r)r5r}r;rr<r)r$r(r)r9r:rrrr�#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*rr!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*rr!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;rrr!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;rrr!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*rl�ConnectionErrorrr!r+r0r
r5rhr2r;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
r0r1)r$rrr2�	szcSendfileMixin.test_sendfile_fallback_close_peer_in_the_middle_of_receiving.<locals>.sendfile_nativei)r%)r!r/r*rlrBrr+r0r
r5rhr2r;rr)r$r2r(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)r9r!r+r0r
r)r)r�r$rrrC�	s
z=SendfileMixin.test_sendfile_prevents_bare_write.<locals>.corozsendfile is in progresssdata)r*r!rr�rrBrmr0rDr}r;r)r$r(rCr�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��	rTzPSendfileMixin.test_sendfile_no_fallback_for_fallback_transport.<locals>.<lambda>zfallback is disabledF)r4)
rrPrCrrZ
_SendfileModeZFALLBACKZ_sendfile_compatiblerBrmr!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-r3r6r7r8r;r<r>r?r@rArDrErr�rFrGrrrrr$�s&+	
r$c@seZdZdd�ZdS)�SelectEventLoopTestscCst��S)N)r�SelectorEventLoop)r$rrrrb
sz&SelectEventLoopTests.create_event_loopN)r+r,r-rbrrrrrH
srHc@sDeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)�ProactorEventLoopTestscCst��S)N)rr5)r$rrrrb
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-rbr�rKr�rLr�r�rrrrrJ
srJcs(eZdZ�fdd�Z�fdd�Z�ZS)�UnixEventLoopTestsMixincs,t���t��}|�|j�t�|�dS)N)rCrar�SafeChildWatcher�attach_loopr!�set_child_watcher)r$�watcher)rErrra,
s
zUnixEventLoopTestsMixin.setUpcst�d�t���dS)N)rrPrCrf)r$)rErrrf2
s
z UnixEventLoopTestsMixin.tearDown)r+r,r-rarfrFrr)rErrM)
srM�KqueueSelectorcs\eZdZdd�Ze�dd�e�ej	�
d�d��fdd���Ze�dd��fd	d
��Z�Z
S)�KqueueEventLoopTestscCst�t���S)N)rrI�	selectorsrR)r$rrrrb<
sz&KqueueEventLoopTests.create_event_loopr�	Zopenbsdztest hangs on OpenBSDcst���dS)N)rCr�)r$)rErrr�B
sz)KqueueEventLoopTests.test_read_pty_outputcst���dS)N)rCr�)r$)rErrr�L
sz#KqueueEventLoopTests.test_write_pty)r+r,r-rbrr�r<r�rrrr�r�rFrr)rErrS8
s

rS�
EpollSelectorc@seZdZdd�ZdS)�EPollEventLoopTestscCst�t���S)N)rrIrTrV)r$rrrrbU
sz%EPollEventLoopTests.create_event_loopN)r+r,r-rbrrrrrWQ
srW�PollSelectorc@seZdZdd�ZdS)�PollEventLoopTestscCst�t���S)N)rrIrTrX)r$rrrrb]
sz$PollEventLoopTests.create_event_loopN)r+r,r-rbrrrrrYY
srYc@seZdZdd�ZdS)rHcCst�t���S)N)rrIrTZSelectSelector)r$rrrrbe
sz&SelectEventLoopTests.create_event_loopN)r+r,r-rbrrrrrHa
scOsdS)Nr)r�rbrrr�noopi
srZcsheZdZ�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)rCrarrPr!�	get_debug�return_value)r$)rErrrao
s

zHandleTests.setUpcCs`dd�}d}t�|||j�}|�|j|�|�|j|�|�|���|��|�	|���dS)NcWs|S)Nr)r�rrrryu
sz)HandleTests.test_handle.<locals>.callbackr)
r�Handler!r��	_callback�_argsr�r�r�rh)r$ryr��hrrr�test_handlet
szHandleTests.test_handlecCs\dd�}t��|_t��|j_t�|d|j�}|��|jj�t�	d�tj
||jd��dS)NcSs
t��dS)N)r�rrrrry�
sz:HandleTests.test_callback_with_exception.<locals>.callbackrzException in callback.*)r5rZhandleZsource_traceback)rrPr!rurr^Z_run�assert_called_withrdZMockPattern�ANY�_source_traceback)r$ryrarrr�test_callback_with_exception�
s
z(HandleTests.test_callback_with_exceptioncCs(t��}t�dd�d|j�}||d<dS)NcSsdS)Nrrrrrr��
rTz1HandleTests.test_handle_weakref.<locals>.<lambda>rra)�weakrefZWeakValueDictionaryrr^r!)r$Zwdrarrr�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)rUrVz<Handle noop(1, 2) at %s:%s>z<Handle cancelled>rz<Handle noop() at %s:%s>rUrV)rSz%^<Handle noop\(1, 2\)\(3\) at %s:%s>$)�x)rVrSz'^<Handle noop\(x=1\)\(2, 3\) at %s:%s>$)rS�z*<function HandleTests.test_handle_repr .*>z%functools.partialmethod\(%s, , \)\(\)z^<Handle %s at %s:%s>$)r!r\r]rr^rZrd�get_function_sourcer}r�r�rkrr �re�escapeZassertRegexrr;r[�test_handle_repr�
partialmethod)r$ra�filename�linenoruZregex�methodZcb_regexrrrrn�
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)NTrU)rUrVz-<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^rZrdrkr}r�r�)r$�create_filename�
create_linenorarprqrrr�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)NrUr�rS�test_handle_source_traceback)rrsrtr�re�listr}r�)rarq)r$rr�check_source_traceback�
szHHandleTests.test_handle_source_traceback.<locals>.check_source_tracebackr)	r�get_event_loop_policyrr�rr�rZr�rz)r$r!rzrar)r$rrx�
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+rhrZiscoroutiner}rZ_format_coroutiner-�
cr_running�cr_code)r$rCrrr�+test_coroutine_like_object_debug_formatting�
s$z7HandleTests.test_coroutine_like_object_debug_formatting)r+r,r-rarbrfrhrnrwrxr<r�r�collections�abcrrFrr)rErr[m
s
1r[csLeZdZ�fdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	�Z
S)�
TimerTestscst���t��|_dS)N)rCrarrPr!)r$)rErrra#s
zTimerTests.setUpcCs8t��}t�|dd�dt���}|�t|�t|��dS)NcSsdS)NFrrrrrr�)rTz&TimerTests.test_hash.<locals>.<lambda>r)ror{r�TimerHandlerrPr}�hash)r$�whenrarrr�	test_hash's
zTimerTests.test_hashcCs4t��}t�|dd�dt���}|�||���dS)NcSsdS)NFrrrrrr�/rTz&TimerTests.test_when.<locals>.<lambda>r)ror{rr�rrPr}r�)r$r�rarrr�	test_when-s
zTimerTests.test_whencCs�dd�}d}t��}t�|||t���}|�|j|�|�|j|�|�	|�
��|��|�|�
��|�
|j�|�
|j�|�ttjd|||j�dS)NcWs|S)Nr)r�rrrry4sz'TimerTests.test_timer.<locals>.callback)rUrVrS)ror{rr�rrPr�r_r`r�r�r�rhr{rlr8r!)r$ryr�r�rarrr�
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�rZrdrkr}r�r�)r$ra�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)NTrUr�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�rrsrtrr�rZrdrkr}r�r�)r$rurvrarprqrrr�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�rrrrymsz2TimerTests.test_timer_comparison.<locals>.callbackrg$@)
ror{rr�r!r�rhr�r^r��NotImplemented�__eq__�__ne__)r$ryr�Zh1Zh2Zh3rrr�test_timer_comparisonls>z TimerTests.test_timer_comparison)r+r,r-rar�r�r�r�r�r�rFrr)rErr�!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)NrU)rrPr�AbstractEventLooprl�NotImplementedErrorr|r rtrircr)r�rzr�r�ror�Zset_default_executorr�r�r�r�r�r�Zset_exception_handlerZdefault_exception_handlerrur\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)rrPrr�rlr�r�r�Zgetnameinfor�rRr�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)NrU)rrPrr�r{r:rAr=r?�DatagramProtocolrKrJr�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�AbstractEventLoopPolicyrlr��get_event_looprrzrZget_child_watcherrP)r$�policyrrr�test_event_loop_policys
z"PolicyTests.test_event_loop_policycCsXt��}|�|jj�|��}|�|tj�|�|jj|�|�||���|�	�dS)N)
r�DefaultEventLoopPolicyr{�_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�rrrzrr�rcr))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�rrlrmr�)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�rlrmr�)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�rlr8rrzrr��assertIsNotr))r$r�Zold_loopr!rrr�test_set_event_loopPs
zPolicyTests.test_set_event_loopcCs*t��}|�|tj�|�|t���dS)N)rr{r�r�r�)r$r�rrr�test_get_event_loop_policy]sz&PolicyTests.test_get_event_loop_policycCsL|�ttjt��t��}t��}t�|�|�|t���|�||�dS)N)	rlr8r�set_event_loop_policyrzr{r�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_implrrCrarr!rrrrNrOrP)r$rQ)rErrrau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)rrrrPrCrfr!r)rr�rr�r�r�r�r�r�r�)r$)rErrrf�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)r2rr�r{r�rrlr�rrBrmr�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�rarfrrr�r�rFrr)rErr�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�
rTz*TestServer.test_get_loop.<locals>.<lambda>z0.0.0.0r)
rrrAr)rBr rRr}�get_loopr)r$r!rTr)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)rlr�r�AbstractServerr))r$rrrr�
szTestAbstractServer.test_closec	Cs@t��}|�|j�|�t��|�t���	��WdQRXdS)N)
rrrAr)rlr�r rr�r)r$r!rrr�test_wait_closed
sz#TestAbstractServer.test_wait_closedc	Cs&|�t��t����WdQRXdS)N)rlr�rr�r�)r$rrrr�
sz TestAbstractServer.test_get_loopN)r+r,r-r�r�r�rrrrr�	
sr��__main__)M�__doc__Zcollections.abcr��concurrent.futuresr�rr�r�rrlr�r�r
�ImportErrorr�rr!r�ror*r<rrgr�rrrrrrr	Ztest.test_asyncior
rdr�rrr"r#r�r.rBr�rGrLZBaseProtocolrNr�rOr`r�rrr$ZTestCaserHrJrTrMrrSrWrYrZr[r�r�r�r�r�r�Z_asyncior�r�r�r+r�rrrr�<module>s�

	" )T
5tf[y