a
    	¼3j!	  ã                   @   s–   d dl Z d dlZd dlmZ dd„ ZG dd„ de jƒ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)Ú
functionalc                   C   s   t  d ¡ d S ©N)ÚasyncioZset_event_loop_policy© r   r   úa/www/server/python_manager/versions/3.9.10/lib/python3.9/test/test_asyncio/test_buffered_proto.pyÚtearDownModule   s    r   c                   @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
ÚReceiveStuffProtoc                 C   s   || _ || _d S r   )ÚcbÚcon_lost_fut)Úselfr	   r
   r   r   r   Ú__init__   s    zReceiveStuffProto.__init__c                 C   s   t dƒ| _| jS )Néd   )Ú	bytearrayÚbuffer)r   Úsizehintr   r   r   Ú
get_buffer   s    
zReceiveStuffProto.get_bufferc                 C   s   |   | jd |… ¡ d S r   )r	   r   )r   Únbytesr   r   r   Úbuffer_updated   s    z ReceiveStuffProto.buffer_updatedc                 C   s&   |d u r| j  d ¡ n| j  |¡ d S r   )r
   Ú
set_resultÚset_exception)r   Úexcr   r   r   Úconnection_lost   s    z!ReceiveStuffProto.connection_lostN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r   r   r   r      s   r   c                   @   s   e Zd Zdd„ Zdd„ ZdS )ÚBaseTestBufferedProtocolc                 C   s   t ‚d S r   )ÚNotImplementedError©r   r   r   r   Únew_loop    s    z!BaseTestBufferedProtocol.new_loopc                    sz   dd ‰ ‡ ‡fdd„}‡ fdd„}ˆj  t |dd¡¡}|jd  ¡ }ˆj  t ||ƒd	¡¡ | ¡  ˆj  | ¡ ¡ d S )
Ns	   12345678+i   c                 “   sT   d‰‡‡‡fdd„‰ˆj  ¡ ‰ ˆj j‡ ‡fdd„g| ¢R Ž I d H \‰}ˆ I d H  d S )Nó    c                    s   ˆ| 7 ‰ˆˆ krˆ  d¡ d S )Nó   1)Úwrite)Úbuf)ÚNOISEÚdataÚtrr   r   Úon_buf*   s    z^BaseTestBufferedProtocol.test_buffered_proto_create_connection.<locals>.client.<locals>.on_bufc                      s
   t ˆˆ ƒS r   )r   r   )Úconn_lost_futr&   r   r   Ú<lambda>3   r   z`BaseTestBufferedProtocol.test_buffered_proto_create_connection.<locals>.client.<locals>.<lambda>)ÚloopZcreate_futureÚcreate_connection)ÚaddrZpr©r#   r   )r'   r$   r&   r%   r   Úclient'   s    
ÿÿzNBaseTestBufferedProtocol.test_buffered_proto_create_connection.<locals>.clientc                 “   s4   |  ˆ ¡ |  d¡I d H  | ¡  | ¡ I d H  d S )Né   )r!   ZreadexactlyÚcloseÚwait_closed)ÚreaderÚwriter)r#   r   r   Úon_server_client7   s    
zXBaseTestBufferedProtocol.test_buffered_proto_create_connection.<locals>.on_server_clientz	127.0.0.1r   é   )	r)   Zrun_until_completer   Zstart_serverZsocketsÚgetsocknameÚwait_forr/   r0   )r   r-   r3   Zsrvr+   r   r,   r   Ú%test_buffered_proto_create_connection#   s    ÿÿÿz>BaseTestBufferedProtocol.test_buffered_proto_create_connectionN)r   r   r   r   r7   r   r   r   r   r      s   r   c                   @   s   e Zd Zdd„ ZdS )ÚBufferedProtocolSelectorTestsc                 C   s   t  ¡ S r   )r   ZSelectorEventLoopr   r   r   r   r   L   s    z&BufferedProtocolSelectorTests.new_loopN©r   r   r   r   r   r   r   r   r8   I   s   r8   ÚProactorEventLoopzWindows onlyc                   @   s   e Zd Zdd„ ZdS )ÚBufferedProtocolProactorTestsc                 C   s   t  ¡ S r   )r   r:   r   r   r   r   r   T   s    z&BufferedProtocolProactorTests.new_loopNr9   r   r   r   r   r;   P   s   r;   Ú__main__)r   ZunittestZtest.test_asyncior   Z
func_testsr   ZBufferedProtocolr   ZFunctionalTestCaseMixinr   ZTestCaser8   Z
skipUnlessÚhasattrr;   r   Úmainr   r   r   r   Ú<module>   s   +ÿÿ