<s> """<STR_LIT>""" <EOL> import win32api <EOL> import os , msvcrt <EOL> from zope . interface import implements <EOL> from twisted . internet . interfaces import IHalfCloseableProtocol , ITransport , IAddress <EOL> from twisted . internet . interfaces import IConsumer , IPushProducer <EOL> from twisted . internet import _pollingfile , main <EOL> from twisted . python . failure import Failure <EOL> class Win32PipeAddress ( object ) : <EOL> implements ( IAddress ) <EOL> class StandardIO ( _pollingfile . _PollingTimer ) : <EOL> implements ( ITransport , <EOL> IConsumer , <EOL> IPushProducer ) <EOL> disconnecting = False <EOL> disconnected = False <EOL> def __init__ ( self , proto , reactor = None ) : <EOL> """<STR_LIT>""" <EOL> if reactor is None : <EOL> from twisted . internet import reactor <EOL> for stdfd in range ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> ) : <EOL> msvcrt . setmode ( stdfd , os . O_BINARY ) <EOL> _pollingfile . _PollingTimer . __init__ ( self , reactor ) <EOL> self . proto = proto <EOL> hstdin = win32api . GetStdHandle ( win32api . STD_INPUT_HANDLE ) <EOL> hstdout = win32api . GetStdHandle ( win32api . STD_OUTPUT_HANDLE ) <EOL> self . stdin = _pollingfile . _PollableReadPipe ( <EOL> hstdin , self . dataReceived , self . readConnectionLost ) <EOL> self . stdout = _pollingfile . _PollableWritePipe ( <EOL> hstdout , self . writeConnectionLost ) <EOL> self . _addPollableResource ( self . stdin ) <EOL> self . _addPollableResource ( self . stdout ) <EOL> self . proto . makeConnection ( self ) <EOL> def dataReceived ( self , data ) : <EOL> self . proto . dataReceived ( data ) <EOL> def readConnectionLost ( self ) : <EOL> if IHalfCloseableProtocol . providedBy ( self . proto ) : <EOL> self . proto . readConnectionLost ( ) <EOL> self . checkConnLost ( ) <EOL> def writeConnectionLost ( self ) : <EOL> if IHalfCloseableProtocol . providedBy ( self . proto ) : <EOL> self . proto . writeConnectionLost ( ) <EOL> self . checkConnLost ( ) <EOL> connsLost = <NUM_LIT:0> <EOL> def checkConnLost ( self ) : <EOL> self . connsLost += <NUM_LIT:1> <EOL> if self . connsLost >= <NUM_LIT:2> : <EOL> self . disconnecting = True <EOL> self . disconnected = True <EOL> self . proto . connectionLost ( Failure ( main . CONNECTION_DONE ) ) <EOL> def write ( self , data ) : <EOL> self . stdout . write ( data ) <EOL> def writeSequence ( self , seq ) : <EOL> self . stdout . write ( '<STR_LIT>' . join ( seq ) ) <EOL> def loseConnection ( self ) : <EOL> self . disconnecting = True <EOL> self . stdin . close ( ) <EOL> self . stdout . close ( ) <EOL> def getPeer ( self ) : <EOL> return Win32PipeAddress ( ) <EOL> def getHost ( self ) : <EOL> return Win32PipeAddress ( ) <EOL> def registerProducer ( self , producer , streaming ) : <EOL> return self . stdout . registerProducer ( producer , streaming ) <EOL> def unregisterProducer ( self ) : <EOL> return self . stdout . unregisterProducer ( ) <EOL> def stopProducing ( self ) : <EOL> self . stdin . stopProducing ( ) <EOL> def pauseProducing ( self ) : <EOL> self . stdin . pauseProducing ( ) <EOL> def resumeProducing ( self ) : <EOL> self . stdin . resumeProducing ( ) </s>
