@contextmanager
def redirected_stdio(conn):
 orig_stdin = conn.modules.sys.stdin
 orig_stdout = conn.modules.sys.stdout
 orig_stderr = conn.modules.sys.stderr
 try:
  conn.modules.sys.stdin = restricted(sys.stdin, ['softspace', 'write', 'readline', 'encoding', 'close'])
  conn.modules.sys.stdout = restricted(sys.stdout, ['softspace', 'write', 'readline', 'encoding', 'close', 'flush'])
  conn.modules.sys.stderr = restricted(sys.stderr, ['softspace', 'write', 'readline', 'encoding', 'close', 'flush'])
  (yield)
 finally:
  conn.modules.sys.stdin = orig_stdin
  conn.modules.sys.stdout = orig_stdout
  conn.modules.sys.stderr = orig_stderr

@ contextmanager def redirected_stdio ( conn ) : orig_stdin = conn . modules . sys . stdin orig_stdout = conn . modules . sys . stdout orig_stderr = conn . modules . sys . stderr try : conn . modules . sys . stdin = restricted ( sys . stdin , [ 'softspace' , 'write' , 'readline' , 'encoding' , 'close' ] ) conn . modules . sys . stdout = restricted ( sys . stdout , [ 'softspace' , 'write' , 'readline' , 'encoding' , 'close' , 'flush' ] ) conn . modules . sys . stderr = restricted ( sys . stderr , [ 'softspace' , 'write' , 'readline' , 'encoding' , 'close' , 'flush' ] ) ( yield ) finally : conn . modules . sys . stdin = orig_stdin conn . modules . sys . stdout = orig_stdout conn . modules . sys . stderr = orig_stderr
redirects the other partys stdin .