B
    ÐH/\Ï  ã               @   sŠ   d dl Z d dlZd dlmZ d dlmZmZmZ d dlmZ d dlmZ e	e dƒZ
e jd  dkZdd	„ ZG d
d„ deƒZedkr†eƒ  dS )é    N)Úsocket)ÚTestCaseÚmainÚtcp_listener)Ú
skipOnPyPy)ÚparamsZpypy_version_infoé   c             C   s@   y|   |¡}W n tk
r*   ts&t‚Y nX |d ks<t|ƒ‚d S )N)ÚwriteÚ
ValueErrorÚPY3ÚAssertionError)ÚfÚsÚr© r   ú9lib/python3.7/site-packages/gevent/tests/test__greenio.pyÚ_write_to_closed"   s
    r   c               @   s$   e Zd Zdd„ Zedƒdd„ ƒZdS )ÚTestGreenIoc                sl   ‡ fdd„}‡ fdd„}‡ fdd„}t ƒ }t ||¡}||ƒ | ¡  t ƒ }t ||¡}||ƒ | ¡  d S )Nc                sb   zR|   ¡ \}}|jdd}| ¡  | d¡ | ¡  t|dƒ ˆ  tj|jd¡ W d |  ¡  X d S )NÚwb)Úmodes   hello
ó   aó   b)	ÚacceptÚmakefileÚcloser	   r   ÚassertRaisesr   ÚerrorÚsend)ÚlistenerÚconnÚ_Úfd)Úselfr   r   Úaccept_close_early/   s    

z@TestGreenIo.test_close_with_makefile.<locals>.accept_close_earlyc                sl   z\|   ¡ \}}|jdd}| d¡ | ¡  | d¡ | ¡  t|dƒ ˆ  tj|jd¡ W d |  ¡  X d S )Nr   )r   s   helloó   
r   r   )	r   r   r	   r   r   r   r   r   r   )r   r   r    r!   )r"   r   r   Úaccept_close_late=   s    


z?TestGreenIo.test_close_with_makefile.<locals>.accept_close_latec                sV   t  tj|  ¡ d f¡}|jdd}| ¡  ˆ  | ¡ d¡ ˆ  	| 
¡ ¡ | ¡  d S )Né   Úrb)r   s   hello
)r   Úcreate_connectionr   ÚDEFAULT_CONNECTÚgetsocknamer   r   ÚassertEqualÚreadlineZassertFalseÚread)ÚserverÚclientr!   )r"   r   r   Údid_it_workL   s    z9TestGreenIo.test_close_with_makefile.<locals>.did_it_work)r   ÚgeventÚspawnÚkill)r"   r#   r%   r0   r.   Zserver_greenletr   )r"   r   Útest_close_with_makefile-   s    z$TestGreenIo.test_close_with_makefilezGC is differentc          	   C   s~   dd„ }t ƒ }t ||¡ t tj| ¡ d f¡}tj 	d¡6 | 
¡ }| ¡  |  | ¡ d¡ |  | ¡ d¡ W d Q R X d S )Nc             S   sd   d }z@|   ¡ \}}tr|}|jdd}| d¡ | ¡  t|dƒ W d |  ¡  |d k	r^| ¡  X d S )Nr   )r   s   hello
r   )r   r   r   r	   r   r   )r   Zoconnr   r    r   r   r   Úaccept_once`   s    
z7TestGreenIo.test_del_closes_socket.<locals>.accept_oncer&   g      à?zhello
Ú )r   r1   r2   r   r(   r   r)   r*   ZTimeoutÚ	start_newr   r   r+   r-   )r"   r5   r.   r/   r!   r   r   r   Útest_del_closes_socket^   s    z"TestGreenIo.test_del_closes_socketN)Ú__name__Ú
__module__Ú__qualname__r4   r   r8   r   r   r   r   r   +   s   1r   Ú__main__)Úsysr1   r   Zgevent.testingr   r   r   r   r   ÚhasattrZPYPYÚversion_infor   r   r   r9   r   r   r   r   Ú<module>   s   
	T