<s> """<STR_LIT>""" <EOL> import os <EOL> import errno <EOL> try : <EOL> import fcntl <EOL> except ImportError : <EOL> fcntl = None <EOL> from twisted . internet . main import CONNECTION_LOST , CONNECTION_DONE <EOL> from twisted . python . runtime import platformType <EOL> def setNonBlocking ( fd ) : <EOL> """<STR_LIT>""" <EOL> flags = fcntl . fcntl ( fd , fcntl . F_GETFL ) <EOL> flags = flags | os . O_NONBLOCK <EOL> fcntl . fcntl ( fd , fcntl . F_SETFL , flags ) <EOL> def setBlocking ( fd ) : <EOL> """<STR_LIT>""" <EOL> flags = fcntl . fcntl ( fd , fcntl . F_GETFL ) <EOL> flags = flags & ~ os . O_NONBLOCK <EOL> fcntl . fcntl ( fd , fcntl . F_SETFL , flags ) <EOL> if fcntl is None : <EOL> _setCloseOnExec = _unsetCloseOnExec = lambda fd : None <EOL> else : <EOL> def _setCloseOnExec ( fd ) : <EOL> """<STR_LIT>""" <EOL> flags = fcntl . fcntl ( fd , fcntl . F_GETFD ) <EOL> flags = flags | fcntl . FD_CLOEXEC <EOL> fcntl . fcntl ( fd , fcntl . F_SETFD , flags ) <EOL> def _unsetCloseOnExec ( fd ) : <EOL> """<STR_LIT>""" <EOL> flags = fcntl . fcntl ( fd , fcntl . F_GETFD ) <EOL> flags = flags & ~ fcntl . FD_CLOEXEC <EOL> fcntl . fcntl ( fd , fcntl . F_SETFD , flags ) <EOL> def readFromFD ( fd , callback ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> output = os . read ( fd , <NUM_LIT> ) <EOL> except ( OSError , IOError ) , ioe : <EOL> if ioe . args [ <NUM_LIT:0> ] in ( errno . EAGAIN , errno . EINTR ) : <EOL> return <EOL> else : <EOL> return CONNECTION_LOST <EOL> if not output : <EOL> return CONNECTION_DONE <EOL> callback ( output ) <EOL> def writeToFD ( fd , data ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> return os . write ( fd , data ) <EOL> except ( OSError , IOError ) , io : <EOL> if io . errno in ( errno . EAGAIN , errno . EINTR ) : <EOL> return <NUM_LIT:0> <EOL> return CONNECTION_LOST <EOL> __all__ = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] </s>
