HEX
Server: LiteSpeed
System: Linux server.nevid-deploma.com 4.18.0-553.111.1.lve.el8.x86_64 #1 SMP Fri Mar 13 13:42:17 UTC 2026 x86_64
User: smilepac (1037)
PHP: 8.1.34
Disabled: NONE
Upload Files
File: //opt/cppython/lib/python3.8/test/test_asyncio/__pycache__/test_base_events.cpython-38.pyc
U

/D�g�8�@sjdZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddl
mZddlZddlm
Z
ddlmZddlmZddlmZddlmZejZejd	kZd
d�Zdd
�Zdd�ZGdd�dej�ZGdd�dej�ZGdd�dej �Z!Gdd�dej"�Z#Gdd�dej�Z$Gdd�de
j�Z%Gdd�dej�Z&Gdd�dej�Z'e(d k�rfe
�)�dS)!zTests for base_events.py�N)�mock)�base_events)�	constants)�utils)�support)�assert_python_ok)��cCst�d�dS�N)�asyncioZset_event_loop_policy�rr�A/opt/cppython/lib/python3.8/test/test_asyncio/test_base_events.py�tearDownModulesrcCs`tjtd�}dD],}tt|�r2t||tt|��qt||�qt��|_t��|j_	d|j
_|S)N)�spec)
�AF_INET�AF_INET6�	AF_UNSPEC�IPPROTO_TCP�IPPROTO_UDP�SOCK_STREAM�
SOCK_DGRAM�
SOL_SOCKET�SO_REUSEADDR�	inet_ptonF)rZ	MagicMock�socket�hasattr�setattr�getattr�delattr�
test_utilsZmock_nonblocking_socket�return_value�getaddrinfo�
_is_coroutine)�m_socket�namerrr
�mock_socket_modules

r%cCstjdtd�|�S)Nzasyncio.base_events.socket)Znew_callable)r�patchr%)�frrr
�patch_socket0s
��r(c@s(eZdZdd�Zdd�Zedd��ZdS)�BaseEventTestsc
Cs�tj}tj}tj}tj}tj}tj}tj}|�|||ddft	�
dd|||��|�|||ddft	�
dd|||��|�|||ddft	�
dd|||��|�|||ddft	�
dd|||��|�|||ddft	�
dd||d��|�|||ddft	�
dd||d��|�t	�
dd|dd��tj
�r�|�t	�
dd|||��|�|||ddft	�
dd|||��|�|||ddft	�
dd|||��|�t	�
dd|||��|�t	�
d	d|||��dS)
N���1.2.3.4�r,r-s1.2.3.4r)�::3r-rrr.z::3%lo0)rrrrrrrr�assertEqualr�_ipaddr_info�assertIsNoner�IPV6_ENABLED)�selfZUNSPEC�INETZINET6�STREAMZDGRAM�TCPZUDPrrr
�test_ipaddr_info7sh������������zBaseEventTests.test_ipaddr_infoc
Cs�tj}tj}tj}|�|||ddft�dd|||��|�|||ddft�dd|||��|�|||ddft�dd|||��|�|||ddft�dd|||��|�|||ddft�dd|||��dS)Nr*�r,rr,�r+�1�1)rrrrr/rr0)r3r4r5r6rrr
�test_port_parameter_typesss.�����z(BaseEventTests.test_port_parameter_typesc	Cs&|`|�t�ddtjtjtj��dS)Nr,r-)rr1rr0rrrr�r3r#rrr
�test_ipaddr_info_no_inet_pton�s�z,BaseEventTests.test_ipaddr_info_no_inet_ptonN)�__name__�
__module__�__qualname__r7r<r(r>rrrr
r)5s<r)csleZdZ�fdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Zd7d8�Zd9d:�Zd;d<�Z d=d>�Z!d?d@�Z"dAdB�Z#dCdD�Z$dEdF�Z%dGdH�Z&dIdJ�Z'dKdL�Z(dMdN�Z)dOdP�Z*dQdR�Z+dSdT�Z,dUdV�Z-�Z.S)W�BaseEventLoopTestscs<t���t��|_t��|j_d|jjj_	|�
|j�dS�Nr)�super�setUpr�
BaseEventLoop�loopr�Mock�	_selector�selectr �set_event_loop�r3��	__class__rr
rE�s


zBaseEventLoopTests.setUpc	Cs�t��}|�t|jj||�|�t|jj||||�|�t|jj||�|�t|jjg�|�t|jj	�|�t|jj
||�|�t|jj||�|j�|||||||�}|�t��|�
d�W5QRXdSr
)rrH�assertRaises�NotImplementedErrorrGZ_make_socket_transport�_make_ssl_transportZ_make_datagram_transport�_process_events�_write_to_selfZ_make_read_pipe_transportZ_make_write_pipe_transportZ_make_subprocess_transport�send)r3�m�genrrr
�test_not_implemented�sZ�������z'BaseEventLoopTests.test_not_implementedcCsn|�|j���|j��|�|j���|j��|j��|j��}|�t|jj�|�t|jj	|�dSr
)
�assertFalserGZ	is_closed�close�
assertTrue�
create_futurerO�RuntimeError�run_forever�run_until_complete)r3r'rrr
�
test_close�s



zBaseEventLoopTests.test_closecCsDt�dd�d|jd�}|j�|�|�|jj�|�||jj�dS)NcSsdS�NFrrrrr
�<lambda>�r9z>BaseEventLoopTests.test__add_callback_handle.<locals>.<lambda>r)r�HandlerG�
_add_callbackrX�
_scheduled�assertIn�_ready�r3�hrrr
�test__add_callback_handle�sz,BaseEventLoopTests.test__add_callback_handlecCsJt�dd�d|jd�}|��|j�|�|�|jj�|�|jj�dS)NcSsdSr`rrrrr
ra�r9zHBaseEventLoopTests.test__add_callback_cancelled_handle.<locals>.<lambda>r)rrbrG�cancelrcrXrdrfrgrrr
�#test__add_callback_cancelled_handle�s
z6BaseEventLoopTests.test__add_callback_cancelled_handlecCs:Gdd�dtjj�}|�}|j�|�|�||jj�dS)Nc@seZdZdd�ZdS)zCBaseEventLoopTests.test_set_default_executor.<locals>.DummyExecutorc_std��dS)Nz#cannot submit into a dummy executor)rP)r3�fn�args�kwargsrrr
�submit�s�zJBaseEventLoopTests.test_set_default_executor.<locals>.DummyExecutor.submitN)r?r@rArorrrr
�
DummyExecutor�srp)�
concurrent�futures�ThreadPoolExecutorrG�set_default_executor�assertIsZ_default_executor)r3rp�executorrrr
�test_set_default_executor�sz,BaseEventLoopTests.test_set_default_executorc	Cs.t��}|�t��|j�|�W5QRXdSr
)rrH�assertWarns�DeprecationWarningrGrt)r3rvrrr
�.test_set_default_executor_deprecation_warnings�szABaseEventLoopTests.test_set_default_executor_deprecation_warningscCsDdd�}|j�|�}|�|j|�|�|tj�|�||jj�dS)NcSsdSr
rrrrr
�cb�sz-BaseEventLoopTests.test_call_soon.<locals>.cb)	rG�	call_soonr/�	_callback�assertIsInstancerrbrerf�r3r{rhrrr
�test_call_soon�s
z!BaseEventLoopTests.test_call_soonc	Cs4|j�d�|�td��|j�d�W5QRXdS)NTza callable objectr-)rG�	set_debug�assertRaisesRegex�	TypeErrorr|rLrrr
�test_call_soon_non_callable�sz.BaseEventLoopTests.test_call_soon_non_callablecCsHdd�}|j�d|�}|�|tj�|�||jj�|�||jj�dS)NcSsdSr
rrrrr
r{�sz.BaseEventLoopTests.test_call_later.<locals>.cb�$@)	rG�
call_laterr~r�TimerHandlererdZassertNotInrfrrrr
�test_call_later�s
z"BaseEventLoopTests.test_call_latercs\g��fdd�}t��|j_|j�d|d�|j�d|d�t�|j�|��ddg�dS)Ncs��|�dSr
)�append)�arg�Zcallsrr
r{�sz>BaseEventLoopTests.test_call_later_negative_delays.<locals>.cb����a����b)rrHrGrRr�r�run_brieflyr/)r3r{rr�r
�test_call_later_negative_delays�sz2BaseEventLoopTests.test_call_later_negative_delayscs~�fdd�}t���j_d}�j��|}�j�||��j��}�j���j��|}��||d|���|d|�dS)Ncs�j��dSr
�rG�stoprrLrr
r{	sz4BaseEventLoopTests.test_time_and_call_at.<locals>.cb皙�����?g�������?g�������?)	rrHrGrR�time�call_atr]ZassertGreaterEqual�assertLessEqual)r3r{�delayZwhen�t0ZdtrrLr
�test_time_and_call_ats

z(BaseEventLoopTests.test_time_and_call_atc	Cs�dd�}|�|�|r�d}|�t|��|�|�W5QRX|�t|��|�d|�W5QRX|�t|��|�|��d|�W5QRXn*|�|�|�d|�|�|��d|�dS)NcSsdSr
rrrrr
r{sz+BaseEventLoopTests.check_thread.<locals>.cbzMNon-thread-safe operation invoked on an event loop other than the current one�<)r�r�r\r|r�r�r�)r3rG�debugr{�msgrrr
�check_threads
 
zBaseEventLoopTests.check_threadcsn�fdd��d�fdd�	}t���j_t���j_|�jd�|�jd�|�jddd�|�jddd�dS)	Nc
s�|��zN|rHt��}zt�|���||�W5t�d�|��Xn��||�Wn0tk
r�}z|�|j	|�W5d}~XYnX|�|j
d�dSr
)�waitrrFrrKrYr��	Exception�call_soon_threadsafe�
set_exception�
set_result)rG�eventr��create_loop�futZloop2�excrLrr
�check_in_thread/s

 z=BaseEventLoopTests.test_check_thread.<locals>.check_in_threadFcsVt��}|��}|�|j�|||||f}tj�|d�}|��|�|�|��dS)N)�targetrm)	�	threading�Eventr[r|�set�Thread�startr^�join)rGr�r�r�r�rm�thread)r�rr
�test_threadCs
z9BaseEventLoopTests.test_check_thread.<locals>.test_threadT)r�)F)rrHrGrRrS)r3r�r)r�r3r
�test_check_thread.s
z$BaseEventLoopTests.test_check_threadcCs�t�t��ddd�d|jd�}t�t��ddd�d|jd�}|��t��|j_|jj	�
|�|jj	�
|�|j��|jjj
jdd}|�d|ko�d	kn|�|�|g|jj	�|�|jjj�dS)
Ng@cSsdS�NTrrrrr
ra^r9z3BaseEventLoopTests.test__run_once.<locals>.<lambda>rr�cSsdSr�rrrrr
ra`r9rg#@g%@)rr�r��	monotonicrGrjrrHrRrdr��	_run_oncerIrJ�	call_argsrZr/�called)r3Zh1Zh2�trrr
�test__run_once]s"��
 z!BaseEventLoopTests.test__run_oncecCs<|j�d�|�|j���|j�d�|�|j���dS)NTF)rGr�rZZ	get_debugrXrLrrr
�test_set_debugosz!BaseEventLoopTests.test_set_debugcs~d�d���fdd�}t�t��d||jf|jd�}t��|j_|jj�	|�|j�
�|���|��gt
|jj��dS)NFcsd�|�dd���dS)NTcSsdSr�rrrrr
ra|r9zOBaseEventLoopTests.test__run_once_schedule_handle.<locals>.cb.<locals>.<lambda>)r|�rG��handleZ	processedrr
r{ysz=BaseEventLoopTests.test__run_once_schedule_handle.<locals>.cbr-)rr�r�r�rGrrHrRrdr�r�rZr/�listrfrrr�r
�test__run_once_schedule_handleus�

z1BaseEventLoopTests.test__run_once_schedule_handlecCs�t��|j_|�dtjko$dkn�dd�}d}|j�d|�d}td�D]}|j�d|�}|�	�qR|d7}td�D]}|j�d	|�}|�	�q~|�
||tj�|�|jj
|�|j��|d8}|�|jj
|�|�t|jj�||�tt�tjtj��d}ttj|d�}||7}t|�D]}|j�d|��q0||7}t|�D]}|j�d|�}|�	��qV|�t|jj�||�|j��|�t|jj�|�|�td
d�|jjD���dS)Nrg�?cSsdSr
rrrrr
r{�szEBaseEventLoopTests.test__run_once_cancelled_event_cleanup.<locals>.cbr-��i�dcSsg|]}|j�qSr)Z
_cancelled)�.0�xrrr
�
<listcomp>�szMBaseEventLoopTests.test__run_once_cancelled_event_cleanup.<locals>.<listcomp>)rrHrGrRrZrZ%_MIN_CANCELLED_TIMER_HANDLES_FRACTIONr��rangerjr�Z_MIN_SCHEDULED_TIMER_HANDLESr/Z_timer_cancelled_countr��lenrd�int�math�ceil�max�all)r3r{Znot_cancelled_countZcancelled_countr�rhZadd_cancel_countZadd_not_cancel_countrrr
�&test__run_once_cancelled_event_cleanup�sd�


�
�������
z9BaseEventLoopTests.test__run_once_cancelled_event_cleanupcCs|�t|jjd�dS)NZblah)rOr�rGr^rLrrr
�"test_run_until_complete_type_error�s�z5BaseEventLoopTests.test_run_until_complete_type_errorcCs2|j��}|��}|�|j�|�t|j|�dSr
)rGr[Z
new_test_loop�
addCleanuprYrO�
ValueErrorr^)r3�taskZ
other_looprrr
�test_run_until_complete_loop�s
�z/BaseEventLoopTests.test_run_until_complete_loopc	svGdd�dt��dd�}�fdd�}t��|j_|j�|�|����|j�|d��W5QRX|j�|d��dS)	Nc@seZdZdS)z]BaseEventLoopTests.test_run_until_complete_loop_orphan_future_close_loop.<locals>.ShowStopperN�r?r@rArrrr
�ShowStopper�sr�c�st�|�IdHdSr
�r�sleep)r�rrr
�foo�szUBaseEventLoopTests.test_run_until_complete_loop_orphan_future_close_loop.<locals>.foocs��dSr
rr�r�rr
�throw�szWBaseEventLoopTests.test_run_until_complete_loop_orphan_future_close_loop.<locals>.throwr�g�������?)�
SystemExitrrHrGrRr|rOr^)r3r�r�rr�r
�5test_run_until_complete_loop_orphan_future_close_loop�szHBaseEventLoopTests.test_run_until_complete_loop_orphan_future_close_loopcCs�tjddg}|�t|jj|jjtj�|�t|jj|jjtj|�|�t|jj|jjtjtjd�|jt|jj|jjtjf|�ddi�|jt|jj|jjtjf|�ddi�|jt|jj|jjtjf|�ddi�dS)	N�-c�pass�{�universal_newlinesT�shell�bufsize�)	�sys�
executablerOr�rGr^Zsubprocess_execr�SubprocessProtocol)r3rmrrr
�!test_subprocess_exec_invalid_args�s\������������z4BaseEventLoopTests.test_subprocess_exec_invalid_argsc	Cs�|�t|jj|jjtjd�|�t|jj|jjtjtjddg�|jt|jj|jjtjddd�|jt|jj|jjtjddd�|jt|jj|jjtjddd	�dS)
Nr�r�r�zexit 0T)r�)r�r�)r�)	rOr�rGr^Zsubprocess_shellrr�r�r�rLrrr
�"test_subprocess_shell_invalid_argssB�
����z5BaseEventLoopTests.test_subprocess_shell_invalid_argsc	s�t���j_dd�}t�d��V}�j��}�j�||�|��fdd���j��|j	j
t�d�t
ttfd�W5QRXt�d��X}�j��}�j�d||�|��fd	d���j��|j	j
t�d�t
ttfd�W5QRXdS)
NcSs|�d�dddS)NTr-r)r��r�rrr
�
zero_error&s
zHBaseEventLoopTests.test_default_exc_handler_callback.<locals>.zero_error�asyncio.base_events.loggercs
�j��Sr
r�r�rLrr
ra.r9zFBaseEventLoopTests.test_default_exc_handler_callback.<locals>.<lambda>�Exception in callback.*zero��exc_info�{�G�z�?cs
�j��Sr
r�r�rLrr
ra8r9)rrHrGrRr&r[r|�add_done_callbackr]�error�assert_called_withr�MockPattern�ZeroDivisionError�MOCK_ANYr�)r3r��logr�rrLr
�!test_default_exc_handler_callback#s(

�

�z4BaseEventLoopTests.test_default_exc_handler_callbackc	s�t���j_dd�}t�d��x}tj|��jd�}|��fdd���j��d}t	�
�tr||jj
t�d�tttfd�n|jj
t�d	�d
d�W5QRXdS)Nc�st�d�IdHdddS)Nr�r-rr�rrrr
�zero_error_coroAszIBaseEventLoopTests.test_default_exc_handler_coro.<locals>.zero_error_coror�r�cs
�j��Sr
r��rmrLrr
raHr9zBBaseEventLoopTests.test_default_exc_handler_coro.<locals>.<lambda>z.*exception was never retrievedr�z(.*exception was never retrieved.*ZeroDivF)rrHrGrRr&r�
ensure_futurer�r]r�
gc_collect�PY34r�r�rr�r�r�)r3r�r�r�rrLr
�test_default_exc_handler_coro>s&
���z0BaseEventLoopTests.test_default_exc_handler_coroc	Cs(|�td��|j�d�W5QRXdS)NzA callable object or None�spam)r�r�rG�set_exception_handlerrLrrr
�test_set_exc_handler_invalidYsz/BaseEventLoopTests.test_set_exc_handler_invalidc	s�dd����fdd�}�j�d�t���j_���j���t��}�j�|����j��|�|�}|�	�jt
t�d�||j
d��|���j�d�t�d��(}|�|jj	t�d	�tt
t
fd
�W5QRX|jr�t�dS)NcSsdddS�Nr-rrrrrr
r�^szBBaseEventLoopTests.test_set_exc_handler_custom.<locals>.zero_errorcs�j���}�j��|Sr
�rGr|r�)r��r3r�rr
�run_loopas
z@BaseEventLoopTests.test_set_exc_handler_custom.<locals>.run_loopTz!Exception in callback.*zero_error)�	exception�messager�Zsource_tracebackr�r�r�)rGr�rrHrRr1Zget_exception_handlerr�rur�r�rr�Z_source_traceback�
reset_mockr&r�r�r��AssertionError)r3rZmock_handlerr�r�rrr
�test_set_exc_handler_custom]s8����z.BaseEventLoopTests.test_set_exc_handler_customc	sh�fdd�}dd�}t���j_�j�|�t�d��(}|�|jjt�	d�t
ttfd�W5QRXdS)Ncs"dd�}�j�|��j��dS)NcSsdddSrrrrrr
r��szTBaseEventLoopTests.test_set_exc_handler_broken.<locals>.run_loop.<locals>.zero_errorr�r�rLrr
r�sz@BaseEventLoopTests.test_set_exc_handler_broken.<locals>.run_loopcSstd��dS�Nr�)�AttributeError�rG�contextrrr
�handler�sz?BaseEventLoopTests.test_set_exc_handler_broken.<locals>.handlerr�z$Unhandled error in exception handlerr�)rrHrGrRr�r&r�r�rr�rr�)r3rrr�rrLr
�test_set_exc_handler_broken�s��z.BaseEventLoopTests.test_set_exc_handler_brokenc	s�d�G�fdd�dtj�}|��|��j�t����fdd�}t�d��}|�|jj	ddd�W5QRXd	d
�}d���
|�t�d��F}|�|jj	t�d�dd�|�
d��|�t�dd
�t�W5QRXdS)Ncs(eZdZe��Ze��Z�fdd�ZdS)z@BaseEventLoopTests.test_default_exc_handler_broken.<locals>.Loopcs|�td��dSr
�r�)r3r
��_contextrr
�default_exception_handler�szZBaseEventLoopTests.test_default_exc_handler_broken.<locals>.Loop.default_exception_handlerN)r?r@rArrHrIrRrrrrr
�Loop�srcsdd�}��|����dS)NcSsdddSrrrrrr
r��szXBaseEventLoopTests.test_default_exc_handler_broken.<locals>.run_loop.<locals>.zero_error)r|r�r	r�rr
r�s
zDBaseEventLoopTests.test_default_exc_handler_broken.<locals>.run_loopr�z&Exception in default exception handlerTr�cSstd��dS)NZhamrrrrr
�custom_handler�szJBaseEventLoopTests.test_default_exc_handler_broken.<locals>.custom_handlerz9Exception in default exception.*while handling.*in customr
r)rrFr�rYrrKrr&r�r�r�rr�reru�typer�)r3rrr�rr)rrGr
�test_default_exc_handler_broken�s2
�
��z2BaseEventLoopTests.test_default_exc_handler_brokenc	Cs8|�td��|j�d�W5QRX|�|j���dS)Nz'task factory must be a callable or Noner-)r�r�rG�set_task_factoryr1�get_task_factoryrLrrr
�test_set_task_factory_invalid�s�z0BaseEventLoopTests.test_set_task_factory_invalidcs�t��|j_Gdd�dtj��dd�}�fdd�}|�|j���|j�|�|�	|j��|�|j�
|��}|�t|���|j�
|�|j�d�|�|j���|j�
|��}|�t|tj��|�t|���|j�
|�dS)Nc@seZdZdS)z8BaseEventLoopTests.test_set_task_factory.<locals>.MyTaskNr�rrrr
�MyTask�src�sdSr
rrrrr
�coro�sz6BaseEventLoopTests.test_set_task_factory.<locals>.corocs�||d�S�Nr�r�rGr�rrr
ra�r9z:BaseEventLoopTests.test_set_task_factory.<locals>.<lambda>)rrHrGrRr�Taskr1rrru�create_taskrZ�
isinstancer^rX)r3r�factoryr�rrr
�test_set_task_factory�s z(BaseEventLoopTests.test_set_task_factorycCs�d�d�}tdd|�\}}}|�|��d�td|ddd�\}}}|�|��d�td|ddd�\}}}|�|��d	�tdd|dd
�\}}}|�|��d�tdddd|�\}}}|�|��d	�dS)
N�
)zimport asynciozloop = asyncio.get_event_loop()zprint(loop.get_debug())z-Er�sFalser*)�PYTHONASYNCIODEBUGZ
PYTHONDEVMODEr:sTrue)r&z-X�dev)r�rr/�rstrip)r3�code�sts�stdout�stderrrrr
�test_env_var_debug�s,
����
z%BaseEventLoopTests.test_env_var_debugcstGdd�dtj��dd�}G��fdd�dtj�}|��|���|�}tj|�d�}|�|��d|_|��dS)	Nc@seZdZdS)z3BaseEventLoopTests.test_create_task.<locals>.MyTaskNr�rrrr
rsrc�sdSr
rrrrr
�testsz1BaseEventLoopTests.test_create_task.<locals>.testcseZdZ��fdd�ZdS)z6BaseEventLoopTests.test_create_task.<locals>.EventLoopcs�|�d�Srr�r3r�rrGrr
r!szBBaseEventLoopTests.test_create_task.<locals>.EventLoop.create_taskN)r?r@rAr!rr0rr
�	EventLoopsr1r�F)	rr rrFrKr�r~Z_log_destroy_pendingrY)r3r.r1rr�rr0r
�test_create_tasks
z#BaseEventLoopTests.test_create_taskc	CsNdd�}t��}|j|�dd�}z|�|��d�W5|�|�|��XdS)Nc�sdSr
rrrrr
r.szLBaseEventLoopTests.test_create_named_task_with_default_factory.<locals>.test�	test_task�r$)r�new_event_loopr!r^rYr/�get_name)r3r.rGr�rrr
�+test_create_named_task_with_default_factorys
z>BaseEventLoopTests.test_create_named_task_with_default_factoryc	Cs`dd�}dd�}t��}|�|�|j|�dd�}z|�|��d�W5|�|�|��XdS)NcSstj||d�Sr)rr rrrr
�task_factory*szSBaseEventLoopTests.test_create_named_task_with_custom_factory.<locals>.task_factoryc�sdSr
rrrrr
r.-szKBaseEventLoopTests.test_create_named_task_with_custom_factory.<locals>.testr3r4)rr5rr!r^rYr/r6)r3r8r.rGr�rrr
�*test_create_named_task_with_custom_factory)s

z=BaseEventLoopTests.test_create_named_task_with_custom_factorycCsndd�}t��|j_t��|j_z|j�|��Wntk
rFYnX|j��t�	�|�
|jjj�dS)Nc�st�dSr
��KeyboardInterruptrrrr
�raise_keyboard_interrupt=szXBaseEventLoopTests.test_run_forever_keyboard_interrupt.<locals>.raise_keyboard_interrupt)rrHrGrRZcall_exception_handlerr^r;rYrr�rXr��r3r<rrr
�#test_run_forever_keyboard_interrupt9s
z6BaseEventLoopTests.test_run_forever_keyboard_interruptcs�dd�}t���j_z�j�|��Wntk
r:YnX��fdd��d�_z�j����j��Wntk
r~YnX��	�j�dS)Nc�st�dSr
r:rrrr
r<OszZBaseEventLoopTests.test_run_until_complete_baseexception.<locals>.raise_keyboard_interruptcs�j��d�_dSr�)rGr�r�r��funcr3rr
r@Ys
zFBaseEventLoopTests.test_run_until_complete_baseexception.<locals>.funcF)
rrHrGrRr^r;r�r|r]rZr=rr?r
�%test_run_until_complete_baseexceptionLsz8BaseEventLoopTests.test_run_until_complete_baseexceptionc
s�t��d�d�����fdd�}���fdd����fdd��|�j_�f�jjj_tdd	�D]D}��d
|��,�j��jj	��j�
����d�W5QRXq^dS)Nrcs�|kr�j����dSr
�rGr|)Z
event_list)�do_event�doer�event_sentinelr3rr
�proc_eventskszZBaseEventLoopTests.test_single_selecter_event_callback_after_stopping.<locals>.proc_eventscs�d7��j���dS�Nr-rBr)�	callcount�clear_selectorr3rr
rCpszWBaseEventLoopTests.test_single_selecter_event_callback_after_stopping.<locals>.do_eventcs���d�jjj_dSrC)rjrGrIrJr r)rDr3rr
rIusz]BaseEventLoopTests.test_single_selecter_event_callback_after_stopping.<locals>.clear_selectorr-rz	Loop %d/2)�objectrGrRrIrJr r�ZsubTestr|r�r]r/)r3rF�ir)rHrIrCrDrEr3r
�2test_single_selecter_event_callback_after_stoppingds
zEBaseEventLoopTests.test_single_selecter_event_callback_after_stoppingcsDd��fdd�}t��|j_|j�|�t�|j�|��d�dS)Nrcs�d7�dSrGrr��countrr
�callback�sz2BaseEventLoopTests.test_run_once.<locals>.callbackr-)rrHrGrRr|rZrun_oncer/)r3rOrrMr
�
test_run_once�sz BaseEventLoopTests.test_run_oncecCs4t��|j_|j��|j��|jjj�d�dS�Nr)	rrHrGrRr�r]rIrJZassert_called_once_withrLrrr
�test_run_forever_pre_stopped�s

z/BaseEventLoopTests.test_run_forever_pre_stoppedc�sFdddd���fdd�}|�}|������fdd��t�����S)NF)�started�stopped�	finalizedc	s,d�d<zdD]
}|VqW5d�d<XdS)NTrSrU)ZZEROZONEZTWO�THREEZFOURr��item)�statusrr
�agen�s
z;BaseEventLoopTests.leave_unfinalized_asyncgen.<locals>.agenc�sNz���IdH}Wntk
r(YdSX|dkr>d�d<dSt����dS)NrVTrT)�	__anext__�StopAsyncIterationrr!rW�Zai�iter_onerYrr
r^�sz?BaseEventLoopTests.leave_unfinalized_asyncgen.<locals>.iter_one)�	__aiter__rr!)r3rZZagrr]r
�leave_unfinalized_asyncgen�s�
z-BaseEventLoopTests.leave_unfinalized_asyncgenc	Cs�t��|j_t��|j_t���x|j�|���}|dsHt	�
|j�q2|�|d�|�|d�|�|d�t�
�t	�
|j�|�|d�W5QRXdS)NrTrSrU)rrHrGrRrSr�
disable_gcr^r`rr�rZrXr��r3rYrrr
� test_asyncgen_finalization_by_gc�s
z3BaseEventLoopTests.test_asyncgen_finalization_by_gcc	Cs�t��|j_t��|j_|j�d�t����|j�|�	��}|dsTt
�|j�q>|�|d�|�|d�|�
|d�|j�|j�dtj��t
�|j�|�|d�W5QRXdS)NTrTrSrU)rrHrGrRrSr�rrar^r`rr�rZrX�run_in_executorr�rbrrr
�0test_asyncgen_finalization_by_gc_in_other_thread�s
�zCBaseEventLoopTests.test_asyncgen_finalization_by_gc_in_other_thread)/r?r@rArErWr_rirkrwrzr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrr$r-r2r7r9r>rArLrPrRr`rcre�
__classcell__rrrMr
rB�sV
		/L$0"rBc@s:eZdZdZd
dd�Zdd�Zdd�Zd	d
�Zdd�ZdS)�MyProtoNFcCs"d|_d|_|rt����|_dS�N�INITIALr)�state�nbytesrZget_running_loopr[�done)r3r[rrr
�__init__�szMyProto.__init__cCs.||_|jdkst|j��d|_|�d�dS)Nri�	CONNECTEDs%GET / HTTP/1.0
Host: example.com

)�	transportrjr�write�r3rorrr
�connection_made�szMyProto.connection_madecCs*|jdkst|j��|jt|�7_dS)Nrn�rjrrkr��r3�datarrr
�
data_received�szMyProto.data_receivedcCs|jdkst|j��d|_dS)Nrn�EOF�rjrrLrrr
�eof_received�szMyProto.eof_receivedcCs0|jdkst|j��d|_|jr,|j�d�dS)N)rnrw�CLOSED�rjrrlr��r3r�rrr
�connection_lost�szMyProto.connection_lost)F)	r?r@rArlrmrrrvryr}rrrr
rg�s
rgc@s:eZdZdZd
dd�Zdd�Zdd�Zd	d
�Zdd�ZdS)�MyDatagramProtoNFcCsd|_d|_|r|��|_dSrh)rjrkr[rl)r3r[rGrrr
rm�szMyDatagramProto.__init__cCs$||_|jdkst|j��d|_dS)Nri�INITIALIZED)rorjrrqrrr
rrszMyDatagramProto.connection_madecCs*|jdkst|j��|jt|�7_dS�Nrrs)r3ru�addrrrr
�datagram_received
sz!MyDatagramProto.datagram_receivedcCs|jdkst|j��dSr�rxr|rrr
�error_receivedszMyDatagramProto.error_receivedcCs0|jdkst|j��d|_|jr,|j�d�dS)Nrrzr{r|rrr
r}szMyDatagramProto.connection_lost)FN)	r?r@rArlrmrrr�r�r}rrrr
r~�s
r~cs�eZdZ�fdd�Ze�d�dd��Zedd��Zedd	��Z	d
d�Z
dd
�Zdd�Zdd�Z
e�eed�d�dd��Ze�ejd�dd��Zdd�Zdd�Zdd�Zdd �Zd!d"�Zed#d$��Zd%d&�Ze�ejd�e�ej� d'�d(�ed)d*����Z!ed+d,��Z"ed-d.��Z#ed/d0��Z$d1d2�Z%ed3d4��Z&d5d6�Z'd7d8�Z(d9d:�Z)d;d<�Z*d=d>�Z+d?d@�Z,dAdB�Z-dCdD�Z.edEdF��Z/edGdH��Z0edIdJ��Z1edKdL��Z2dMdN�Z3dOdP�Z4dQdR�Z5edSdT��Z6e�ejdU�dVdW��Z7edXdY��Z8dZd[�Z9ed\d]��Z:d^d_�Z;e�eed`�da�dbdc��Z<ej=ddde��Z>dfdg�Z?dhdi�Z@djdk�ZAdldm�ZBedndo��ZCedpdq��ZDdrds�ZEe�dt�dudv��ZFdwdx�ZGe�dt�dydz��ZH�ZIS){�BaseEventLoopWithSelectorTestscs$t���t��|_|�|j�dSr
)rDrErZSelectorEventLooprGrKrLrMrr
rEs

z$BaseEventLoopWithSelectorTests.setUpzsocket.getnameinfocCs.dd�|_|j�|j�d��}|�|d�dS)NcWsdS)N�*rr�rrr
ra!r9zABaseEventLoopWithSelectorTests.test_getnameinfo.<locals>.<lambda>)�abcr�r�)�side_effectrGr^�getnameinfor/)r3Zm_gai�rrrr
�test_getnameinfos
z/BaseEventLoopWithSelectorTests.test_getnameinfoc	s�Gdd�dtj�}dd����fdd�}d�dd	g���fd
d�}||_|�j_�j�|dd
�}��t��}�j�|�W5QRX��	t
|j�d�dS)Nc@seZdZdS)zVBaseEventLoopWithSelectorTests.test_create_connection_multiple_errors.<locals>.MyProtoNr�rrrr
rg(srgc�sddgS�N�r�r-�r*)z107.6.106.82�Pr�rm�kwrrr
r!+s�zZBaseEventLoopWithSelectorTests.test_create_connection_multiple_errors.<locals>.getaddrinfocs�j��||��Sr
�rGr!�rm�kwds�r!r3rr
�getaddrinfo_task/sz_BaseEventLoopWithSelectorTests.test_create_connection_multiple_errors.<locals>.getaddrinfo_taskr�Zerr1Zerr2cs�d7�t����dSrG)�OSErrorr�)�errors�idxrr
�_socket5szVBaseEventLoopWithSelectorTests.test_create_connection_multiple_errors.<locals>._socket�example.comr�zMultiple exceptions: err1, err2)r�ProtocolrrGr!�create_connectionrOr�r^r/�strr)r3r#rgr�r�r�cmr)r�r!r�r3r
�&test_create_connection_multiple_errors%szEBaseEventLoopWithSelectorTests.test_create_connection_multiple_errorsc
s�t��}||j_�fdd�}|�j_tjj�jdtj	d��H�j�
tdd�}��tj	���j�
|�W5QRX��|jj�W5QRXdS)Ncs,�j��}tjtjdddf}|�|g�|S)Nrr*)�	127.0.0.1r�)rGr[rrrr�)rmr�r�r�rLrr
r!Js
�zRBaseEventLoopWithSelectorTests.test_create_connection_timeout.<locals>.getaddrinfo�sock_connect)r�r�r�)rrHrr rGr!r&rJr�TimeoutErrorr�rgrOr^rZrYr�)r3r#�sockr!rrrLr
�test_create_connection_timeoutDs�z=BaseEventLoopWithSelectorTests.test_create_connection_timeoutcCs,|jjtddt�d�}|�t|jj|�dS)Nr�r��r�)rGr�rgrJrOr�r^r/rrr
�%test_create_connection_host_port_sockYs�zDBaseEventLoopWithSelectorTests.test_create_connection_host_port_sockc
CsXt�tjtj�}|�:|jjt|d�}|�td��|j�|�W5QRXW5QRXdS�Nr�zA Stream Socket was expected)	rrrrGr�rgr�r�r^�r3r�rrrr
�!test_create_connection_wrong_sock^s�z@BaseEventLoopWithSelectorTests.test_create_connection_wrong_sockc
CsXt�tjtj�}|�:|jjt|d�}|�td��|j�|�W5QRXW5QRXdSr�)	rrrrG�
create_serverrgr�r�r^r�rrr
�test_create_server_wrong_sockfs�z<BaseEventLoopWithSelectorTests.test_create_server_wrong_sockc	Cs<|jjtdddd�}|�td��|j�|�W5QRXdS�Nr�r�r-)�ssl_handshake_timeoutz1ssl_handshake_timeout is only meaningful with ssl)rGr�rgr�r�r^r/rrr
�/test_create_server_ssl_timeout_for_plain_socketns��zNBaseEventLoopWithSelectorTests.test_create_server_ssl_timeout_for_plain_socket�
SOCK_NONBLOCKz$no socket.SOCK_NONBLOCK (linux only)c	Csbt�tjtjtjB�}|�>|jjdd�|d�}|j�|�}|��|j�|���W5QRXdS)NcSsdSr
rrrrr
ra|r9zRBaseEventLoopWithSelectorTests.test_create_server_stream_bittype.<locals>.<lambda>r�)	rrrr�rGr�r^rY�wait_closed)r3r�r�srvrrr
�!test_create_server_stream_bittypevs
�z@BaseEventLoopWithSelectorTests.test_create_server_stream_bittypezno IPv6 supportc
sj�fdd�}z�j�|��WnFtk
rd}z(ttd�rR|jtjkrR��d�n�W5d}~XYnXdS)Nc	�sh��t��$tjdd�dd�jd�IdH}W5QRXz��t|j	�d�W5|��|��IdHXdS)NcSsdSr
rrrrr
ra�r9zVBaseEventLoopWithSelectorTests.test_create_server_ipv6.<locals>.main.<locals>.<lambda>�::1rr�)
rxryrZstart_serverrGrYr�Z
assertGreaterr��sockets)r�rLrr
�main�s�zDBaseEventLoopWithSelectorTests.test_create_server_ipv6.<locals>.main�
EADDRNOTAVAILzfailed to bind to ::1)rGr^r�r�errnor�ZskipTest)r3r��exrrLr
�test_create_server_ipv6�s


�z6BaseEventLoopWithSelectorTests.test_create_server_ipv6c
CsTt�tj�}|�:|jjt|d�}|�td��|j�|�W5QRXW5QRXdS)Nr�zA UDP Socket was expected)rrrG�create_datagram_endpointrgr�r�r^r�rrr
�(test_create_datagram_endpoint_wrong_sock�s�zGBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_wrong_sockcCs"|j�t�}|�t|jj|�dSr
�rGr�rgrOr�r^r/rrr
�(test_create_connection_no_host_port_sock�szGBaseEventLoopWithSelectorTests.test_create_connection_no_host_port_sockcsDdd����fdd�}|�j_�j�tdd�}��t�jj|�dS)Nc�sgSr
rr�rrr
r!�szYBaseEventLoopWithSelectorTests.test_create_connection_no_getaddrinfo.<locals>.getaddrinfocs�j��||��Sr
r�r�r�rr
r��sz^BaseEventLoopWithSelectorTests.test_create_connection_no_getaddrinfo.<locals>.getaddrinfo_taskr�r�)rGr!r�rgrOr�r^�r3r�rrr�r
�%test_create_connection_no_getaddrinfo�s�zDBaseEventLoopWithSelectorTests.test_create_connection_no_getaddrinfocsZdd����fdd�}|�j_t���j_t�jj_�j�tdd�}��	t�jj
|�dS)Nc�sdgSr�rr�rrr
r!�szVBaseEventLoopWithSelectorTests.test_create_connection_connect_err.<locals>.getaddrinfocs�j��||��Sr
r�r�r�rr
r��sz[BaseEventLoopWithSelectorTests.test_create_connection_connect_err.<locals>.getaddrinfo_taskr�r�)rGr!rrHr�r�r�r�rgrOr^r�rr�r
�"test_create_connection_connect_err�s
�zABaseEventLoopWithSelectorTests.test_create_connection_connect_errc	spdd����fdd�}|�j_t���j_t�jj_�jjtddt	j
d�}��t���j�|�W5QRXdS)Nc�sddgS�N)r�r-r�r*)�0.0.0.1r�)r�r-r�r*)z0.0.0.2r�rr�rrr
r!�s�zSBaseEventLoopWithSelectorTests.test_create_connection_multiple.<locals>.getaddrinfocs�j��||��Sr
r�r�r�rr
r��szXBaseEventLoopWithSelectorTests.test_create_connection_multiple.<locals>.getaddrinfo_taskr�r���family)
rGr!rrHr�r�r�r�rgrrrOr^r�rr�r
�test_create_connection_multiple�s
�z>BaseEventLoopWithSelectorTests.test_create_connection_multiplec	s�dd�}||jj_dd����fdd�}|�j_t���j_td��jj_	�jj
tdd	tjd
d�}��
t��}�j�|�W5QRX��t|j��d����|jjjj�dS)
NcSs"|ddkrtd�}d|_|�dS)Nrr��Err)r��strerror)r��errrrr
�bind�sz^BaseEventLoopWithSelectorTests.test_create_connection_multiple_errors_local_addr.<locals>.bindc�sddgSr�rr�rrr
r!�s�zeBaseEventLoopWithSelectorTests.test_create_connection_multiple_errors_local_addr.<locals>.getaddrinfocs�j��||��Sr
r�r�r�rr
r��szjBaseEventLoopWithSelectorTests.test_create_connection_multiple_errors_local_addr.<locals>.getaddrinfo_taskZErr2r�r��Ni��r��
local_addrzMultiple exceptions: )rr r�rGr!rrHr�r�r�r�rgrrOr^rZr�r�
startswithrYr�)r3r#r�r�rr�rr�r
�1test_create_connection_multiple_errors_local_addr�s$
�zPBaseEventLoopWithSelectorTests.test_create_connection_multiple_errors_local_addrc	Csv|s|`tj|_|jj}t��|j_d|jj_t��|j_	d|jj	_|j�
tjdd�}|j�
|�\}}z@|j�d�|jj\}}|�|d|j�|�|d|j�W5|��t�|j�Xtj�rrtj|_|j�
tjdd�}|j�
|�\}}zj|jjd\}	|	dd	�\}
}|�|
d
�|�|d�|jj\}}|�|d|j�|�|d|j�W5|��t�|j�XdS)NFr,r��r,r�r�rr�rr�z	::(0\.)*1)rrr!r rrHrG�_add_readerr"�_add_writerr�rr�r^rYrr��connectr�r�r/rrrr2rr��assertRegex)r3r#Zallow_inet_ptonr�rr��p�_rn�address�host�portrrr
�_test_create_connection_ip_addr�s>

z>BaseEventLoopWithSelectorTests._test_create_connection_ip_addrZaixzDbpo-25545: IPv6 scope id and getaddrinfo() behave differently on AIXc	Cs�tj|_|jj}tj|_t��|j_d|jj_	t��|j_
d|jj
_	|j�tj
dd�}|j�|�\}}z@|j�d�|jj\}}|�|d|j�|�|d|j�W5|��t�|j�XdS)NFz	fe80::1%1r�)zfe80::1r�rr-r�r)rr!r rr�rrHrGr�r"r�r�rr�r^rYrr�r�r�r�r/r)r3r#r�rr�r�r�rnrrr
�!test_create_connection_ipv6_scopes 

z@BaseEventLoopWithSelectorTests.test_create_connection_ipv6_scopecCs|�|d�dSr��r�r=rrr
�test_create_connection_ip_addr1sz=BaseEventLoopWithSelectorTests.test_create_connection_ip_addrcCs|�|d�dSr`r�r=rrr
�#test_create_connection_no_inet_pton5szBBaseEventLoopWithSelectorTests.test_create_connection_no_inet_ptonc

Cs
tj|_|jj}t��|j_d|jj_t��|j_d|jj_dD]�\}}|j�	t
jd|�}|j�|�\}}zD|j�d|f�|jj\}}	|�|	d|j�|�|	d|j�W5|�
�t�|j�Xq@dD]8}|j�	t
jd|�}|�t��|j�|�W5QRXq�dS)NF))Zhttpr�)shttpr�r�r�r)Znonsensesnonsense)rr!r rrHrGr�r"r�r�rr�r^rYrr�r�r�r�r/rrrOr�)
r3r#r�Zservicer�rr�r�r�rnrrr
�#test_create_connection_service_name9s4


�
�zBBaseEventLoopWithSelectorTests.test_create_connection_service_namecsLdd����fdd�}|�j_�jjtddtjdd�}��t�jj|�dS)	Nc�s|dkrddgSgSdS)Nr�r�r)r�rmr�rrr
r!Ys
�zXBaseEventLoopWithSelectorTests.test_create_connection_no_local_addr.<locals>.getaddrinfocs�j��||��Sr
r�r�r�rr
r�`sz]BaseEventLoopWithSelectorTests.test_create_connection_no_local_addr.<locals>.getaddrinfo_taskr�r�r�r�)	rGr!r�rgrrrOr�r^r�rr�r
�$test_create_connection_no_local_addrXs��zCBaseEventLoopWithSelectorTests.test_create_connection_no_local_addrcs<d��fdd�}||_|��}|j�|��}|j�|�dS)N)z00:01:02:03:04:05r-cs$||f�kst�dddd�dffgS)Ni�r-r*)r)r�r�rmr��r�rr
r!pszTBaseEventLoopWithSelectorTests.test_create_connection_bluetooth.<locals>.getaddrinfo)r!rrGr�r^)r3r#r!r�rrr�r
� test_create_connection_bluetoothjsz?BaseEventLoopWithSelectorTests.test_create_connection_bluetoothc	s�t���j_�fdd�}|�jj_t���j_�j���jj_�jjj�d�t���j_	Gdd�d���fdd�}|�jj	_tj
}t�}�jj	���jj
tddd	|d
�}�j�|�\}}|���jj	j||||dd|d��jj	���jj
tddd	d
|d�}�j�|�\}}|���jj	j||||dd
|d��jj	���jj
tddd	d|d�}�j�|�\}}|���jj	j||||dd|d�dS)Ncs*�j��}|�tjtjtjddfg�|S)Nr*r�)rGr[r�rrr�SOL_TCP)rmr�r'rLrr
�mock_getaddrinfo|s
�zkBaseEventLoopWithSelectorTests.test_create_connection_ssl_server_hostname_default.<locals>.mock_getaddrinfoc@s eZdZdZdd�Zdd�ZdS)zqBaseEventLoopWithSelectorTests.test_create_connection_ssl_server_hostname_default.<locals>._SelectorTransportMockNcSst��Sr
)rrH)r3�keyrrr
�get_extra_info�sz�BaseEventLoopWithSelectorTests.test_create_connection_ssl_server_hostname_default.<locals>._SelectorTransportMock.get_extra_infocSs|j��dSr
)�_sockrYrLrrr
rY�szwBaseEventLoopWithSelectorTests.test_create_connection_ssl_server_hostname_default.<locals>._SelectorTransportMock.close)r?r@rAr�r�rYrrrr
�_SelectorTransportMock�sr�cs|�d���}||_|Sr
)r�r�)r��protocolZ
sslcontext�waiterr�ro)r�rr
�mock_make_ssl_transport�s
zrBaseEventLoopWithSelectorTests.test_create_connection_ssl_server_hostname_default.<locals>.mock_make_ssl_transport�
python.orgr�T)�sslr�F)Zserver_side�server_hostnamer�zperl.com)r�r�r�r*)rrHrGr!r�r�r[r r�rQ�ANYrJrr�rgr^rYr�)r3r�r�r�Zhandshake_timeoutrror�r)r�r3r
�2test_create_connection_ssl_server_hostname_defaultys�
	
������zQBaseEventLoopWithSelectorTests.test_create_connection_ssl_server_hostname_defaultcCsP|jjtdddd�}|�t|jj|�|jjtdddd�}|�t|jj|�dS)Nr�r�r*)r�r�r/rrr
�4test_create_connection_no_ssl_server_hostname_errors�s��zSBaseEventLoopWithSelectorTests.test_create_connection_no_ssl_server_hostname_errorscCs�|jjtdddd�}|�t|jj|�|jjtdddd�}|�t|jj|�t��}|jjtddd|d�}|�|j�|�t|jj|�dS)Nr*r�T)r�)r�r�)	rGr�rgrOr�r^rr�rY)r3rr�rrr
�1test_create_connection_ssl_server_hostname_errors�s�zPBaseEventLoopWithSelectorTests.test_create_connection_ssl_server_hostname_errorsc	Cs<|jjtdddd�}|�td��|j�|�W5QRXdSr�)rGr�rgr�r�r^r/rrr
�3test_create_connection_ssl_timeout_for_plain_socket�s��zRBaseEventLoopWithSelectorTests.test_create_connection_ssl_timeout_for_plain_socketcsXt���fdd����fdd�}|�j_�j�tdd�}��t�jj|�����dS)Nc�s|d�gSrQrr�)r�rr
r!�szQBaseEventLoopWithSelectorTests.test_create_server_empty_host.<locals>.getaddrinfocs�j��||��Sr
r�r�r�rr
r��szVBaseEventLoopWithSelectorTests.test_create_server_empty_host.<locals>.getaddrinfo_taskr*r)	rJrGr!r�rgrOr�r^r1)r3r�r�r)r!r�r3r
�test_create_server_empty_host�sz<BaseEventLoopWithSelectorTests.test_create_server_empty_hostcCs,|jjtddt�d�}|�t|jj|�dS)N�0.0.0.0rr�)rGr�rgrJrOr�r^�r3r�rrr
�!test_create_server_host_port_sock�s�z@BaseEventLoopWithSelectorTests.test_create_server_host_port_sockcCs"|j�t�}|�t|jj|�dSr
)rGr�rgrOr�r^r�rrr
�$test_create_server_no_host_port_sock�szCBaseEventLoopWithSelectorTests.test_create_server_no_host_port_sockcCsNt��}|j_|j��|_|j�d�|j�tdd�}|�	t
|jj|�dS)Nr�r)rrHrGr!r[r r�r�rgrOr�r^)r3r!r'rrr
�!test_create_server_no_getaddrinfo�s
z@BaseEventLoopWithSelectorTests.test_create_server_no_getaddrinfocCsBtj|_|`t��|j_|jjtdddd�}|�	t
|jj|�dS)Nr�rT��
reuse_port)rr!�SO_REUSEPORTrrHr rGr�rgrOr�r^�r3r#r'rrr
� test_create_server_nosoreuseports�z?BaseEventLoopWithSelectorTests.test_create_server_nosoreuseportcCsDtj|_t��|j_d|_|jjtdddd�}|�	t
|jj|�dS)Nr�r�rTr�)rr!rrHr r�rGr�rgrOr�r^r�rrr
�+test_create_server_soreuseport_only_defineds�zJBaseEventLoopWithSelectorTests.test_create_server_soreuseport_only_definedcCsnGdd�dt�}dg|j_d|j_t��}|j_||j_|j	�
tdd�}|�t|j	j
|�|�|jj�dS)Nc@seZdZdZdS)zHBaseEventLoopWithSelectorTests.test_create_server_cant_bind.<locals>.Errr�N)r?r@rAr�rrrr
r�sr�)r�r-r�r*)r�it'Fr�r)r�r!r r"rrHrr�r�rGr�rgrOr^rZrYr��r3r#r�Zm_sockr�rrr
�test_create_server_cant_binds�z;BaseEventLoopWithSelectorTests.test_create_server_cant_bindcCs6g|j_d|j_|jjtdd�}|�t|jj|�dS)NF)�	localhostr�r�)	r!r r"rGr�r~rOr�r^�r3r#rrrr
�)test_create_datagram_endpoint_no_addrinfo's��zHBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_no_addrinfocCsH|jjtdd�}|�t|jj|�|jjtdd�}|�t|jj|�dS)Nrr)rr-r�r)rGr�r~rOrr^r/rrr
�(test_create_datagram_endpoint_addr_error1s$����zGBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_addr_errorcCs>t��|j_t|jj_|jjtjdd�}|�	t|jj
|�dS)N�r�r)�remote_addr)rrHrGr�r�r�r�r�DatagramProtocolrOr^r/rrr
�)test_create_datagram_endpoint_connect_err;s
��zHBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_connect_errcs�td|jd��t��|j_}g|_|jj�fdd�ddd�}|j�|�\}}|�|j	�|�
�|j��j�|�d�j
�dS)NT�r[rGcs�Sr
rr�r�rr
raJr9z^BaseEventLoopWithSelectorTests.test_create_datagram_endpoint_allow_broadcast.<locals>.<lambda>r)r�allow_broadcastrz)r~rGrrHr�r r�r^rXr�rYrlr/rj)r3r�rror�rrr
�-test_create_datagram_endpoint_allow_broadcastDs
�zLBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_allow_broadcastcCs^tj|_t|j_|jjtjtjd�}|�	t|jj
|�|jjtjdd�}|�	t|jj
|�dS)Nr�rr)rr!r�r�rGr�rrrrOr^rrrr
�(test_create_datagram_endpoint_socket_errUs(����zGBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_socket_errzIPv6 not supported or enabledcCs*|jjtjddd�}|�t|jj|�dS)Nr)r�r)rr��rGr�rrrOr�r^r/rrr
�0test_create_datagram_endpoint_no_matching_familyds��zOBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_no_matching_familycCsHt|jjj_|jjtjtj	d�}|�
t|jj|�|�|jjj
j�dS)Nr�)r�rr �setblockingr�rGr�rrrrOr^rZrYr�rrrr
�(test_create_datagram_endpoint_setblk_errls��
�zGBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_setblk_errcCs$|j�tj�}|�t|jj|�dSr
rr/rrr
�-test_create_datagram_endpoint_noaddr_nofamilyws�zLBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_noaddr_nofamilycCshGdd�dt�}tj|_t��}|j_||j_|jj	t
dtjd�}|�||jj
|�|�|jj�dS)Nc@seZdZdS)zSBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_cant_bind.<locals>.ErrNr�rrrr
r�~sr�r)r�r�)r�rr!rrHr r�r�rGr�r~rrOr^rZrYr�r�rrr
�'test_create_datagram_endpoint_cant_bind|s�zFBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_cant_bindcsjt�tjtj�}|�d��jj�fdd�|d�}�j�|�\}}|���j�|j���	d|j
�dS)Nrcstd�jd�S�NTr
�r~rGrrLrr
ra�r9zSBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_sock.<locals>.<lambda>r�rz)rrrr�rGr�r^rYrlr/rj)r3r�r�ror�rrLr
�"test_create_datagram_endpoint_sock�s

�zABaseEventLoopWithSelectorTests.test_create_datagram_endpoint_sock�AF_UNIXzNo UNIX Socketscsd�jj�fdd�tjd�}�j�|�\}}|jjtjks<t�|���j�|j	���
d|j�dS)Ncstd�jd�SrrrrLrr
ra�r9zXBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_sock_unix.<locals>.<lambda>r�rz)rGr�rrr^r�r�rrYrlr/rj)r3r�ror�rrLr
�'test_create_datagram_endpoint_sock_unix�s
�zFBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_sock_unixc	s~t���l}tjtjtjd�}|�|�|���jj�fdd�|tjd�}�j�	|�\}}|���j�	|j
�W5QRXdS)N)rcstd�jd�SrrrrLrr
ra�r9zaBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_existing_sock_unix.<locals>.<lambda>r�)rZunix_socket_pathrrrr�rYrGr�r^rl)r3�pathr�rror�rrLr
�0test_create_datagram_endpoint_existing_sock_unix�s


�zOBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_existing_sock_unixcCsGdd�d�}|jjtd|�d�}|�t|jj|�|jjtd|�d�}|�t|jj|�|jjtd|�d�}|�t|jj|�|jjtd|�d�}|�t|jj|�|jjtd|�d	�}|�t|jj|�|jjtd
|�d�}|�t|jj|�|jjtd
|�d�}|�t|jj|�dS)
Nc@seZdZejZdS)z\BaseEventLoopWithSelectorTests.test_create_datagram_endpoint_sock_sockopts.<locals>.FakeSockN)r?r@rArrrrrrr
�FakeSock�srr)r�r�)rr�r-)r�r�)�protor�)�flagsr�T)r�r�)rr�)rGr�r~rOr�r^)r3rr�rrr
�+test_create_datagram_endpoint_sock_sockopts�sV�������zJBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_sock_sockoptscs4�jj�fdd�dd�}�j�|�\}}|�d�}ttd�}|rV��|�tjtj	����|�tjtj
��|���j�|j���
d|j��jj�fdd�d|d	d
�}�j�|�\}}|�d�}��|�tjtj��|r���|�tjtj	����|�tjtj
��|���j�|j���
d|j�dS)Ncstd�jd�SrrrrLrr
ra�r9zWBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_sockopts.<locals>.<lambda>rrrr�rzcstd�jd�SrrrrLrr
ra�r9T)r�r�r)rGr�r^r�rrrX�
getsockoptrr��SO_BROADCASTrYrlr/rjrrZ)r3rror�r��reuseport_supportedrrLr
�&test_create_datagram_endpoint_sockopts�sj
�

����
�
������zEBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_sockoptsc	s@�jj�fdd�ddd�}��t���j�|�W5QRXdS)Ncstd�jd�SrrrrLrr
rar9zbBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_reuse_address_error.<locals>.<lambda>rT�r�Z
reuse_address)rGr�rOr�r^r/rrLr
�1test_create_datagram_endpoint_reuse_address_error�s
�zPBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_reuse_address_errorc	sh�jj�fdd�ddd�}��t��:�j�|�\}}|���j�|j���d|j�W5QRXdS)Ncstd�jd�SrrrrLrr
rar9zdBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_reuse_address_warning.<locals>.<lambda>rFr$rz)	rGr�rxryr^rYrlr/rj)r3rror�rrLr
�3test_create_datagram_endpoint_reuse_address_warning
s
�zRBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_reuse_address_warningcs@|`t��|j_�jj�fdd�ddd�}��t�jj	|�dS)Ncst�jd�SrrrrLrr
rar9z\BaseEventLoopWithSelectorTests.test_create_datagram_endpoint_nosoreuseport.<locals>.<lambda>rT�r�r�)
r�rrHrr rGr�rOr�r^rrrLr
�+test_create_datagram_endpoint_nosoreuseports
�zJBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_nosoreuseportc	s��fdd�}||_t��|jj_}t���j_d�jj_t	td�}�jj
�fdd�d|d�}�j�|�\}}z&|�d�|jj|j|j|jd	�W5|��t
��j�XdS)
Ncs��d�dS)Nz"should not have called getaddrinfo)Zfailr�rLrr
r!&szYBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_ip_addr.<locals>.getaddrinfoFr�cst�jd�SrrrrLrr
ra0r9zVBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_ip_addr.<locals>.<lambda>r8r')r�rr)r!rrHrr r�rGr�r"rr�r^rYrr�r�rrr)r3r#r!r�r"rr�r�rrLr
�%test_create_datagram_endpoint_ip_addr$s(


�

�
zDBaseEventLoopWithSelectorTests.test_create_datagram_endpoint_ip_addrcCs2t��}t�|j_|j�t|�|�|j	j
�dSr
)rrH�BlockingIOError�acceptr�rG�_accept_connectionrgrXrYr��r3r�rrr
�test_accept_connection_retry>s
z;BaseEventLoopWithSelectorTests.test_accept_connection_retryr�c
Cs�t��}d|j_ttjd�|j_t��|j	_
t��|j	_|j	�t
|�|�|jj�|�|jj�|j	j
�d�|j	j�tjtjt
|ddtjtj�dS)N�
zToo many open files)rrH�filenor r�r�ZEMFILEr+r�rGZ_remove_readerr�r,rgrZr�r�rXrYr�rZACCEPT_RETRY_DELAYr�)r3Zm_logr�rrr
� test_accept_connection_exceptionEs&�z?BaseEventLoopWithSelectorTests.test_accept_connection_exceptionc
Cs|�t��tjdd��}W5QRX|j�d�|}|�}|�|j�||fD]�}|�t	��|j�
|�W5QRX|�t	��|j�|�W5QRX|�t	��|j�d|�W5QRX|�t	��|j�
|j��d|�W5QRX|�t	��|j�|j�d|��W5QRXqNdS)NcSsdSr
rrrrr
�simple_coroutineYszLBaseEventLoopWithSelectorTests.test_call_coroutine.<locals>.simple_coroutineTr�)rxryr�	coroutinerGr�r�rYrOr�r|r�r�r�r�r^rd)r3r2Z	coro_funcZcoro_objr@rrr
�test_call_coroutineWs("�z2BaseEventLoopWithSelectorTests.test_call_coroutinecCs�dd�}dd�}t�|j�|j�d�d|j_|j�||j�|j��|jjd^}}|�	|t
|�d�tj||j�|jd	�|j��|jjd^}}|�	|t
|�d
�dS)NcSs|��dSr
�r�r�rrr
�stop_loop_cbpszLBaseEventLoopWithSelectorTests.test_log_slow_callbacks.<locals>.stop_loop_cbc�s|��dSr
r5r�rrr
�stop_loop_corosszNBaseEventLoopWithSelectorTests.test_log_slow_callbacks.<locals>.stop_loop_coroTgrz4^Executing <Handle.*stop_loop_cb.*> took .* seconds$r�z4^Executing <Task.*stop_loop_coro.*> took .* seconds$)rrKrGr�Zslow_callback_durationr|r]�warningr�r��tupler�)r3Zm_loggerr6r7�fmtrmrrr
�test_log_slow_callbacksns"
�
�z6BaseEventLoopWithSelectorTests.test_log_slow_callbacks)Jr?r@rArErr&r�r(r�r�r�r�r�r��unittest�
skipUnlessrrr�rr2r�r�r�r�r�r�r�r�ZskipIfr��platformr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrr	r
rrrrrrrZskip_unless_bind_unix_socketrrr#r%r&r(r)r.r1r4r;rfrrrMr
r�s�


�
	

+�



I	





	
	








 /


r�c@seZdZdd�ZdS)�RunningLoopTestsc	CsZdd�}t��}t��}z*|�td��|�||��W5QRXW5|��|��XdS)Nc�s|��dSr
)r]r�rrr
�runner�sz@RunningLoopTests.test_running_loop_within_a_loop.<locals>.runnerzwhile another loop is running)rr5rYr�r\r^)r3r@rGZ
outer_looprrr
�test_running_loop_within_a_loop�s�z0RunningLoopTests.test_running_loop_within_a_loopN)r?r@rArArrrr
r?�sr?cs�eZdZddZGdd�dej�Ze�fdd��Ze�fdd��Z	�fd	d
�Z
d(dd
�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Z�ZS))�BaseLoopSockSendfileTestss�12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcdeic@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)z!BaseLoopSockSendfileTests.MyProtocCs(d|_d|_t�|_|��|_d|_dSr`)rS�closed�	bytearrayrur[r�ro)r3rGrrr
rm�s

z*BaseLoopSockSendfileTests.MyProto.__init__cCsd|_||_dSr�)rSrorqrrr
rr�sz1BaseLoopSockSendfileTests.MyProto.connection_madecCs|j�|�dSr
)ru�extendrtrrr
rv�sz/BaseLoopSockSendfileTests.MyProto.data_receivedcCsd|_|j�d�d|_dSr�)rCr�r�ror|rrr
r}�sz1BaseLoopSockSendfileTests.MyProto.connection_lostc�s|jIdHdSr
r�rLrrr
r��sz-BaseLoopSockSendfileTests.MyProto.wait_closedN)r?r@rArmrrrvr}r�rrrr
rg�s
rgc	s@tj|_dt_ttjd��}|�|j�W5QRXt��	�dS)Ni@�wb)
r�!SENDFILE_FALLBACK_READBUFFER_SIZE�'_BaseLoopSockSendfileTests__old_bufsize�openr�TESTFNrp�DATArD�
setUpClass)�cls�fprMrr
rL�s
z$BaseLoopSockSendfileTests.setUpClasscs"|jt_t�tj�t���dSr
)rHrrGr�unlinkrJrD�
tearDownClass)rMrMrr
rP�sz'BaseLoopSockSendfileTests.tearDownClasscsJddlm}|�|_|�|j�ttjd�|_|�|jj	�t
���dS)Nr)�BaseSelectorEventLoop�rb)Zasyncio.selector_eventsrQrGrKrIrrJ�filer�rYrDrE)r3rQrMrr
rE�szBaseLoopSockSendfileTests.setUpFcCs*t�tjtj�}|�|�|�|j�|Sr
)rrrrr�rY)r3�blockingr�rrr
�make_socket�s
z%BaseLoopSockSendfileTests.make_socketcCs|j�|�Sr
)rGr^r/rrr
r�sz"BaseLoopSockSendfileTests.run_loopc	s��������j�����jj�fdd�tjdtjd����j	d�
�}td�D]J}z���j��|��Wn(t
k
r���t�d��YqPYqPXq�qP���j��|������fdd�}��|���fS)	Ncs�Sr
rr)rrr
ra�r9z3BaseLoopSockSendfileTests.prepare.<locals>.<lambda>rr�r/g�?csD�������������jdk	r@�j��������dSr
)rYrr�ror�rr3Zserverr�rr
�cleanup�s

z2BaseLoopSockSendfileTests.prepare.<locals>.cleanup)rUrgrGrr�rZHOSTrrr��getsocknamer�r�r�rr�r�)r3r�r�rWrrVr
�prepare�s(

�

z!BaseLoopSockSendfileTests.preparec	Csd|��\}}|�tjd�� |�|j�||jdd��W5QRX|�|j	d�|�|j�
�d�dS)N�sendfile is not availablerr9)rYr�r�SendfileNotAvailableErrorrrGZ_sock_sendfile_nativerSr/ru�tell�r3r�rrrr
�"test__sock_sendfile_native_failure�s��z<BaseLoopSockSendfileTests.test__sock_sendfile_native_failurec	Csd|��\}}|�tjd�� |�|jj||jdd��W5QRX|�|j�	�d�|�|j
d�dS)NrZF)�fallbackrr9)rYr�rr[rrG�
sock_sendfilerSr/r\rur]rrr
�test_sock_sendfile_no_fallbacks��z8BaseLoopSockSendfileTests.test_sock_sendfile_no_fallbackcCsv|��\}}|�|j�||j��}|��|�|���|�|t|j	��|�|j�
�t|j	��|�|j|j	�dSr
)rYrrGr`rSrYr�r/r�rKr\ru�r3r�r�retrrr
�test_sock_sendfile_fallback
sz5BaseLoopSockSendfileTests.test_sock_sendfile_fallbackcCsv|��\}}|�|j�||jdd��}|��|�|���|�|d�|�|j��d�|�|j	|j
dd��dS)Ni�i�r�)rYrrGr`rSrYr�r/r\rurKrbrrr
�,test_sock_sendfile_fallback_offset_and_counts�zFBaseLoopSockSendfileTests.test_sock_sendfile_fallback_offset_and_countc	CsJ|j�d�|jdd�}|�td��|�|j�||j��W5QRXdS)NT)rTzmust be non-blocking)rGr�rUr�r�rr`rSr-rrr
�test_blocking_socket$sz.BaseLoopSockSendfileTests.test_blocking_socketc
CsP|��}ttjd��2}|�td��|�|j�||��W5QRXW5QRXdS)Nr�zbinary mode)	rUrIrrJr�r�rrGr`)r3r�r'rrr
�test_nonbinary_file*sz-BaseLoopSockSendfileTests.test_nonbinary_filec	CsXt�tjtj�}|�d�|�|j�|�td��|�|j	�
||j��W5QRXdS)NFzonly SOCK_STREAM type)rrrrr�rYr�r�rrGr`rSr-rrr
�test_nonstream_socket0s

z/BaseLoopSockSendfileTests.test_nonstream_socketc	Cs>|��}|�td�� |�|j�||jdd��W5QRXdS)N� count must be a positive integerrrN�rUr�r�rrGr`rSr-rrr
�test_notint_count7s
�z+BaseLoopSockSendfileTests.test_notint_countc	Cs>|��}|�td�� |�|j�||jdd��W5QRXdS)Nrirr��rUr�r�rrGr`rSr-rrr
�test_negative_count=s
�z-BaseLoopSockSendfileTests.test_negative_countc	Cs<|��}|�td��|�|j�||jd��W5QRXdS)N�%offset must be a non-negative integer�offsetrjr-rrr
�test_notint_offsetCs
�z,BaseLoopSockSendfileTests.test_notint_offsetc	Cs<|��}|�td��|�|j�||jd��W5QRXdS)Nrnr�rlr-rrr
�test_negative_offsetIs
�z.BaseLoopSockSendfileTests.test_negative_offset)F)r?r@rArKrr�rg�classmethodrLrPrErUrrYr^rardrerfrgrhrkrmrprqrfrrrMr
rB�s*	
rBc@s.eZdZdd�Ze�eed�d�dd��ZdS)�TestSelectorUtilscCsB|�tjtj�}|�|�t�|�|�tjtj�}|�|�dSr
)r rr�TCP_NODELAYrXrZ_set_nodelayrZ)r3r��optrrr
�check_set_nodelayQs


z#TestSelectorUtils.check_set_nodelayrtzneed socket.TCP_NODELAYc	Csntjtjtjtjd�}|�|�|�W5QRXtjtjtjtjd�}|�|�d�|�|�W5QRXdS)N)r�rrF)rrrrrvrr-rrr
�test_set_nodelayZs��
z"TestSelectorUtils.test_set_nodelayN)	r?r@rArvr<r=rrrwrrrr
rsPs
	�rs�__main__)*�__doc__�concurrent.futuresrqr�r��osrr�r�r�r<rrrrZtest.test_asynciorrr.rZtest.support.script_helperrr�r��version_infor�rr%r(ZTestCaser)rBr�rgrr~r�r?rBrsr?r�rrrr
�<module>sX
aNy5