o
    U˟i                     @   s   d dl Z d dlZd dlmZ d dlmZ d dlmZmZ d dlmZ d dlm	Z	 d dlm
Z
 e jd  dkZd	d
 ZG dd deZedkrKe  dS dS )    N)socket)testing)TestCasetcp_listener)gc_collect_if_needed)
skipOnPyPy)params   c                 C   s@   z|  |}W n ty   tsJ Y d S w |d u sJ |d S )N)write
ValueErrorPY3)fsr r   b/var/www/apps/myagent/mysuperagent/venv/lib/python3.10/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                    sh   z.|   \}}|jdd}|  |d |  t|d  tj|jd W |   d S |   w )Nwbmode   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                    sr   z3|   \}}|jdd}|d |  |d |  t|d  tj|jd W |   d S |   w )Nr   r   s   hello   
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   rbr   r   )r   create_connectionr   DEFAULT_CONNECTgetsocknamer   r   assertEqualreadline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)   r5   r3   server_greenletr   r%   r   test_close_with_makefile-   s   z$TestGreenIo.test_close_with_makefilez6Takes multiple GCs and issues a warning we can't catchc                    s   dd l   fdd}t }t|| ttj| d f}tj	
d' | }|  | | d | | d |  W d    ~~d S 1 sOw   Y  ~~d S )Nr   c              	      s      D  d z(|  d }|jdd}|d |  t|d W |   ~ ~t  t  n|   ~ ~t  t  w W d    d S 1 sKw   Y  d S )Nignorer   r   r   r   r   )catch_warningssimplefilterr   r   r
   r   r   r   )r!   r"   warningsr   r   accept_oncea   s&   



"z7TestGreenIo.test_del_closes_socket.<locals>.accept_oncer*   g      ?zhello
 )r?   r   r6   r7   r   r,   r   r-   r.   Timeout	start_newr   r   r/   r2   )r&   r@   r3   r4   r$   r   r>   r   test_del_closes_socket^   s"    

		z"TestGreenIo.test_del_closes_socketN)__name__
__module____qualname__r:   r   rD   r   r   r   r   r   +   s    1r   __main__)sysr6   r   r   	greentestgevent.testingr   r   r   r   r   version_infor   r   r   rE   mainr   r   r   r   <module>   s   	f