U
    ¹êW[O  ã                   @   sx   d Z ddlmZ ddlmZmZmZ ddlmZm	Z	 eej
ƒG dd„ deƒƒZeejejejejƒG dd„ deƒƒZd	S )
zÚStandard input/out/err support.

Future Plans::

    support for stderr, perhaps
    Rewrite to use the reactor instead of an ad-hoc mechanism for connecting
        protocols to transport.

Maintainer: James Y Knight
é    )Úimplementer)ÚprocessÚerrorÚ
interfaces)ÚlogÚfailurec                   @   s   e Zd ZdS )ÚPipeAddressN)Ú__name__Ú
__module__Ú__qualname__© r   r   ú>/usr/lib/python3/dist-packages/twisted/internet/_posixstdio.pyr      s   r   c                   @   s¶   e Zd ZdZdZdZdZd+dd„Zdd„ Zd	d
„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Zd!d"„ Zd#d$„ Zd%d&„ Zd'd(„ Zd)d*„ ZdS ),Ú
StandardIONFr   é   c                 C   sX   |d krddl m} || _t || d|¡| _t || d|¡| _| j ¡  | j 	| ¡ d S )Nr   )ÚreactorÚwriteÚread)
Útwisted.internetr   Úprotocolr   ZProcessWriterÚ_writerZProcessReaderÚ_readerÚstartReadingZmakeConnection)ÚselfÚprotoÚstdinÚstdoutr   r   r   r   Ú__init__"   s    
zStandardIO.__init__c                 C   s   | j d k	r| j  ¡  d S ©N)r   ÚloseConnection©r   r   r   r   ÚloseWriteConnection/   s    
zStandardIO.loseWriteConnectionc                 C   s   | j d k	r| j  |¡ d S r   )r   r   ©r   Údatar   r   r   r   3   s    
zStandardIO.writec                 C   s   | j d k	r| j  |¡ d S r   )r   ÚwriteSequencer!   r   r   r   r#   7   s    
zStandardIO.writeSequencec                 C   s2   d| _ | jd k	r| j ¡  | jd k	r.| j ¡  d S ©NT)Údisconnectingr   r   r   ÚstopReadingr   r   r   r   r   ;   s
    


zStandardIO.loseConnectionc                 C   s   t ƒ S r   ©r   r   r   r   r   ÚgetPeerD   s    zStandardIO.getPeerc                 C   s   t ƒ S r   r'   r   r   r   r   ÚgetHostG   s    zStandardIO.getHostc                 C   s   | j  |¡ d S r   )r   ZdataReceived)r   Úfdr"   r   r   r   ÚchildDataReceivedL   s    zStandardIO.childDataReceivedc                 C   sF   | j r
d S |jjtjkr8|dkr,|  |¡ qB|  |¡ n
|  |¡ d S )Nr   )ÚdisconnectedÚvalueÚ	__class__r   ZConnectionDoneÚ_readConnectionLostÚ_writeConnectionLostÚconnectionLost)r   r*   Úreasonr   r   r   ÚchildConnectionLostO   s    zStandardIO.childConnectionLostc                 C   s‚   d| _ | j}| j}| j}d  | _| _d | _|d k	rB|j sB| |¡ |d k	rZ|j sZ| |¡ z| |¡ W n   t ¡  Y nX d S r$   )r,   r   r   r   r1   r   Úerr)r   r2   r   r   r   r   r   r   r1   \   s    

zStandardIO.connectionLostc                 C   s`   d | _ | jr|  |¡ d S t | jd ¡}|r\z| ¡  W n"   t ¡  |  t	 
¡ ¡ Y nX d S r   )r   r%   r1   r   ÚIHalfCloseableProtocolr   ZwriteConnectionLostr   r4   r   ÚFailure©r   r2   Úpr   r   r   r0   q   s    
zStandardIO._writeConnectionLostc                 C   sX   d | _ t | jd ¡}|rJz| ¡  W qT   t ¡  |  t 	¡ ¡ Y qTX n
|  |¡ d S r   )
r   r   r5   r   ZreadConnectionLostr   r4   r1   r   r6   r7   r   r   r   r/      s    zStandardIO._readConnectionLostc                 C   s&   | j d kr| ¡  n| j  ||¡ d S r   )r   ÚstopProducingÚregisterProducer)r   ZproducerZ	streamingr   r   r   r:   Œ   s    

zStandardIO.registerProducerc                 C   s   | j d k	r| j  ¡  d S r   )r   ÚunregisterProducerr   r   r   r   r;   ’   s    
zStandardIO.unregisterProducerc                 C   s   |   ¡  d S r   )r   r   r   r   r   r9   —   s    zStandardIO.stopProducingc                 C   s   | j d k	r| j  ¡  d S r   )r   ÚpauseProducingr   r   r   r   r<   š   s    
zStandardIO.pauseProducingc                 C   s   | j d k	r| j  ¡  d S r   )r   ÚresumeProducingr   r   r   r   r=   ž   s    
zStandardIO.resumeProducingc                 C   s   |   ¡  dS )z3Compatibility only, don't use. Call pauseProducing.N)r<   r   r   r   r   r&   ¢   s    zStandardIO.stopReadingc                 C   s   |   ¡  dS )z4Compatibility only, don't use. Call resumeProducing.N)r=   r   r   r   r   r   ¦   s    zStandardIO.startReading)r   r   N)r	   r
   r   r   r   r,   r%   r   r    r   r#   r   r(   r)   r+   r3   r1   r0   r/   r:   r;   r9   r<   r=   r&   r   r   r   r   r   r      s.   
	r   N)Ú__doc__Zzope.interfacer   r   r   r   r   Ztwisted.pythonr   r   ZIAddressÚobjectr   Z
ITransportZ	IProducerZ	IConsumerZIHalfCloseableDescriptorr   r   r   r   r   Ú<module>   s   
 ÿ