
    \d
                         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             dS dS )zC
Asynchronous local terminal input handling

@author: Jp Calderone
    N)ServerProtocol)ColoredManhole)deferprotocolreactorstdio)failurelogreflectc                       e Zd ZdS )UnexpectedOutputErrorN)__name__
__module____qualname__     3lib/python3.11/site-packages/twisted/conch/stdio.pyr   r      s        Dr   r   c                   8    e Zd Zd Zd Zd Zd Zd Zd Zd Z	dS )	TerminalProcessProtocolc                 D    || _         t          j                    | _        d S N)protor   DeferredonConnection)selfr   s     r   __init__z TerminalProcessProtocol.__init__   s    
!N,,r   c                 |    | j                             |            | j                            d            d | _        d S r   )r   makeConnectionr   callback)r   s    r   connectionMadez&TerminalProcessProtocol.connectionMade   s=    
!!$'''""4((( r   c                 :    | j                             |           dS )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                             |           dS )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        B| j                            t	          j        t          |                               d| _        dS dS )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   s\     	%%''':!J%%go6KD6Q6Q&R&RSSSDJJJ "!r   c                 L    | j         | j                             |           d S d S r   )r   childConnectionLost)r   childFDs     r   r/   z+TerminalProcessProtocol.childConnectionLostB   s.    :!J**733333 "!r   c                 Z    | j         #| j                             |           d | _         d S d S r   )r   r+   r   reasons     r   processEndedz$TerminalProcessProtocol.processEndedF   s3    :!J%%f---DJJJ "!r   N)
r   r   r   r   r    r#   r(   r-   r/   r4   r   r   r   r   r      s}        - - -! ! !
# # #& & &
 
 
4 4 4    r   r   c                       e Zd ZdZd ZdS )ConsoleManholezK
    A manhole protocol specifically for use with L{stdio.StandardIO}.
    c                 ,    t          j                     dS )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                                        }t          j        |          }t          j        |           	 t          j        t          |                      t          j                     t          j        |t          j        |           t          j        |d           d S # 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JrNNN#..///"go{;;;
\""""" 	"go{;;;
\""""s   4B3 37C*c                     t          j        t          dd                     | t          j        dd          } | rt          j        | d                   }nt          }t          |           d S )Nz	child.logw   r   )	r
   startLoggingopenr;   argvr   
namedClassr6   rJ   )rP   rG   s     r   mainrR   e   sh    T+s++,,,|x| "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      sd  
  
			 



  



 8 8 8 8 8 8 0 0 0 0 0 0 < < < < < < < < < < < < 0 0 0 0 0 0 0 0 0 0	 	 	 	 	I 	 	 	/ / / / /h6 / / /d
 
 
 
 
^ 
 
 
	# 	# 	#	 	 	 	 zDFFFFF r   