o
    Òó·iÕ
  ã                   @   sÂ   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„ deƒZG d	d
„ d
ejƒZG dd„ deƒZdd„ Zd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                   @   s   e Zd ZdS )ÚUnexpectedOutputErrorN)Ú__name__Ú
__module__Ú__qualname__© r   r   úYC:\Users\psant\Downloads\PAF backend\school\venv\Lib\site-packages\twisted/conch/stdio.pyr      s    r   c                   @   sD   e Z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 )ÚTerminalProcessProtocolc                 C   s   || _ t ¡ | _d S ©N)Úprotor   ZDeferredÚonConnection)Úselfr   r   r   r   Ú__init__   s   z TerminalProcessProtocol.__init__c                 C   s"   | j  | ¡ | j d ¡ d | _d S r   )r   ZmakeConnectionr   Úcallback)r   r   r   r   ÚconnectionMade   s   
z&TerminalProcessProtocol.connectionMadec                 C   ó   | j  |¡ dS )zj
        Write to the terminal.

        @param data: Data to write.
        @type data: L{bytes}
        N)Ú	transportÚwrite©r   Údatar   r   r   r   $   ó   zTerminalProcessProtocol.writec                 C   r   )zs
        Receive data from the terminal.

        @param data: Data received.
        @type data: L{bytes}
        N)r   ZdataReceivedr   r   r   r   ÚoutReceived-   r   z#TerminalProcessProtocol.outReceivedc                 C   s8   | j  ¡  | jdur| j t t|ƒ¡¡ d| _dS dS )zt
        Report an error.

        @param data: Data to include in L{Failure}.
        @type data: L{bytes}
        N)r   ZloseConnectionr   ÚconnectionLostr   ZFailurer   r   r   r   r   ÚerrReceived6   s
   


þz#TerminalProcessProtocol.errReceivedc                 C   s   | j d ur| j  |¡ d S d S r   )r   ÚchildConnectionLost)r   ZchildFDr   r   r   r"   B   s   
ÿz+TerminalProcessProtocol.childConnectionLostc                 C   s$   | j d ur| j  |¡ d | _ d S d S r   )r   r    ©r   Úreasonr   r   r   ÚprocessEndedF   s   

þz$TerminalProcessProtocol.processEndedN)
r   r   r   r   r   r   r   r!   r"   r%   r   r   r   r   r      s    		r   c                   @   s   e Zd ZdZdd„ ZdS )ÚConsoleManholezK
    A manhole protocol specifically for use with L{stdio.StandardIO}.
    c                 C   s   t  ¡  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   Ústopr#   r   r   r   r    Q   s   zConsoleManhole.connectionLostN)r   r   r   Ú__doc__r    r   r   r   r   r&   L   s    r&   c                 C   sv   t j ¡ }t |¡}t |¡ zt t	| ƒ¡ t
 ¡  W t |tj|¡ t |d¡ d S t |tj|¡ t |d¡ w )Ns   c)ÚsysÚ	__stdin__ÚfilenoÚtermiosÚ	tcgetattrÚttyZsetrawr   Z
StandardIOr   r   ÚrunÚ	tcsetattrZTCSANOWÚosr   )ÚklassÚfdZoldSettingsr   r   r   ÚrunWithProtocolY   s   



ÿr4   c                 C   sJ   t  tddƒ¡ | d u rtjdd … } | rt | d ¡}nt}t|ƒ d S )Nz	child.logÚwé   r   )	r	   ZstartLoggingÚopenr)   Úargvr
   Z
namedClassr&   r4   )r8   r2   r   r   r   Úmaine   s   r9   Ú__main__r   )r(   r1   r)   r,   r.   Ztwisted.conch.insults.insultsr   Ztwisted.conch.manholer   Ztwisted.internetr   r   r   r   Ztwisted.pythonr   r	   r
   Ú	Exceptionr   ZProcessProtocolr   r&   r4   r9   r   r   r   r   r   Ú<module>   s"   2

ÿ