Your IP : 216.73.216.213


Current Path : /proc/242857/root/opt/alt/python34/lib64/python3.4/test/__pycache__/
Upload File :
Current File : //proc/242857/root/opt/alt/python34/lib64/python3.4/test/__pycache__/test_asynchat.cpython-34.pyc

�
g f�+�
@s�ddlmZejd�ZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZ
yddlZWne
k
r�dZYnXejZdZdZerGdd�dej�ZGdd	�d	ej�Zd
d�Zne
jed�Gd
d�de
j��ZGdd�de�ZGdd�de
j�ZGdd�de
j�ZGdd�de
j�ZGdd�de
j�Zedkr�e
j�ndS)�)�support�_threadNsQUIT
g@c@s.eZdZdZdd�Zdd�ZdS)�echo_server�cCsVtjj|�||_tjtjtj�|_tj	|j�|_
d|_dS)N)�	threading�Thread�__init__�event�socket�AF_INET�SOCK_STREAM�sockrZ	bind_port�port�start_resend_event)�selfr	�r�7/opt/alt/python34/lib64/python3.4/test/test_asynchat.pyrs
	zecho_server.__init__c
Cs'|jjd�|jj�|jj�\}}d|_x<t|jkry|jd�}|sfPn|j||_q>W|jjtd�|_|j	r�|j	j
�nyVxO|jr�|j|jd|j��}t
jd�|j|d�|_q�WWnYnX|j�|jj�dS)Nr�g����MbP?)r
Zlistenr	�setZaccept�buffer�SERVER_QUIT�recv�replacer�wait�send�
chunk_size�time�sleep�close)rZconn�client�data�nrrr�run(s*
		

zecho_server.runN)�__name__�
__module__�__qualname__rrr"rrrrrs	rc@s4eZdZdd�Zdd�Zdd�ZdS)�echo_clientcCs�tjj|�g|_|jtjtj�|jt	|f�|j
|�d|_dd�}tj
dkr�dd�}ndS)NrcSsdS)Nr)rrrr�handle_connectRsz,echo_client.__init__.<locals>.handle_connect�darwincSsdS)Nr)rrrr�handle_exptXsz)echo_client.__init__.<locals>.handle_expt)�asynchat�
async_chatr�contentsZ
create_socketr
rrZconnect�HOST�set_terminatorr�sys�platform)rZ
terminatorZserver_portr'r)rrrrJs	
	zecho_client.__init__cCs|j|7_dS)N)r)rr rrr�collect_incoming_data[sz!echo_client.collect_incoming_datacCs |jj|j�d|_dS)Nr)r,�appendr)rrrr�found_terminator^szecho_client.found_terminatorN)r#r$r%rr1r3rrrrr&Hsr&cCsMtj�}t|�}|j�|j�|j�tjd�||fS)Ng{�G�z�?)r�Eventr�startr�clearrr)r	�srrr�start_echo_serverbs



r8z!Threading required for this test.c@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zd S)!�TestAsynchatFcCstj�|_dS)N)rZthreading_setup�_threads)rrrr�setUppszTestAsynchat.setUpcCstj|j�dS)N)rZthreading_cleanupr:)rrrr�tearDownsszTestAsynchat.tearDowncCstj�}t|�}||_|j�|j�|j�tjd�t	||j
�}|jd�|jd|�|jd|�|jt�t
jd|jdddd�|jdt�|j�r�|jd	�n|j|jd
dg�dS)Ng{�G�z�?shello sworldsI'm not dead yet!�use_poll�counti,�timeoutzjoin() timed outshello world)rr4rrr5rr6rrr&r�pushr�asyncore�loop�usepoll�join�TIMEOUT�is_alive�fail�assertEqualr,)rZtermZserver_chunkr	r7�crrr�line_terminator_checkvs"	





z"TestAsynchat.line_terminator_checkcCs%xdD]}|jd|�qWdS)Nr��s
)rrKrL)rJ)r�lrrr�test_line_terminator1�s
z"TestAsynchat.test_line_terminator1cCs%xdD]}|jd|�qWdS)NrrKrLs
)rrKrL)rJ)rrMrrr�test_line_terminator2�s
z"TestAsynchat.test_line_terminator2cCs%xdD]}|jd|�qWdS)NrrKrLsqqq)rrKrL)rJ)rrMrrr�test_line_terminator3�s
z"TestAsynchat.test_line_terminator3cCs�t�\}}t||j�}d}|j|�|jt�tjd|jdddd�|jdt	�|j
�r�|jd�n|j|j
|d|�g�dS)Nshello world, I'm not dead yet!
r=r>i,r?g{�G�z�?zjoin() timed out)r8r&rr@rrArBrCrDrErFrGrHr,)rZtermlenr7r	rIr rrr�numeric_terminator_check�s

z%TestAsynchat.numeric_terminator_checkcCs|jd�dS)Nr)rQ)rrrr�test_numeric_terminator1�sz%TestAsynchat.test_numeric_terminator1cCs|jd�dS)N�)rQ)rrrr�test_numeric_terminator2�sz%TestAsynchat.test_numeric_terminator2cCs�t�\}}td|j�}d}|j|�|jt�tjd|jdddd�|jdt	�|j
�r�|jd�n|j|j
g�|j|j|�dS)Nshello world, I'm not dead yet!
r=r>i,r?g{�G�z�?zjoin() timed out)r8r&rr@rrArBrCrDrErFrGrHr,r)rr7r	rIr rrr�test_none_terminator�s

z!TestAsynchat.test_none_terminatorcCs�t�\}}td|j�}d}tj|tdd�}|j|�tjd|j	dddd	�|j
dt�|j�r�|j
d
�n|j|jddg�dS)
Ns
shello world
I'm not dead yet!
Zbuffer_size�r=r>i,r?g{�G�z�?zjoin() timed outshello worldsI'm not dead yet!)r8r&rr*Zsimple_producerr�push_with_producerrArBrCrDrErFrGrHr,)rr7r	rIr �prrr�test_simple_producer�s
z!TestAsynchat.test_simple_producercCs�t�\}}td|j�}d}|j|t�tjd|jdddd�|jdt	�|j
�r�|jd�n|j|j
d	d
g�dS)Ns
shello world
I'm not dead yet!
r=r>i,r?g{�G�z�?zjoin() timed outshello worldsI'm not dead yet!)r8r&rrWrrArBrCrDrErFrGrHr,)rr7r	rIr rrr�test_string_producer�sz!TestAsynchat.test_string_producercCs�t�\}}td|j�}|jd�|jt�tjd|jdddd�|jdt	�|j
�r�|jd�n|j|j
d	d
dg�dS)Ns
shello world

I'm not dead yet!
r=r>i,r?g{�G�z�?zjoin() timed outshello worldrsI'm not dead yet!)r8r&rr@rrArBrCrDrErFrGrHr,)rr7r	rIrrr�test_empty_line�s

zTestAsynchat.test_empty_linecCs�t�\}}tj�|_td|j�}|jd�|jt�|j�t	j
d|jdddd�|jj�|j
dt�|j�r�|jd�n|j|jg�|jt|j�d	�dS)
Ns
shello world
I'm not dead yet!
r=r>i,r?g{�G�z�?zjoin() timed outr)r8rr4rr&rr@rZclose_when_donerArBrCrrDrErFrGrHr,Z
assertGreater�lenr)rr7r	rIrrr�test_close_when_done�s



z!TestAsynchat.test_close_when_donecCs�t�\}}td|j�}d}|j|�|jt|��|jt|��|jt|jd�|jt|jd�|jt�t	j
d|jdddd	�|jdt
�|j|jd
d
d
g�dS)Ns
sbytes
�
Zunicoder=r>i,r?g{�G�z�?sbytes)r8r&rr@�	bytearray�
memoryview�assertRaises�	TypeErrorrrArBrCrDrErHr,)rr7r	rIr rrr�	test_pushs

zTestAsynchat.test_pushN)r#r$r%rCr;r<rJrNrOrPrQrRrTrUrYrZr[r]rcrrrrr9ls 
r9c@seZdZdZdS)�TestAsynchat_WithPollTN)r#r$r%rCrrrrrdsrdc@seZdZdd�ZdS)�TestAsynchatMockedcCs�tjj�}ttj�|j_tj	�}|j
|�|j|j�tjj
j|d��}|j�WdQX|j|j�dS)NZhandle_error)�unittestZmockZMock�BlockingIOError�errnoZEAGAINrZside_effectr*r+Z
set_socketZ
addCleanupZdel_channelZpatch�objectZhandle_readZassertFalseZcalled)rr
Z
dispatcher�errorrrr�test_blockingioerrors
z'TestAsynchatMocked.test_blockingioerrorN)r#r$r%rkrrrrresrec@seZdZdd�ZdS)�TestHelperFunctionscCs<|jtjdd�d�|jtjdd�d�dS)Nzqwerty
z
rZ
qwertydkjfr)rHr*Zfind_prefix_at_end)rrrr�test_find_prefix_at_end&sz+TestHelperFunctions.test_find_prefix_at_endN)r#r$r%rmrrrrrl%srlc@s(eZdZdd�Zdd�ZdS)�TestFifocCstj�}|jd�|jd�|jt|�d�|j|j�d�|j|j�d�|jt|�d�|j|j�d�|j|j�d�|j|j�d	�|jt|�d�|j|j�d�|j|j�d
�dS)N��arKrFrT)rro)rrp)rN)r*�fifor@rHr\�first�popZis_empty)r�frrr�
test_basic,s

zTestFifo.test_basiccCs�tjdddg�}|jt|�d�|j|j�d�|j|j�d�|j|j�d�|j|j�d	�dS)
N�x�rLrr)rrv)rrw)rrL)rN)r*rqrHr\rs)rrtrrr�test_given_list;szTestFifo.test_given_listN)r#r$r%rurxrrrrrn+srnc@seZdZdd�ZdS)�TestNotConnectedcCs&tj�}|jt|jd�dS)Nr���)r*r+ra�
ValueErrorr.)rrrrr�!test_disallow_negative_terminatorEsz2TestNotConnected.test_disallow_negative_terminatorN)r#r$r%r|rrrrryDsry�__main__) Ztestr�
import_moduleZthreadr*rArhr
r/rrfZ
unittest.mockr�ImportErrorr-rrErrr+r&r8Z
skipUnlessZTestCaser9rdrerlrnryr#�mainrrrr�<module>s:
	.
�