
    Ϫf
                         d Z ddlZddlZddlZddlZddlmZ ddlmZ ddl	m
Z
mZmZmZ ddlmZmZmZ  G d de      Z G d	 d
ej(                        Z G d de      Zd ZddZedk(  r e        yy)zC
Asynchronous local terminal input handling

@author: Jp Calderone
    N)ServerProtocol)ColoredManhole)deferprotocolreactorstdio)failurelogreflectc                       e Zd Zy)UnexpectedOutputErrorN)__name__
__module____qualname__     5/usr/lib/python3/dist-packages/twisted/conch/stdio.pyr   r      s    r   r   c                   6    e Zd Zd Zd Zd Zd Zd Zd Zd Z	y)	TerminalProcessProtocolc                 D    || _         t        j                         | _        y N)protor   DeferredonConnection)selfr   s     r   __init__z TerminalProcessProtocol.__init__   s    
!NN,r   c                 ~    | j                   j                  |        | j                  j                  d        d | _        y r   )r   makeConnectionr   callback)r   s    r   connectionMadez&TerminalProcessProtocol.connectionMade   s0    

!!$'""4( r   c                 :    | j                   j                  |       y)zj
        Write to the terminal.

        @param data: Data to write.
        @type data: L{bytes}
        N)	transportwriter   datas     r   r#   zTerminalProcessProtocol.write$   s     	T"r   c                 :    | j                   j                  |       y)zs
        Receive data from the terminal.

        @param data: Data received.
        @type data: L{bytes}
        N)r   dataReceivedr$   s     r   outReceivedz#TerminalProcessProtocol.outReceived-   s     	

%r   c                     | j                   j                          | j                  ?| j                  j                  t	        j
                  t        |                   d| _        yy)zt
        Report an error.

        @param data: Data to include in L{Failure}.
        @type data: L{bytes}
        N)r"   loseConnectionr   connectionLostr	   Failurer   r$   s     r   errReceivedz#TerminalProcessProtocol.errReceived6   sK     	%%'::!JJ%%goo6KD6Q&RSDJ "r   c                 T    | j                   | j                   j                  |       y y r   )r   childConnectionLost)r   childFDs     r   r/   z+TerminalProcessProtocol.childConnectionLostB   s#    ::!JJ**73 "r   c                 b    | j                   #| j                   j                  |       d | _         y y r   )r   r+   r   reasons     r   processEndedz$TerminalProcessProtocol.processEndedF   s*    ::!JJ%%f-DJ "r   N)
r   r   r   r   r    r#   r(   r-   r/   r4   r   r   r   r   r      s%    -!
#&
4r   r   c                       e Zd ZdZd Zy)ConsoleManholezK
    A manhole protocol specifically for use with L{stdio.StandardIO}.
    c                 ,    t        j                          y)z
        When the connection is lost, there is nothing more to do.  Stop the
        reactor so that the process can exit.
        N)r   stopr2   s     r   r+   zConsoleManhole.connectionLostQ   s    
 	r   N)r   r   r   __doc__r+   r   r   r   r6   r6   L   s    r   r6   c                    t         j                  j                         }t        j                  |      }t        j                  |       	 t        j                  t        |              t        j                          t        j                  |t        j                  |       t        j                  |d       y # t        j                  |t        j                  |       t        j                  |d       w xY w)Ns   c)sys	__stdin__filenotermios	tcgetattrttysetrawr   
StandardIOr   r   run	tcsetattrTCSANOWosr#   )klassfdoldSettingss      r   runWithProtocolrJ   Y   s    				B##B'KJJrN#./"goo{;
\" 	"goo{;
\"s   
2B8 8=C5c                     t        j                  t        dd             | t        j                  dd  } | rt        j                  | d         }nt        }t        |       y )Nz	child.logw   r   )	r
   startLoggingopenr;   argvr   
namedClassr6   rJ   )rP   rG   s     r   mainrR   e   sO    T+s+,|xx|""47+Er   __main__r   )r9   rF   r;   r>   r@   twisted.conch.insults.insultsr   twisted.conch.manholer   twisted.internetr   r   r   r   twisted.pythonr	   r
   r   	Exceptionr   ProcessProtocolr   r6   rJ   rR   r   r   r   r   <module>rZ      ss   
 
 
  
 8 0 < < 0 0	I 	/h66 /d
^ 
	#	 zF r   