
    Ϫf                         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             Z eej                  ej                  ej                  ej                         G d d             Zy	)
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                       e Zd Zy)PipeAddressN)__name__
__module____qualname__     >/usr/lib/python3/dist-packages/twisted/internet/_posixstdio.pyr
   r
      s    r   r
   c                       e Zd ZdZdZdZdZddZd Zd Z	d Z
d Zd Zd	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zy)
StandardIONFc                     |ddl m} || _        t        j                  || d|      | _        t        j                  || d|      | _        | j                  j                          | j                  j                  |        y )Nr   )reactorwriteread)
twisted.internetr   protocolr   ProcessWriter_writerProcessReader_readerstartReadingmakeConnection)selfprotostdinstdoutr   s        r   __init__zStandardIO.__init__%   sc    ?0,,WdGVL,,WdFEJ!!#$$T*r   c                 R    | j                   | j                   j                          y y N)r   loseConnectionr   s    r   loseWriteConnectionzStandardIO.loseWriteConnection2   !    <<#LL'') $r   c                 T    | j                   | j                   j                  |       y y r%   )r   r   r   datas     r   r   zStandardIO.write6   s#    <<#LLt$ $r   c                 T    | j                   | j                   j                  |       y y r%   )r   writeSequencer+   s     r   r.   zStandardIO.writeSequence:   s#    <<#LL&&t, $r   c                     d| _         | j                  | j                  j                          | j                  | j                  j	                          y y NT)disconnectingr   r&   r   stopReadingr'   s    r   r&   zStandardIO.loseConnection>   sC    !<<#LL'')<<#LL$$& $r   c                     t               S r%   r
   r'   s    r   getPeerzStandardIO.getPeerG   
    }r   c                     t               S r%   r4   r'   s    r   getHostzStandardIO.getHostJ   r6   r   c                 :    | j                   j                  |       y r%   )r   dataReceived)r   fdr,   s      r   childDataReceivedzStandardIO.childDataReceivedN   s    ""4(r   c                     | j                   ry |j                  j                  t        j                  k(  r)|dk(  r| j                  |       y | j                  |       y | j                  |       y )Nr   )disconnectedvalue	__class__r   ConnectionDone_readConnectionLost_writeConnectionLostconnectionLost)r   r;   reasons      r   childConnectionLostzStandardIO.childConnectionLostQ   sW    <<!!U%9%99V|((0))&1'r   c                 j   d| _         | j                  }| j                  }| j                  }d x| _        | _        d | _        ||j                   s|j	                  |       ||j                   s|j	                  |       	 |j	                  |       y # t
        $ r t        j                          Y y w xY wr0   )r>   r   r   r   rD   BaseExceptionr   err)r   rE   r   r   r   s        r   rD   zStandardIO.connectionLost^   s      ,,,,==&**t|w';';""6*w';';""6*	##F+ 	GGI	s    B B21B2c                 B   d | _         | j                  r| j                  |       y t        j                  | j
                  d       }|r	 |j                          y y # t        $ r: t        j                          | j                  t        j                                Y y w xY wr%   )r   r1   rD   r   IHalfCloseableProtocolr   writeConnectionLostrH   r   rI   r   Failurer   rE   ps      r   rC   zStandardIO._writeConnectionLosts   s    '--dmmTB7%%'  ! 7	##GOO$567s   	A A BBc                 (   d | _         t        j                  | j                  d       }|r	 |j	                          y | j                  |       y # t
        $ r: t        j                          | j                  t        j                                Y y w xY wr%   )r   r   rK   r   readConnectionLostrH   r   rI   rD   r   rM   rN   s      r   rB   zStandardIO._readConnectionLost   sr    --dmmTB7$$&
 '	 ! 7	##GOO$567s   A A BBc                 v    | j                   |j                          y | j                   j                  ||       y r%   )r   stopProducingregisterProducer)r   producer	streamings      r   rT   zStandardIO.registerProducer   s,    <<""$LL))(I>r   c                 R    | j                   | j                   j                          y y r%   )r   unregisterProducerr'   s    r   rX   zStandardIO.unregisterProducer   s!    <<#LL++- $r   c                 $    | j                          y r%   )r&   r'   s    r   rS   zStandardIO.stopProducing   s    r   c                 R    | j                   | j                   j                          y y r%   )r   pauseProducingr'   s    r   r[   zStandardIO.pauseProducing   r)   r   c                 R    | j                   | j                   j                          y y r%   )r   resumeProducingr'   s    r   r]   zStandardIO.resumeProducing   s!    <<#LL((* $r   c                 $    | j                          y)z3Compatibility only, don't use. Call pauseProducing.N)r[   r'   s    r   r2   zStandardIO.stopReading   s    r   c                 $    | j                          y)z4Compatibility only, don't use. Call resumeProducing.N)r]   r'   s    r   r   zStandardIO.startReading   s    r   c                     t               r%   NotImplementedErrorr   rE   s     r   rQ   zStandardIO.readConnectionLost       !##r   c                     t               r%   ra   rc   s     r   rL   zStandardIO.writeConnectionLost   rd   r   )r      N)r   r   r   r   r   r>   r1   r#   r(   r   r.   r&   r5   r8   r<   rF   rD   rC   rB   rT   rX   rS   r[   r]   r2   r   rQ   rL   r   r   r   r   r      s     GGLM+*%-')(*7
(?.
*+$$r   r   N)__doc__zope.interfacer   r   r   r   r   twisted.pythonr   r   IAddressr
   
ITransport	IProducer	IConsumerIHalfCloseableDescriptorr   r   r   r   <module>ro      s   	 ' 7 7 ' Z  !	 	 "	 ''	S$ S$S$r   