o ¯bÕ ã@sÂdZddlZddlZddlZddlZddlmZddlmZddl m Z m Z m Z m Z ddlmZmZmZGdd„deƒZGd d „d e jƒZGd d „d eƒZd d„Zddd„Zedkr_eƒdSdS)zC Asynchronous local terminal input handling @author: Jp Calderone éN)ÚServerProtocol)ÚColoredManhole)ÚdeferÚprotocolÚreactorÚstdio)ÚfailureÚlogÚreflectc@s eZdZdS)ÚUnexpectedOutputErrorN)Ú__name__Ú __module__Ú __qualname__©rrú5/usr/lib/python3/dist-packages/twisted/conch/stdio.pyr sr c@sDeZdZdd„Zdd„Zdd„Zdd„Zd d „Zd d „Zd d„Z dS)ÚTerminalProcessProtocolcCs||_t ¡|_dS©N)ÚprotorÚDeferredÚ onConnection)ÚselfrrrrÚ__init__sz TerminalProcessProtocol.__init__cCs"|j |¡|j d¡d|_dSr)rÚmakeConnectionrÚcallback)rrrrÚconnectionMades   z&TerminalProcessProtocol.connectionMadecCó|j |¡dS)zj Write to the terminal. @param data: Data to write. @type data: L{bytes} N)Ú transportÚwrite©rÚdatarrrr$ózTerminalProcessProtocol.writecCr)zs Receive data from the terminal. @param data: Data received. @type data: L{bytes} N)rÚ dataReceivedrrrrÚ outReceived-r z#TerminalProcessProtocol.outReceivedcCs8|j ¡|jdur|j t t|ƒ¡¡d|_dSdS)zt Report an error. @param data: Data to include in L{Failure}. @type data: L{bytes} N)rÚloseConnectionrÚconnectionLostrÚFailurer rrrrÚ errReceived6s   þz#TerminalProcessProtocol.errReceivedcCs|jdur |j |¡dSdSr)rÚchildConnectionLost)rÚchildFDrrrr'Bs ÿz+TerminalProcessProtocol.childConnectionLostcCs$|jdur|j |¡d|_dSdSr)rr$©rÚreasonrrrÚ processEndedFs   þz$TerminalProcessProtocol.processEndedN) r r rrrrr"r&r'r+rrrrrs   rc@seZdZdZdd„ZdS)ÚConsoleManholezK A manhole protocol specifically for use with L{stdio.StandardIO}. cCs t ¡dS)zƒ When the connection is lost, there is nothing more to do. Stop the reactor so that the process can exit. N)rÚstopr)rrrr$Qs zConsoleManhole.connectionLostN)r r rÚ__doc__r$rrrrr,Ls r,c Csvtj ¡}t |¡}t |¡zt t |ƒ¡t   ¡Wt  |tj |¡t |d¡dSt  |tj |¡t |d¡w)Ns c )ÚsysÚ __stdin__ÚfilenoÚtermiosÚ tcgetattrÚttyÚsetrawrÚ StandardIOrrÚrunÚ tcsetattrÚTCSANOWÚosr)ÚklassÚfdÚ oldSettingsrrrÚrunWithProtocolYs    ÿr>cCsJt tddƒ¡|durtjdd…}|rt |d¡}nt}t|ƒdS)Nz child.logÚwér) r Ú startLoggingÚopenr/Úargvr Ú namedClassr,r>)rCr;rrrÚmaines rEÚ__main__r)r.r:r/r2r4Útwisted.conch.insults.insultsrÚtwisted.conch.manholerÚtwisted.internetrrrrÚtwisted.pythonrr r Ú Exceptionr ÚProcessProtocolrr,r>rEr rrrrÚs"  2  ÿ