<s> EOF = b'<STR_LIT>' <EOL> def ttyflags ( fd ) : <EOL> """<STR_LIT>""" <EOL> import termios as T <EOL> attrs = T . tcgetattr ( fd ) <EOL> attrs [ <NUM_LIT:1> ] &= ~ T . OPOST <EOL> attrs [ <NUM_LIT:3> ] &= ~ T . ECHO <EOL> T . tcsetattr ( fd , T . TCSANOW , attrs ) <EOL> def readall ( fd ) : <EOL> """<STR_LIT>""" <EOL> from os import read <EOL> result = b'<STR_LIT>' <EOL> while True : <EOL> try : <EOL> chunk = read ( fd , <NUM_LIT:1> << <NUM_LIT:10> ) <EOL> except OSError as error : <EOL> if error . errno == <NUM_LIT:5> : <EOL> return result <EOL> else : <EOL> raise <EOL> if chunk == '<STR_LIT>' : <EOL> return result <EOL> else : <EOL> result += chunk <EOL> def _test ( fd ) : <EOL> """<STR_LIT>""" <EOL> ttyflags ( fd ) <EOL> from os import write <EOL> assert write ( fd , b'<STR_LIT>' ) == <NUM_LIT:6> <EOL> assert write ( fd , EOF * <NUM_LIT:2> ) == <NUM_LIT:2> <EOL> output = readall ( fd ) <EOL> assert output == b'<STR_LIT>' , repr ( output ) <EOL> print ( '<STR_LIT>' ) <EOL> def test_tty ( debug_disabled ) : <EOL> """<STR_LIT>""" <EOL> import pty <EOL> pid , fd = pty . fork ( ) <EOL> if pid == <NUM_LIT:0> : <EOL> from os import execvp <EOL> execvp ( '<STR_LIT>' , ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> else : <EOL> _test ( fd ) </s>
