<s> import sys <EOL> import os <EOL> from twisted . internet . abstract import FileDescriptor <EOL> from twisted . internet import fdesc <EOL> class FD ( FileDescriptor ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , trigger , fname , mode ) : <EOL> super ( FD , self ) . __init__ ( ) <EOL> self . trigger = trigger <EOL> self . _init_fp ( fname , mode ) <EOL> fdesc . setNonBlocking ( self ) <EOL> self . connected = True <EOL> self . data = b"<STR_LIT>" <EOL> def _init_fp ( self , fname , mode ) : <EOL> self . fp = open ( fname , mode , buffering = <NUM_LIT> ) <EOL> if "<STR_LIT:w>" in mode : <EOL> self . startWriting ( ) <EOL> if "<STR_LIT:r>" in mode : <EOL> self . filelen = os . path . getsize ( fname ) <EOL> self . totalread = <NUM_LIT:0> <EOL> self . startReading ( ) <EOL> def fileno ( self ) : <EOL> return self . fp . fileno ( ) <EOL> def writeSomeData ( self , data ) : <EOL> return fdesc . writeToFD ( self . fp . fileno ( ) , data ) <EOL> def _closeWriteConnection ( self ) : <EOL> self . connected = False <EOL> self . fp . close ( ) <EOL> def writeLine ( self , data ) : <EOL> self . write ( data + "<STR_LIT:\n>" ) <EOL> def dataRead ( self , data ) : <EOL> self . totalread += len ( data ) <EOL> self . data += data <EOL> def doRead ( self ) : <EOL> self . trigger ( ) <EOL> return fdesc . readFromFD ( self . fp . fileno ( ) , self . dataRead ) <EOL> def hasData ( self ) : <EOL> return len ( self . data ) <EOL> def endOfFile ( self ) : <EOL> """<STR_LIT>""" <EOL> return len ( self . data ) == <NUM_LIT:0> and self . totalread == self . filelen <EOL> def readLine ( self ) : <EOL> """<STR_LIT>""" <EOL> line , _ , self . data = self . data . partition ( "<STR_LIT:\n>" ) <EOL> return line <EOL> def close ( self ) : <EOL> self . loseConnection ( ) <EOL> def read ( self ) : <EOL> """<STR_LIT>""" <EOL> data = self . data <EOL> self . data = b"<STR_LIT>" <EOL> return data <EOL> class FDStdIn ( FD ) : <EOL> def __init__ ( self , trigger ) : <EOL> super ( FDStdIn , self ) . __init__ ( trigger , None , None ) <EOL> def _init_fp ( self , * args ) : <EOL> self . fp = sys . stdin <EOL> self . totalread = <NUM_LIT:0> <EOL> self . startReading ( ) <EOL> def endOfFile ( self ) : <EOL> """<STR_LIT>""" <EOL> return False </s>
