o
    b                     @   st   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ZeejejejejG dd dZd	S )
zStandard 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)error
interfacesprocess)failurelogc                   @   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+d, Zd-d. ZdS )0
StandardIONFr      c                 C   sX   |d u r
ddl m} || _t|| d|| _t|| d|| _| j  | j	|  d S )Nr   )reactorwriteread)
twisted.internetr   protocolr   ProcessWriter_writerProcessReader_readerstartReadingmakeConnection)selfprotostdinstdoutr   r   r   r   __init__&   s   
zStandardIO.__init__c                 C      | j d ur| j   d S d S N)r   loseConnectionr   r   r   r   loseWriteConnection3      
zStandardIO.loseWriteConnectionc                 C      | j d ur| j | d S d S r!   )r   r   r   datar   r   r   r   7      
zStandardIO.writec                 C   r&   r!   )r   writeSequencer'   r   r   r   r*   ;   r)   zStandardIO.writeSequencec                 C   s6   d| _ | jd ur| j  | jd ur| j  d S d S NT)disconnectingr   r"   r   stopReadingr#   r   r   r   r"   ?   s   


zStandardIO.loseConnectionc                 C      t  S r!   r   r#   r   r   r   getPeerH      zStandardIO.getPeerc                 C   r.   r!   r/   r#   r   r   r   getHostK   r1   zStandardIO.getHostc                 C   s   | j | d S r!   )r   dataReceived)r   fdr(   r   r   r   childDataReceivedO   s   zStandardIO.childDataReceivedc                 C   sJ   | j rd S |jjtjkr|dkr| | d S | | d S | | d S )Nr   )disconnectedvalue	__class__r   ConnectionDone_readConnectionLost_writeConnectionLostconnectionLost)r   r4   reasonr   r   r   childConnectionLostR   s   zStandardIO.childConnectionLostc                 C   s   d| _ | j}| j}| j}d  | _| _d | _|d ur!|j s!|| |d ur-|j s-|| z|| W d S  tyC   t  Y d S w r+   )r6   r   r   r   r<   BaseExceptionr   err)r   r=   r   r   r   r   r   r   r<   _   s   

zStandardIO.connectionLostc                 C   sj   d | _ | jr| | d S t| jd }|r3z|  W d S  ty2   t	  | t
  Y d S w d S r!   )r   r,   r<   r   IHalfCloseableProtocolr   writeConnectionLostr?   r   r@   r   Failurer   r=   pr   r   r   r;   t   s   
zStandardIO._writeConnectionLostc                 C   s`   d | _ t| jd }|r)z|  W d S  ty(   t  | t	
  Y d S w | | d S r!   )r   r   rA   r   readConnectionLostr?   r   r@   r<   r   rC   rD   r   r   r   r:      s   zStandardIO._readConnectionLostc                 C   s(   | j d u r|  d S | j || d S r!   )r   stopProducingregisterProducer)r   producer	streamingr   r   r   rH      s   
zStandardIO.registerProducerc                 C   r    r!   )r   unregisterProducerr#   r   r   r   rK      r%   zStandardIO.unregisterProducerc                 C   s   |    d S r!   )r"   r#   r   r   r   rG      s   zStandardIO.stopProducingc                 C   r    r!   )r   pauseProducingr#   r   r   r   rL      r%   zStandardIO.pauseProducingc                 C   r    r!   )r   resumeProducingr#   r   r   r   rM      r%   zStandardIO.resumeProducingc                 C      |    dS )z3Compatibility only, don't use. Call pauseProducing.N)rL   r#   r   r   r   r-         zStandardIO.stopReadingc                 C   rN   )z4Compatibility only, don't use. Call resumeProducing.N)rM   r#   r   r   r   r      rO   zStandardIO.startReadingc                 C      t  r!   NotImplementedErrorr   r=   r   r   r   rF         zStandardIO.readConnectionLostc                 C   rP   r!   rQ   rS   r   r   r   rB      rT   zStandardIO.writeConnectionLost)r   r   N)r	   r
   r   r   r   r6   r,   r   r$   r   r*   r"   r0   r2   r5   r>   r<   r;   r:   rH   rK   rG   rL   rM   r-   r   rF   rB   r   r   r   r   r      s4    
	r   N)__doc__zope.interfacer   r   r   r   r   twisted.pythonr   r   IAddressr   
ITransport	IProducer	IConsumerIHalfCloseableDescriptorr   r   r   r   r   <module>   s   