a
    åzeÐ  ã                   @   s¬   d dl Z d dlZd dlZd dlZd dlmZ d dlmZ d dlm	Z
 dd„ ZG dd„ de
jƒZG d	d
„ d
eejƒZe ee dƒd¡G dd„ deejƒƒZedkr¨e ¡  dS )é    N)Úsocket_helper)Úutils)Ú
functionalc                   C   s   t  d ¡ d S ©N)ÚasyncioZset_event_loop_policy© r   r   ú3/usr/lib/python3.9/test/test_asyncio/test_server.pyÚtearDownModule   s    r	   c                   @   s   e Zd Zdd„ Zdd„ ZdS )ÚBaseStartServerc                 C   s   t ‚d S r   )ÚNotImplementedError©Úselfr   r   r   Únew_loop   s    zBaseStartServer.new_loopc              
      sˆ  dd d ‰ ‡ ‡fdd„‰‡fdd„}dd	„ }|   t¡0 | j tj|tjd
| jdd¡‰W d   ƒ n1 sn0    Y  |  ˆ 	¡ ¡ | j 
|ˆƒ¡‰ˆjd
  ¡ ‰|  tj¡P |  ‡‡fdd„¡ | j ˆ¡ W d   ƒ n1 sè0    Y  W d   ƒ n1 s0    Y  |  ˆjd¡ |  ˆj¡ |  ˆj¡ |  ˆ 	¡ ¡ |  td¡  | j ˆ ¡ ¡ W d   ƒ n1 sz0    Y  d S )Nó   1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111é   ó   
c                    s\   t dƒD ]}t d¡ ˆ ¡ r q(qt‚|  d¡ |  |¡ |  ˆ ¡ |  d¡ |  	¡  d S )Né
   gš™™™™™É?é   é   )
ÚrangeÚtimeÚsleepÚ
is_servingÚRuntimeErrorÚ
settimeoutÚconnectÚsendÚrecv_allÚclose)ÚsockÚaddrÚi)Ú	HELLO_MSGÚsrvr   r   Úclient   s    




z3BaseStartServer.test_start_server_1.<locals>.clientc                 “   s:   |   ¡ I d H  ˆ  ¡  | d¡ | ¡  | ¡ I d H  d S ©Nó   1©ÚreadlineÚcancelÚwriter   Zwait_closed©ÚreaderÚwriter©Ú	main_taskr   r   Úserve%   s
    
z2BaseStartServer.test_start_server_1.<locals>.servec              	   Ó   sJ   | 4 I d H š$ |   ¡ I d H  W d   ƒI d H  qF1 I d H s<0    Y  d S r   )Úserve_forever©r#   r   r   r   Úmain,   s    z1BaseStartServer.test_start_server_1.<locals>.mainr   F©ÚloopÚstart_servingc                    s
   ˆ| ˆ ƒS r   r   ©r   ©r    r$   r   r   Ú<lambda>:   ó    z5BaseStartServer.test_start_server_1.<locals>.<lambda>r   ú	is closed)ÚassertWarnsÚDeprecationWarningr5   Úrun_until_completer   Zstart_serverr   ZHOSTv4ÚassertFalser   Úcreate_taskÚsocketsÚgetsocknameÚassertRaisesÚCancelledErrorZ
tcp_clientÚassertEqualÚassertIsNoneÚ_socketsÚ_waitersÚassertRaisesRegexr   r1   )r   r0   r3   r   )r"   r    r$   r/   r#   r   Útest_start_server_1   s(    
ÿ&Jz#BaseStartServer.test_start_server_1N)Ú__name__Ú
__module__Ú__qualname__r   rJ   r   r   r   r   r
      s   r
   c                   @   s"   e Zd Zdd„ Zejdd„ ƒZdS )ÚSelectorStartServerTestsc                 C   s   t  ¡ S r   )r   ZSelectorEventLoopr   r   r   r   r   I   s    z!SelectorStartServerTests.new_loopc              
      s¢  dd d ‰ t  ¡ ‰‡ ‡fdd„‰‡fdd„}‡‡fdd	„}t ¡ F‰ˆ t¡, ˆj tj	|ˆˆjd
d¡}W d   ƒ n1 s„0    Y  ˆj 
||ƒ¡‰ˆ tj¡P ˆ ‡‡fdd„¡ ˆj ˆ¡ W d   ƒ n1 sâ0    Y  W d   ƒ n1 s0    Y  ˆ |jd¡ ˆ |j¡ ˆ |j¡ ˆ | ¡ ¡ ˆ td¡  ˆj | ¡ ¡ W d   ƒ n1 st0    Y  W d   ƒ n1 s”0    Y  d S )Nr   r   r   c                    s>   |   d¡ ˆ d¡ |  |¡ |  ˆ ¡ |  d¡ |  ¡  d S )Nr   r   r   )r   Úwaitr   r   r   r   )r   r    )r"   Ústartedr   r   r$   Q   s    




zASelectorStartServerTests.test_start_unix_server_1.<locals>.clientc                 “   s:   |   ¡ I d H  ˆ  ¡  | d¡ | ¡  | ¡ I d H  d S r%   r'   r+   r.   r   r   r0   Y   s
    
z@SelectorStartServerTests.test_start_unix_server_1.<locals>.servec              	   “   s|   | 4 I d H šV ˆ   |  ¡ ¡ |  ¡ I d H  ˆ  |  ¡ ¡ ˆ ¡  |  ¡ I d H  W d   ƒI d H  qx1 I d H sn0    Y  d S r   )r?   r   r6   Z
assertTrueÚsetr1   r2   )r   rP   r   r   r3   `   s    z?SelectorStartServerTests.test_start_unix_server_1.<locals>.mainFr4   c                    s
   ˆ| ˆ ƒS r   r   r7   r8   r   r   r9   p   r:   zCSelectorStartServerTests.test_start_unix_server_1.<locals>.<lambda>r   r;   )Ú	threadingÚEventÚ
test_utilsZunix_socket_pathr<   r=   r5   r>   r   Zstart_unix_serverr@   rC   rD   Zunix_clientrE   rA   rF   rG   rH   r?   r   rI   r   r1   )r   r0   r3   r#   r   )r"   r    r$   r/   r   rP   r   Útest_start_unix_server_1L   s(    

ÿ&Jz1SelectorStartServerTests.test_start_unix_server_1N)rK   rL   rM   r   r   Zskip_unless_bind_unix_socketrU   r   r   r   r   rN   G   s   rN   ÚProactorEventLoopzWindows onlyc                   @   s   e Zd Zdd„ ZdS )ÚProactorStartServerTestsc                 C   s   t  ¡ S r   )r   rV   r   r   r   r   r   €   s    z!ProactorStartServerTests.new_loopN)rK   rL   rM   r   r   r   r   r   rW   }   s   rW   Ú__main__)r   r   rR   ZunittestZtest.supportr   Ztest.test_asyncior   rT   r   Z
func_testsr	   ZFunctionalTestCaseMixinr
   ZTestCaserN   Z
skipUnlessÚhasattrrW   rK   r3   r   r   r   r   Ú<module>   s   86