Your IP : 216.73.216.85


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



��Yf-�
@s�ddlmZejd�ZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZ
yddl
Z
Wnek
r�dZ
YnXejZdZdZe
rGdd�de
j�ZGdd	�d	ej�Zd
d�Ze
je
d�Gd
d�de
j��ZGdd�de�ZGdd�de
j�ZGdd�de
j�ZGdd�de
j�ZGdd�de
j�Zedkr�e
j �dS)�)�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/python35/lib64/python3.5/test/test_asynchat.pyr s
	zecho_server.__init__c
Cs|jj�|jj�|jj�\}}d|_x9t|jkrs|jd�}|s`P|j||_q;W|jjtd�|_|j	r�|j	j
�yVxO|jr�|j|jd|j��}t
jd�|j|d�|_q�WWnYnX|j�|jj�dS)N�rg����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
dkrdd�}dS)NrcSsdS)Nr)rrrr�handle_connectSsz,echo_client.__init__.<locals>.handle_connect�darwincSsdS)Nr)rrrr�handle_exptYsz)echo_client.__init__.<locals>.handle_expt)�asynchat�
async_chatr�contentsZ
create_socketr
rrZconnect�HOST�set_terminatorr�sys�platform)r�
terminatorZserver_portr'r)rrrrKs	
	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%rr2r4rrrrr&Isr&cCsMtj�}t|�}|j�|j�|j�tjd�||fS)Ng{�G�z�?)r�Eventr�startr�clearrr)r	�srrr�start_echo_servercs



r9z!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�setUpqszTestAsynchat.setUpcCstj|j�dS)N)rZthreading_cleanupr;)rrrr�tearDowntszTestAsynchat.tearDowncCs�tj�}t|�}||_|j�|j�|j�tjd�t	||j
�}|jd�|jd|�|jd|�|jt�t
jd|jdddd�|jdt�|j�r�|jd	�|j|jd
dg�dS)Ng{�G�z�?shello sworldsI'm not dead yet!�use_poll�counti,�timeoutzjoin() timed outshello world)rr5rrr6rr7rrr&r�pushr�asyncore�loop�usepoll�join�TIMEOUT�is_alive�fail�assertEqualr,)rZtermZserver_chunkr	r8�crrr�line_terminator_checkws"	






z"TestAsynchat.line_terminator_checkcCs%xdD]}|jd|�qWdS)Nr��s
)rrLrM)rK)r�lrrr�test_line_terminator1�s
z"TestAsynchat.test_line_terminator1cCs%xdD]}|jd|�qWdS)NrrLrMs
)rrLrM)rK)rrNrrr�test_line_terminator2�s
z"TestAsynchat.test_line_terminator2cCs%xdD]}|jd|�qWdS)NrrLrMsqqq)rrLrM)rK)rrNrrr�test_line_terminator3�s
z"TestAsynchat.test_line_terminator3cCs�t�\}}t||j�}d}|j|�|jt�tjd|jdddd�|jdt	�|j
�r�|jd�|j|j
|d|�g�dS)Nshello world, I'm not dead yet!
r>r?i,r@g{�G�z�?zjoin() timed out)r9r&rrArrBrCrDrErFrGrHrIr,)rZtermlenr8r	rJr rrr�numeric_terminator_check�s


z%TestAsynchat.numeric_terminator_checkcCs|jd�dS)Nr)rR)rrrr�test_numeric_terminator1�sz%TestAsynchat.test_numeric_terminator1cCs|jd�dS)N�)rR)rrrr�test_numeric_terminator2�sz%TestAsynchat.test_numeric_terminator2cCs�t�\}}td|j�}d}|j|�|jt�tjd|jdddd�|jdt	�|j
�r�|jd�|j|j
g�|j|j|�dS)Nshello world, I'm not dead yet!
r>r?i,r@g{�G�z�?zjoin() timed out)r9r&rrArrBrCrDrErFrGrHrIr,r)rr8r	rJr 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
�|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!)r9r&rr*Zsimple_producerr�push_with_producerrBrCrDrErFrGrHrIr,)rr8r	rJr �prrr�test_simple_producer�s

z!TestAsynchat.test_simple_producercCs�t�\}}td|j�}d}|j|t�tjd|jdddd�|jdt	�|j
�r�|jd�|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!)r9r&rrXrrBrCrDrErFrGrHrIr,)rr8r	rJr rrr�test_string_producer�s
z!TestAsynchat.test_string_producercCs�t�\}}td|j�}|jd�|jt�tjd|jdddd�|jdt	�|j
�r�|jd�|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!)r9r&rrArrBrCrDrErFrGrHrIr,)rr8r	rJrrr�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�|j|jg�|jt|j�d	�dS)
Ns
shello world
I'm not dead yet!
r>r?i,r@g{�G�z�?zjoin() timed outr)r9rr5rr&rrArZclose_when_donerBrCrDrrErFrGrHrIr,Z
assertGreater�lenr)rr8r	rJrrr�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)r9r&rrA�	bytearray�
memoryview�assertRaises�	TypeErrorrrBrCrDrErFrIr,)rr8r	rJr rrr�	test_pushs

zTestAsynchat.test_pushN)r#r$r%rDr<r=rKrOrPrQrRrSrUrVrZr[r\r^rdrrrrr:ms 
r:c@seZdZdZdS)�TestAsynchat_WithPollTN)r#r$r%rDrrrrresrec@seZdZdd�ZdS)�TestAsynchatMockedc	Cs�tjj�}ttj�|j_tj	�}|j
|�|j|j�tjj
j|d��}|j�WdQRX|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%rlrrrrrfsrfc@seZdZdd�ZdS)�TestHelperFunctionscCs<|jtjdd�d�|jtjdd�d�dS)Nzqwerty
z
rZ
qwertydkjfr)rIr*Zfind_prefix_at_end)rrrr�test_find_prefix_at_end'sz+TestHelperFunctions.test_find_prefix_at_endN)r#r$r%rnrrrrrm&srmc@s(eZdZdd�Zdd�ZdS)�TestFifocCs8|jt��}tj�}WdQRX|jt|j�d�|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)Nz(fifo class will be removed in Python 3.6��arLrFrT)rrp)rrq)rN)�assertWarns�DeprecationWarningr*�fiforI�str�warningrAr]�first�popZis_empty)r�cm�frrr�
test_basic-s 

zTestFifo.test_basiccCs�|jt��}tjdddg�}WdQRX|jt|j�d�|jt|�d�|j|j�d�|j|j�d�|j|j�d	�|j|j�d
�dS)N�x�rMz(fifo class will be removed in Python 3.6rr)rr|)rr})rrM)rN)	rrrsr*rtrIrurvr]rx)rryrzrrr�test_given_list?szTestFifo.test_given_listN)r#r$r%r{r~rrrrro,sroc@seZdZdd�ZdS)�TestNotConnectedcCs&tj�}|jt|jd�dS)Nr���)r*r+rb�
ValueErrorr.)rrrrr�!test_disallow_negative_terminatorLsz2TestNotConnected.test_disallow_negative_terminatorN)r#r$r%r�rrrrrKsr�__main__)!Ztestr�
import_moduleZthreadr*rBrir
r/rrg�warningsZ
unittest.mockr�ImportErrorr-rrFrrr+r&r9Z
skipUnlessZTestCaser:rerfrmrorr#�mainrrrr�<module>s<
	.
�