U
    
W[’  ã                   @   sÔ   d Z ddlmZm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mZ eeƒG dd	„ d	ejƒƒZed
krÐe ejd ¡ ¡  e eejd dƒ¡ ddl	mZ eƒ Ze
 e¡ e ¡  e ej¡ dS )zÌ
Main program for the child process run by
L{twisted.test.test_stdio.StandardInputOutputTests.test_readConnectionLost}
to test that IHalfCloseableProtocol.readConnectionLost works for process
transports.
é    )Úabsolute_importÚdivisionN)Úimplementer)ÚIHalfCloseableProtocol)ÚstdioÚprotocol)ÚreflectÚlogc                   @   s,   e Zd ZdZdZdd„ Zdd„ Zdd„ ZdS )	ÚHalfCloseProtocolzÎ
    A protocol to hook up to stdio and observe its transport being
    half-closed.  If all goes as expected, C{exitCode} will be set to C{0};
    otherwise it will be set to C{1} to indicate failure.
    Nc                 C   s   | j  d¡ dS )z=
        Signal the parent process that we're ready.
        ó   xN)Z	transportÚwrite©Úself© r   úC/usr/lib/python3/dist-packages/twisted/test/stdio_test_halfclose.pyÚconnectionMade    s    z HalfCloseProtocol.connectionMadec                 C   s   d| _ t ¡  dS )zv
        This is the desired event.  Once it has happened, stop the reactor so
        the process will exit.
        r   N)ÚexitCodeÚreactorÚstopr   r   r   r   ÚreadConnectionLost'   s    z$HalfCloseProtocol.readConnectionLostc                 C   s(   | j dkrd| _ t |d¡ t ¡  dS )zŒ
        This may only be invoked after C{readConnectionLost}.  If it happens
        otherwise, mark it as an error and shut down.
        Né   z!Unexpected call to connectionLost)r   r	   Úerrr   r   )r   Úreasonr   r   r   ÚconnectionLost0   s    
z HalfCloseProtocol.connectionLost)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r   r   r
      s
   	r
   Ú__main__r   é   Úwb)r   )r   Z
__future__r   r   ÚsysZzope.interfacer   Ztwisted.internet.interfacesr   Ztwisted.internetr   r   Ztwisted.pythonr   r	   ZProtocolr
   r   ZnamedAnyÚargvÚinstallZstartLoggingÚopenr   Z
StandardIOÚrunÚexitr   r   r   r   r   Ú<module>   s    $
