@contextmanager
def stdio_as(stdout, stderr, stdin=None):
 (old_stdout, sys.stdout) = (sys.stdout, stdout)
 (old_stderr, sys.stderr) = (sys.stderr, stderr)
 if stdin:
  (old_stdin, sys.stdin) = (sys.stdin, stdin)
 (yield)
 (sys.stdout, sys.stderr) = (old_stdout, old_stderr)
 if stdin:
  sys.stdin = old_stdin

@ contextmanager def stdio_as ( stdout , stderr , stdin = None ) : ( old_stdout , sys . stdout ) = ( sys . stdout , stdout ) ( old_stderr , sys . stderr ) = ( sys . stderr , stderr ) if stdin : ( old_stdin , sys . stdin ) = ( sys . stdin , stdin ) ( yield ) ( sys . stdout , sys . stderr ) = ( old_stdout , old_stderr ) if stdin : sys . stdin = old_stdin
redirect sys .