Your IP : 216.73.216.196


Current Path : /opt/alt/python310/lib64/python3.10/test/__pycache__/
Upload File :
Current File : //opt/alt/python310/lib64/python3.10/test/__pycache__/test_asynchat.cpython-310.pyc

o

0�i�%�@sNddlmZddlmZddlmZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZ
ddlZe�
��e�de�ddlZddlZWd�n1sOwYejZdZGdd�dej�ZGd	d
�d
ej�Zdd�ZGd
d�de
j�ZGdd�de�ZGdd�de
j�ZGdd�de
j�ZGdd�de
j�Zedkr�e
� �dSdS)�)�support)�
socket_helper)�threading_helperN�ignoresQUIT
c@s eZdZdZdd�Zdd�ZdS)�echo_server�cCs<tj�|�||_t�tjtj�|_t�	|j�|_
d|_dS�N)�	threading�Thread�__init__�event�socket�AF_INET�SOCK_STREAM�sockrZ	bind_port�port�start_resend_event)�selfr�r�9/opt/alt/python310/lib64/python3.10/test/test_asynchat.pyrs

zecho_server.__init__cCs�|j��|j��|j��\}}d|_t|jvr,|�d�}|s!n|j||_t|jvs|j�td�|_|j	r<|j	�
�z |jr[|�|jd|j��}t
�d�|j|d�|_|js@WnY|��|j��dS)N�rg����MbP?)rZlistenr�setZaccept�buffer�SERVER_QUIT�recv�replacer�wait�send�
chunk_size�time�sleep�close)rZconn�client�data�nrrr�run's0




�

��zecho_server.runN)�__name__�
__module__�__qualname__rrr%rrrrrs	rc@s>eZdZdd�Zdd�Zejdkrdd�Zdd	�Zd
d�Z	dS)
�echo_clientcCsDtj�|�g|_|�tjtj�|�t	|f�|�
|�d|_dS�Nr)�asynchat�
async_chatr�contentsZ
create_socketr
rrZconnect�HOST�set_terminatorr)r�
terminatorZserver_portrrrrIs

zecho_client.__init__cC�dSrr�rrrr�handle_connectQ�zecho_client.handle_connect�darwincCr1rrr2rrr�handle_exptWr4zecho_client.handle_exptcCs|j|7_dSr)r)rr#rrr�collect_incoming_dataZsz!echo_client.collect_incoming_datacCs|j�|j�d|_dSr*)r-�appendrr2rrr�found_terminator]s
zecho_client.found_terminatorN)
r&r'r(rr3�sys�platformr6r7r9rrrrr)Gs
r)cCs:t��}t|�}|��|��|��t�d�||fS)N�{�G�z�?)r	�Eventr�startr�clearrr )r�srrr�start_echo_serveras
rAc@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zd S)!�TestAsynchatFcCst��|_dSr)rZthreading_setup�_threadsr2rrr�setUpn�zTestAsynchat.setUpcCstj|j�dSr)rZthreading_cleanuprCr2rrr�tearDownqszTestAsynchat.tearDowncCs�t��}t|�}||_|��|��|��t�d�t	||j
�}|�d�|�d|�|�d|�|�t�t
j|jddd�t�|�|�|jddg�dS)Nr<shello sworld�I'm not dead yet!�,�Zuse_poll�countZtimeout�hello world)r	r=rrr>rr?rr r)r�pushr�asyncore�loop�usepollr�join_thread�assertEqualr-)rZtermZserver_chunkrr@�crrr�line_terminator_checkts



z"TestAsynchat.line_terminator_checkcC�dD]}|�d|�qdS)N�r���
�rS�r�lrrr�test_line_terminator1���z"TestAsynchat.test_line_terminator1cCrT)NrUs
rYrZrrr�test_line_terminator2�r]z"TestAsynchat.test_line_terminator2cCrT)NrUsqqqrYrZrrr�test_line_terminator3�r]z"TestAsynchat.test_line_terminator3cCsft�\}}t||j�}d}|�|�|�t�tj|jddd�t�	|�|�
|j|d|�g�dS�Nshello world, I'm not dead yet!
rHr<rI�rAr)rrLrrMrNrOrrPrQr-)rZtermlenr@rrRr#rrr�numeric_terminator_check�s



z%TestAsynchat.numeric_terminator_checkcC�|�d�dS)Nr�rbr2rrr�test_numeric_terminator1�sz%TestAsynchat.test_numeric_terminator1cCrc)N�rdr2rrr�test_numeric_terminator2�rEz%TestAsynchat.test_numeric_terminator2cCsjt�\}}td|j�}d}|�|�|�t�tj|jddd�t�	|�|�
|jg�|�
|j|�dSr`)
rAr)rrLrrMrNrOrrPrQr-r�rr@rrRr#rrr�test_none_terminator�s



z!TestAsynchat.test_none_terminatorcCsht�\}}td|j�}d}tj|tdd�}|�|�tj|j	ddd�t
�|�|�|j
dd	g�dS)
NrX�hello world
I'm not dead yet!
�)Zbuffer_sizerHr<rIrKrG)rAr)rr+Zsimple_producerr�push_with_producerrMrNrOrrPrQr-)rr@rrRr#�prrr�test_simple_producer�s


z!TestAsynchat.test_simple_producercCsZt�\}}td|j�}d}|�|t�tj|jddd�t�	|�|�
|jddg�dS)NrXrjrHr<rIrKrG)rAr)rrlrrMrNrOrrPrQr-rhrrr�test_string_producer�s

z!TestAsynchat.test_string_producercCs\t�\}}td|j�}|�d�|�t�tj|jddd�t�	|�|�
|jgd��dS)NrXshello world

I'm not dead yet!
rHr<rI)rKrrGra�rr@rrRrrr�test_empty_line�s



�zTestAsynchat.test_empty_linecCs�t�\}}t��|_td|j�}|�d�|�t�|��t	j
|jddd�|j��t
�|�|�|jg�|�t|j�d�dS)NrXrjrHr<rIr)rAr	r=rr)rrLrZclose_when_donerMrNrOrrrPrQr-Z
assertGreater�lenrrprrr�test_close_when_done�s





z!TestAsynchat.test_close_when_donecCs�t�\}}td|j�}d}|�|�|�t|��|�t|��|�t|jd�|�t|jd�|�t�t	j
|jddd�t�
|�|�|jgd��dS)	NrXsbytes
�
ZunicoderHr<rI)�bytesruru)rAr)rrL�	bytearray�
memoryview�assertRaises�	TypeErrorrrMrNrOrrPrQr-rhrrr�	test_push�s



zTestAsynchat.test_pushN)r&r'r(rOrDrFrSr\r^r_rbrergrirnrorqrsrzrrrrrBks"

rBc@seZdZdZdS)�TestAsynchat_WithPollTN)r&r'r(rOrrrrr{sr{c@�eZdZdd�ZdS)�TestAsynchatMockedcCs~tj��}ttj�|j_t�	�}|�
|�|�|j�tjj
�|d��}|��Wd�n1s2wY|�|j�dS)NZhandle_error)�unittestZmockZMock�BlockingIOError�errnoZEAGAINrZside_effectr+r,Z
set_socketZ
addCleanupZdel_channelZpatch�objectZhandle_readZassertFalseZcalled)rr�
dispatcher�errorrrr�test_blockingioerrors


�z'TestAsynchatMocked.test_blockingioerrorN)r&r'r(r�rrrrr}�r}c@r|)�TestHelperFunctionscCs,|�t�dd�d�|�t�dd�d�dS)Nzqwerty
z
rZ
qwertydkjfr)rQr+Zfind_prefix_at_endr2rrr�test_find_prefix_at_endsz+TestHelperFunctions.test_find_prefix_at_endN)r&r'r(r�rrrrr�r�r�c@r|)�TestNotConnectedcCst��}|�t|jd�dS)N���)r+r,rx�
ValueErrorr/)rr"rrr�!test_disallow_negative_terminatorsz2TestNotConnected.test_disallow_negative_terminatorN)r&r'r(r�rrrrr�r�r��__main__)!�testrZtest.supportrrr�r
r:r	rr~Z
unittest.mock�warnings�catch_warnings�simplefilter�DeprecationWarningr+rMr.rr
rr,r)rAZTestCaserBr{r}r�r�r&�mainrrrr�<module>s<

�.
�