Your IP : 216.73.217.32


Current Path : /opt/alt/python35/lib64/python3.5/test/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/test/__pycache__/test_asyncore.cpython-35.opt-1.pyc



��Yf�g�@s�ddlZddlZddlZddlZddlZddlZddlZddlZddlZddl	m
Z
ddlmZyddl
Z
Wnek
r�dZ
YnXdZeed�ZGdd�d�ZGdd	�d	�ZGd
d�d�ZGdd
�d
�Zdd�Zdd�ZGdd�dej�ZGdd�dej�ZGdd�dej�ZGdd�dej�Zejeed�d�Gdd�dej��ZGdd�dej �Z!Gd d!�d!ej �Z"Gd"d#�d#e!�Z#Gd$d%�d%�Z$Gd&d'�d'e$�Z%eje
j&d(�Gd)d*�d*e$��Z'ejed+�Gd,d-�d-e$��Z(Gd.d/�d/e%ej�Z)ejeed0�d1�Gd2d3�d3e%ej��Z*Gd4d5�d5e'ej�Z+ejeed0�d1�Gd6d7�d7e'ej��Z,Gd8d9�d9e(ej�Z-ejeed0�d1�Gd:d;�d;e(ej��Z.e/d<kr�ej0�dS)=�N)�support)�BytesIO��AF_UNIXc@s4eZdZdd�Zdd�Zdd�ZdS)�dummysocketcCs
d|_dS)NF)�closed)�self�r	�7/opt/alt/python35/lib64/python3.5/test/test_asyncore.py�__init__szdummysocket.__init__cCs
d|_dS)NT)r)rr	r	r
�closeszdummysocket.closecCsdS)N�*r	)rr	r	r
�filenoszdummysocket.filenoN)�__name__�
__module__�__qualname__rrrr	r	r	r
rsrc@s(eZdZdd�Zdd�ZdS)�dummychannelcCst�|_dS)N)r�socket)rr	r	r
r!szdummychannel.__init__cCs|jj�dS)N)rr)rr	r	r
r$szdummychannel.closeN)rrrrrr	r	r	r
r src@s:eZdZdd�Zdd�ZeZeZeZdS)�exitingdummycCsdS)Nr	)rr	r	r
r(szexitingdummy.__init__cCstj��dS)N)�asyncore�ExitNow)rr	r	r
�handle_read_event+szexitingdummy.handle_read_eventN)rrrrr�handle_write_event�handle_close�handle_expt_eventr	r	r	r
r's
rc@sFeZdZdd�Zdd�ZeZeZeZdd�ZdS)�
crashingdummycCs
d|_dS)NF)�
error_handled)rr	r	r
r3szcrashingdummy.__init__cCs
t��dS)N)�	Exception)rr	r	r
r6szcrashingdummy.handle_read_eventcCs
d|_dS)NT)r)rr	r	r
�handle_error=szcrashingdummy.handle_errorN)	rrrrrrrrrr	r	r	r
r2srcCsz�y |j�|j�\}}Wntjk
r:Yn�Xd}tj�}x�|dkr�tj�|dkr�tj|gggd�\}}}	|r�|d8}|jd�}
|j|
jdd��d|
kr�Ptj	d	�qPW|j
�Wd|j
�|j�XdS)
N��rg@g�������?��
s
�g{�G�z�?)�listenZacceptr�timeout�time�select�recv�write�replace�sleepr�set)�evtZbufZserv�conn�addr�n�start�r�w�e�datar	r	r
�capture_serverAs&
%$

r5cCs6tr%|jtjkr%tj|�|j|�dS)z9Helper function to bind a socket according to its family.N)�HAS_UNIX_SOCKETS�familyrrr�unlink�bind)�sockr.r	r	r
�
bind_af_awareZs
r;c@sseZdZdd�Zejeed�d�dd��Zdd�Z	d	d
�Z
dd�Zd
d�ZdS)�HelperFunctionTestscCs�t�}|jtjtj|�|jtjtj|�|jtjtj|�t�}tj|�|j|j	d�t�}tj|�|j|j	d�t�}tj|�|j|j	d�dS)NT)
r�assertRaisesrr�readr(Z
_exceptionr�assertEqualr)r�tr1�tr2r	r	r
�test_readwriteexccs		
	
	
z%HelperFunctionTests.test_readwriteexc�pollzselect.poll requiredc
CsHd
}tjdftjdftjdftjdftjdftjdff}Gdd�d�}x�|D]�\}}|�}|jt||�d�t	j
||�x-|D]%}|jt||�||k�q�Wt�}|jt	j
t	j
||�t�}	|j|	jd�t	j
|	|�|j|	jd	�qnWdS)Nr>�exptr(rrc@sXeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)z3HelperFunctionTests.test_readwrite.<locals>.testobjcSs1d|_d|_d|_d|_d|_dS)NF)r>r(rrDr)rr	r	r
r�s
				z<HelperFunctionTests.test_readwrite.<locals>.testobj.__init__cSs
d|_dS)NT)r>)rr	r	r
r�szEHelperFunctionTests.test_readwrite.<locals>.testobj.handle_read_eventcSs
d|_dS)NT)r()rr	r	r
r�szFHelperFunctionTests.test_readwrite.<locals>.testobj.handle_write_eventcSs
d|_dS)NT)r)rr	r	r
r�sz@HelperFunctionTests.test_readwrite.<locals>.testobj.handle_closecSs
d|_dS)NT)rD)rr	r	r
r�szEHelperFunctionTests.test_readwrite.<locals>.testobj.handle_expt_eventcSs
d|_dS)NT)r)rr	r	r
r�sz@HelperFunctionTests.test_readwrite.<locals>.testobj.handle_errorN)	rrrrrrrrrr	r	r	r
�testobj�srEFT)r>rDr(rr)r&ZPOLLINZPOLLPRIZPOLLOUTZPOLLERRZPOLLHUPZPOLLNVALr?�getattrrZ	readwriterr=rrr)
rZ
attributes�expectedrE�flagZexpectedattrZtobj�attrr@rAr	r	r
�test_readwrite�s(	
#		z"HelperFunctionTests.test_readwritecCs|jd�dS)NF)�closeall_check)rr	r	r
�
test_closeall�sz!HelperFunctionTests.test_closeallcCs|jd�dS)NT)rK)rr	r	r
�test_closeall_default�sz)HelperFunctionTests.test_closeall_defaultcCs�g}i}xJtd�D]<}t�}|j|�|j|jjd�|||<qW|r�tj}z|t_tj�Wdtj|}t_Xn
tj|�|jt	|�d�x$|D]}|j|jjd�q�WdS)Nr!FrT)
�ranger�appendr?rrr�
socket_map�	close_all�len)rZ
usedefault�lZtestmap�i�cZ	socketmapr	r	r
rK�s"	
		

z"HelperFunctionTests.closeall_checkcCs�ytd��Wn)tj�\}}}tj�}YnX|jd�|\\}}}}}	}
|jtjj	|�dd�|j|d�|j||�|j|	|�|j|
d|||f�dS)NzI don't like spam!zExpected exceptionr ztest_asyncore.py�test_compact_tracebackz
[%s|%s|%s]���)
r�sys�exc_inforZcompact_traceback�failr?�os�path�split)rZreal_tZreal_vZreal_tbr1�fZfunction�line�t�v�infor	r	r
rV�s
 z*HelperFunctionTests.test_compact_tracebackN)
rrrrB�unittest�
skipUnless�hasattrr&rJrLrMrKrVr	r	r	r
r<bs'<r<c@speZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dS)�DispatcherTestscCsdS)Nr	)rr	r	r
�setUp�szDispatcherTests.setUpcCstj�dS)N)rrQ)rr	r	r
�tearDown�szDispatcherTests.tearDowncCs<tj�}|j|j�d�|j|j�d�dS)NT)r�
dispatcherr?�readable�writable)r�dr	r	r
�
test_basic�szDispatcherTests.test_basiccCs0tj�}|jt|�dt|��dS)Nz<asyncore.dispatcher at %#x>)rrir?�repr�id)rrlr	r	r
�	test_repr�szDispatcherTests.test_reprcCs|tj�}d}d}tj��!}|j|�|j|�WdQRX|j�j�}|j|d|d|g�dS)NzLovely spam! Wonderful spam!zI don't like spam!zlog: %s)rrirZcaptured_stderr�log�getvalue�
splitlinesr?)rrl�l1�l2�stderr�linesr	r	r
�test_log�s
zDispatcherTests.test_logcCs�tj�}d}d}d}tj��4}|j|d�|j|�|j|d�WdQRX|j�j�}d|d|d|g}|j||�dS)	Nz#Have you got anything without spam?z.Why can't she have egg bacon spam and sausage?zTHAT'S got spam in it!ZEGGSZSPAMzEGGS: %szinfo: %szSPAM: %s)rrir�captured_stdoutZlog_inforrrsr?)rrlrtru�l3�stdoutrwrGr	r	r
�
test_log_info
s
zDispatcherTests.test_log_infocCs�tj�}f|_tj��/}|j�|j�|j�|j�WdQRX|j	�j
�}ddddg}|j||�dS)Nz*warning: unhandled incoming priority eventzwarning: unhandled read eventzwarning: unhandled write eventz warning: unhandled connect event)rriZignore_log_typesrry�handle_expt�handle_read�handle_write�handle_connectrrrsr?)rrlr{rwrGr	r	r
�test_unhandleds	


	zDispatcherTests.test_unhandledcCsctjtj�}ttd�r=|j|tjtj��tjd�}|j|dk�dS)N�strerrorr �rW)	rZ	_strerror�errnoZEPERMrer[r?r��
assertTrue)r�errr	r	r
�
test_strerror,s
zDispatcherTests.test_strerrorN)rrrrgrhrmrprxr|r�r�r	r	r	r
rf�s
rfc@s(eZdZdd�Zdd�ZdS)�dispatcherwithsend_noreadcCsdS)NFr	)rr	r	r
rj6sz"dispatcherwithsend_noread.readablecCsdS)Nr	)rr	r	r
r�9sz(dispatcherwithsend_noread.handle_connectN)rrrrjr�r	r	r	r
r�5sr�c@sOeZdZdd�Zdd�Zejed�ej	dd���Z
dS)	�DispatcherWithSendTestscCsdS)Nr	)rr	r	r
rg>szDispatcherWithSendTests.setUpcCstj�dS)N)rrQ)rr	r	r
rhAsz DispatcherWithSendTests.tearDownz!Threading required for this test.c
Csmtj�}tj�}|jd�tj|�}t�}|||f}tjdtd|�}|j	�z�t
jd�d}t�}|j
�|jtj|f�t
jd�|j|�|j|�|jd�d}	x-|jr|	d	krtj�|	d
8}	q�W|j�|j|j�|d�Wd|jdt�|j�rh|jd
�XdS)Nr�target�argsg�������?s$Suppose there isn't a 16-ton weight?g�������?s
i�rr �r$zjoin() timed out)�	threadingZEventr�
settimeoutrZ	bind_portr�Threadr5r0r%r*r��
create_socket�connect�HOST�sendZ
out_bufferrrC�waitr?rr�join�TIMEOUT�is_aliverZ)
rr,r:�portZcapr�r`r4rlr/r	r	r
�	test_sendDs6
	

	






z!DispatcherWithSendTests.test_sendN)rrrrgrhrcrdr�r�reap_threadsr�r	r	r	r
r�=sr��file_wrapperzasyncore.file_wrapper requiredc@seZdZdd�Zdd�Zdd�Zdd�Zeje	e
d	�d
�dd��Zd
d�Zdd�Z
dS)�FileWrapperTestc	Cs9d|_ttjd��}|j|j�WdQRXdS)NsIt's not dead, it's sleeping!�wb)rl�openr�TESTFNr()r�filer	r	r
rgrs	zFileWrapperTest.setUpcCstjtj�dS)N)rr8r�)rr	r	r
rhwszFileWrapperTest.tearDowncCs�tjtjtj�}tj|�}tj|�|j|j	|�|j|j
�|�|j|jd�d�|j|j
d�d�|j�|jt|j
d�dS)N�
s
It's not dead�s, it'sr )r[r�rr��O_RDONLYrr�rZassertNotEqual�fdrr?r'r>r=�OSError)rr�r2r	r	r
�	test_recvzs

zFileWrapperTest.test_recvcCs�d}d}tjtjtjtjB�}tj|�}tj|�|j	|�|j
|�|j�ttjd��(}|j|j�|j
||�WdQRXdS)NsCome again?sI want to buy some cheese.�rb)r[r�rr��O_WRONLY�O_APPENDrr�rr(r�r?r>rl)rZd1Zd2r�r2r�r	r	r
r��s



zFileWrapperTest.test_send�file_dispatcherz!asyncore.file_dispatcher requiredcs�tjtjtj�}g�G�fdd�dtj�}||�}tj|�tjdddddd�|j	d	j
��|j�dS)
Ncs"eZdZ�fdd�ZdS)z7FileWrapperTest.test_dispatcher.<locals>.FileDispatchercs�j|jd��dS)N�)rOr')r)r4r	r
r~�szCFileWrapperTest.test_dispatcher.<locals>.FileDispatcher.handle_readN)rrrr~r	)r4r	r
�FileDispatcher�sr�r$g{�G�z�?�use_pollT�countr�r")r[r�rr�r�rr�r�loopr?r�rl)rr�r��sr	)r4r
�test_dispatcher�s
zFileWrapperTest.test_dispatcherc	Csetjtjtj�}tj|�}tj|�tjdt	f��d}tj
�WdQRXdS)Nr�)r[r�rr�r�rr�rZcheck_warnings�ResourceWarningZ
gc_collect)rr�r^r	r	r
�test_resource_warning�s
z%FileWrapperTest.test_resource_warningcCs_tjtjtj�}tj|�}tj|�|j�|j|j	d�|j�dS)Nr rW)
r[r�rr�r�rr�rr?r�)rr�r^r	r	r
�test_close_twice�s

z FileWrapperTest.test_close_twiceN)rrrrgrhr�r�rcrdrerr�r�r�r	r	r	r
r�os

r�c@sgeZdZddd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dS)�BaseTestHandlerNcCs tjj||�d|_dS)NF)rrirrH)rr:r	r	r
r�szBaseTestHandler.__init__cCstd��dS)Nz'handle_accept not supposed to be called)r)rr	r	r
�
handle_accept�szBaseTestHandler.handle_acceptcCstd��dS)Nz)handle_accepted not supposed to be called)r)rr	r	r
�handle_accepted�szBaseTestHandler.handle_acceptedcCstd��dS)Nz(handle_connect not supposed to be called)r)rr	r	r
r��szBaseTestHandler.handle_connectcCstd��dS)Nz%handle_expt not supposed to be called)r)rr	r	r
r}�szBaseTestHandler.handle_exptcCstd��dS)Nz&handle_close not supposed to be called)r)rr	r	r
r�szBaseTestHandler.handle_closecCs�dS)Nr	)rr	r	r
r�szBaseTestHandler.handle_error)
rrrrr�r�r�r}rrr	r	r	r
r��sr�c@sOeZdZdZedd�Zedd��Zdd�Zdd	�Z	d
S)�
BaseServerzYA server which listens on an address and dispatches the
    connection to a handler.
    cCsQtjj|�|j|�|j�t|j|�|jd�||_dS)N�)	rrirr��set_reuse_addrr;rr#�handler)rr7r.r�r	r	r
r�s


zBaseServer.__init__cCs
|jj�S)N)r�getsockname)rr	r	r
�address�szBaseServer.addresscCs|j|�dS)N)r�)rr:r.r	r	r
r��szBaseServer.handle_acceptedcCs�dS)Nr	)rr	r	r
r�szBaseServer.handle_errorN)
rrr�__doc__r�r�propertyr�r�rr	r	r	r
r��s
r�c@s(eZdZdd�Zdd�ZdS)�
BaseClientcCs+tj|�|j|�|j|�dS)N)r�rr�r�)rr7r�r	r	r
r�s

zBaseClient.__init__cCsdS)Nr	)rr	r	r
r��szBaseClient.handle_connectN)rrrrr�r	r	r	r
r��sr�c@seZdZdd�Zddd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�Zej
ejjd�d�dd��Zdd�Zdd�Zdd�Zdd�Zd d!�Zejed"�ejd#d$���Zd%S)&�BaseTestAPIcCstj�dS)N)rrQ)rr	r	r
rh�szBaseTestAPI.tearDownr�cCs�t|�d}d}x\tjrt|dkrttjddddd|j�|jrZdS|d8}tj|�qW|jd�dS)	N�drr$g{�G�z�?r�r r�zflag not set)	�floatrrPr�r�rHr%r*rZ)r�instancer$r�r	r	r
�loop_waiting_for_flag�s	
z!BaseTestAPI.loop_waiting_for_flagcCsQGdd�dt�}t|j|j�}||j|j�}|j|�dS)Nc@seZdZdd�ZdS)z3BaseTestAPI.test_handle_connect.<locals>.TestClientcSs
d|_dS)NT)rH)rr	r	r
r�szBBaseTestAPI.test_handle_connect.<locals>.TestClient.handle_connectN)rrrr�r	r	r	r
�
TestClientsr�)r�r�r7r.r�r�)rr��server�clientr	r	r
�test_handle_connectszBaseTestAPI.test_handle_connectcCsQGdd�dt�}||j|j�}t|j|j�}|j|�dS)Nc@s(eZdZdd�Zdd�ZdS)z4BaseTestAPI.test_handle_accept.<locals>.TestListenercSsMtj|�|j|�t|j|�|jd�|jj�|_dS)Nr�)r�rr�r;rr#r�r�)rr7r.r	r	r
rs



z=BaseTestAPI.test_handle_accept.<locals>.TestListener.__init__cSs
d|_dS)NT)rH)rr	r	r
r�szBBaseTestAPI.test_handle_accept.<locals>.TestListener.handle_acceptN)rrrrr�r	r	r	r
�TestListenersr�)r�r7r.r�r�r�)rr�r�r�r	r	r
�test_handle_acceptszBaseTestAPI.test_handle_acceptcCsQGdd�dt�}||j|j�}t|j|j�}|j|�dS)Nc@s4eZdZdd�Zdd�Zdd�ZdS)z6BaseTestAPI.test_handle_accepted.<locals>.TestListenercSsMtj|�|j|�t|j|�|jd�|jj�|_dS)Nr�)r�rr�r;rr#r�r�)rr7r.r	r	r
r$s



z?BaseTestAPI.test_handle_accepted.<locals>.TestListener.__init__cSstjj|�dS)N)rrir�)rr	r	r
r�+szDBaseTestAPI.test_handle_accepted.<locals>.TestListener.handle_acceptcSs|j�d|_dS)NT)rrH)rr:r.r	r	r
r�.s
zFBaseTestAPI.test_handle_accepted.<locals>.TestListener.handle_acceptedN)rrrrr�r�r	r	r	r
r�"sr�)r�r7r.r�r�r�)rr�r�r�r	r	r
�test_handle_acceptedsz BaseTestAPI.test_handle_acceptedcCsjGdd�dt�}Gdd�dt�}t|j|j|�}||j|j�}|j|�dS)Nc@seZdZdd�ZdS)z0BaseTestAPI.test_handle_read.<locals>.TestClientcSs
d|_dS)NT)rH)rr	r	r
r~;sz<BaseTestAPI.test_handle_read.<locals>.TestClient.handle_readN)rrrr~r	r	r	r
r�:sr�c@seZdZdd�ZdS)z1BaseTestAPI.test_handle_read.<locals>.TestHandlercSs%tj||�|jdd�dS)N�xi)r�rr�)rr-r	r	r
r?sz:BaseTestAPI.test_handle_read.<locals>.TestHandler.__init__N)rrrrr	r	r	r
�TestHandler>sr�)r�r�r�r7r.r�r�)rr�r�r�r�r	r	r
�test_handle_read7s
zBaseTestAPI.test_handle_readcCsQGdd�dt�}t|j|j�}||j|j�}|j|�dS)Nc@seZdZdd�ZdS)z1BaseTestAPI.test_handle_write.<locals>.TestClientcSs
d|_dS)NT)rH)rr	r	r
rKsz>BaseTestAPI.test_handle_write.<locals>.TestClient.handle_writeN)rrrrr	r	r	r
r�Jsr�)r�r�r7r.r�r�)rr�r�r�r	r	r
�test_handle_writeGszBaseTestAPI.test_handle_writecCsjGdd�dt�}Gdd�dt�}t|j|j|�}||j|j�}|j|�dS)Nc@s(eZdZdd�Zdd�ZdS)z1BaseTestAPI.test_handle_close.<locals>.TestClientcSs|jd�dS)Ni)r')rr	r	r
r~Xsz=BaseTestAPI.test_handle_close.<locals>.TestClient.handle_readcSsd|_|j�dS)NT)rHr)rr	r	r
r]s	z>BaseTestAPI.test_handle_close.<locals>.TestClient.handle_closeN)rrrr~rr	r	r	r
r�Vsr�c@seZdZdd�ZdS)z2BaseTestAPI.test_handle_close.<locals>.TestHandlercSstj||�|j�dS)N)r�rr)rr-r	r	r
rbsz;BaseTestAPI.test_handle_close.<locals>.TestHandler.__init__N)rrrrr	r	r	r
r�asr�)r�r�r�r7r.r�r�)rr�r�r�r�r	r	r
�test_handle_closeRs
zBaseTestAPI.test_handle_closecs�dd�G�fdd�dt�}G�fdd�dt�}t|j|j|�}||j|j�}|j|�dS)Ns�cs:eZdZ�fdd�Zdd�Zdd�ZdS)zCBaseTestAPI.test_handle_close_after_conn_broken.<locals>.TestClientcs|j��dS)N)r�)r)r4r	r
rrszPBaseTestAPI.test_handle_close_after_conn_broken.<locals>.TestClient.handle_writecSsd|_|j�dS)NT)rHr)rr	r	r
rus	zPBaseTestAPI.test_handle_close_after_conn_broken.<locals>.TestClient.handle_closecSsd|_|j�dS)NT)rHr)rr	r	r
r}ys	zOBaseTestAPI.test_handle_close_after_conn_broken.<locals>.TestClient.handle_exptN)rrrrrr}r	)r4r	r
r�psr�cs.eZdZ�fdd�Zdd�ZdS)zDBaseTestAPI.test_handle_close_after_conn_broken.<locals>.TestHandlercs!|jt���|j�dS)N)r'rRr)r)r4r	r
r~szPBaseTestAPI.test_handle_close_after_conn_broken.<locals>.TestHandler.handle_readcSsdS)NFr	)rr	r	r
rk�szMBaseTestAPI.test_handle_close_after_conn_broken.<locals>.TestHandler.writableN)rrrr~rkr	)r4r	r
r�}sr�)r�r�r�r7r.r�r�)rr�r�r�r�r	)r4r
�#test_handle_close_after_conn_brokenjs

	z/BaseTestAPI.test_handle_close_after_conn_broken�sunosz OOB support is broken on SolariscCs�tr%|jtjkr%|jd�tjdkrJ|jrJ|jd�Gdd�dt�}Gdd�dt	�}t
|j|j|�}||j|j�}|j
|�dS)Nz"Not applicable to AF_UNIX sockets.�darwinz(poll may fail on macOS; see issue #28087c@seZdZdd�ZdS)z0BaseTestAPI.test_handle_expt.<locals>.TestClientcSs#|jjdtj�d|_dS)NiT)rr'�MSG_OOBrH)rr	r	r
r}�sz<BaseTestAPI.test_handle_expt.<locals>.TestClient.handle_exptN)rrrr}r	r	r	r
r��sr�c@seZdZdd�ZdS)z1BaseTestAPI.test_handle_expt.<locals>.TestHandlercSs9tj||�|jjttd�d�tj�dS)N��zlatin-1)r�rrr��bytes�chrr�)rr-r	r	r
r�sz:BaseTestAPI.test_handle_expt.<locals>.TestHandler.__init__N)rrrrr	r	r	r
r��sr�)r6r7rr�skipTestrX�platformr�r�r�r�r.r�r�)rr�r�r�r�r	r	r
�test_handle_expt�s

zBaseTestAPI.test_handle_exptcCsQGdd�dt�}t|j|j�}||j|j�}|j|�dS)Nc@s(eZdZdd�Zdd�ZdS)z1BaseTestAPI.test_handle_error.<locals>.TestClientcSsdddS)Ng�?rr	)rr	r	r
r�sz>BaseTestAPI.test_handle_error.<locals>.TestClient.handle_writecSs5d|_y�Wntk
r$Yn
Xtd��dS)NTzexception not raised)rH�ZeroDivisionErrorr)rr	r	r
r�s	
z>BaseTestAPI.test_handle_error.<locals>.TestClient.handle_errorN)rrrrrr	r	r	r
r��sr�)r�r�r7r.r�r�)rr�r�r�r	r	r
�test_handle_error�szBaseTestAPI.test_handle_errorcCs1t|j|j�}t|j|j�}|j|j�|j|j�|j|j�t	j
ddd|jdd�|j|j�|j|j�|j|j�|j|j�|j�|j|j�|j|j�|j|j�|j|j�|j�|j|j�|j|j�dS)Nr$g{�G�z�?r�r�r�)
r�r7r.r�r��assertFalseZ	connectedr�Z	acceptingrr�r�r)rr�r�r	r	r
�test_connection_attributes�s$

z&BaseTestAPI.test_connection_attributescCs�tj�}|j|j�|j|jj|j�ttdd�}tj|B}ttd�r�|j	|jj
|tjB|f�n|j|jj
|�dS)N�
SOCK_NONBLOCKr�SOCK_CLOEXEC)rrir�r7r?rrF�SOCK_STREAMreZassertIn�typer�)rr�r�Z	sock_typer	r	r
�test_create_socket�s
zBaseTestAPI.test_create_socketcCs�tr%|jtjkr%|jd�tj�}|j|j�|j|j	�|j
d�|jj�d}tj�}|j|j�|jt
|j|j	d|f�dS)Nz"Not applicable to AF_UNIX sockets.r�r r)r6r7rrr�rrir�r9r.r#r�r=r�)r�s1r��s2r	r	r
�	test_bind�s

zBaseTestAPI.test_bindcCstr%|jtjkr%|jd�tj|j�}z�y|jtjtjd�Wntk
rxt	j
d�Yn�Xtjtj|j��}|j
|jjtjtj��|jj�|j|j�|j�|j|jjtjtj��Wd|j�XdS)Nz"Not applicable to AF_UNIX sockets.r z+SO_REUSEADDR not supported on this platform)r6r7rrr��
setsockopt�
SOL_SOCKETZSO_REUSEADDRr�rc�skiprrir�Z
getsockoptrr�r�r�)rr:r�r	r	r
�test_set_reuse_addr�s 




zBaseTestAPI.test_set_reuse_addrz!Threading required for this test.cs�jtjttdt��fkrt�j�j�}tjddd����j	���fdd�}�j
|�tj�jtj�}|jd�|j
tjtjtjdd	d
��z-y|j|j�Wntk
r�YnXWd|j�XdS)N�AF_INET6r�cSstjdddd�S)Nr$g�������?r�i�)rr�r	r	r	r
�<lambda>
sz0BaseTestAPI.test_quick_connect.<locals>.<lambda>cs-�jdt��j�r)�jd�dS)Nr$zjoin() timed out)r�r�r�rZr	)rr`r	r
�cleanup
sz/BaseTestAPI.test_quick_connect.<locals>.cleanupg�������?Ziir r)r7r�AF_INETrF�objectr�r.r�r�r0Z
addCleanupr�r�r�r�Z	SO_LINGER�structZpackr�r�r�r)rr�r�r�r	)rr`r
�test_quick_connects'



	zBaseTestAPI.test_quick_connectN)rrrrhr�r�r�r�r�r�r�r�rcZskipIfrXr��
startswithr�r�r�r�r�r�rdr�rr�r�r	r	r	r
r��s$ r�c@s(eZdZejZejdfZdS)�TestAPI_UseIPv4SocketsrN)	rrrrr�r7rr�r.r	r	r	r
r�s	r�zIPv6 support requiredc@s(eZdZejZejdfZdS)�TestAPI_UseIPv6SocketsrN)	rrrrr�r7rZHOSTv6r.r	r	r	r
r�"s	r�zUnix sockets requiredc@s4eZdZerejZejZ	dd�Z
dS)�TestAPI_UseUnixSocketscCs!tj|j�tj|�dS)N)rr8r.r�rh)rr	r	r
rh-szTestAPI_UseUnixSockets.tearDownN)rrrr6rrr7rr�r.rhr	r	r	r
r�'s		r�c@seZdZdZdS)�TestAPI_UseIPv4SelectFN)rrrr�r	r	r	r
r�1sr�rCzselect.poll requiredc@seZdZdZdS)�TestAPI_UseIPv4PollTN)rrrr�r	r	r	r
r�4sr�c@seZdZdZdS)�TestAPI_UseIPv6SelectFN)rrrr�r	r	r	r
r�8sr�c@seZdZdZdS)�TestAPI_UseIPv6PollTN)rrrr�r	r	r	r
r�;sr�c@seZdZdZdS)�TestAPI_UseUnixSocketsSelectFN)rrrr�r	r	r	r
r�?sr�c@seZdZdZdS)�TestAPI_UseUnixSocketsPollTN)rrrr�r	r	r	r
r�Bsr��__main__)1rrcr&r[rrXr%r�r�Ztestr�iorr��ImportErrorr�rer6rrrrr5r;ZTestCaser<rfZdispatcher_with_sendr�r�rdr�rir�r�r�r�r�ZIPV6_ENABLEDr�r�r�r�r�r�r�r�r�mainr	r	r	r
�<module>sd

�H2D�.	%%%