示例#1
0
    def new_func(inp):
        old_stdin = sys.stdin
        old_stdout = sys.stdout
        old_stderr = sys.stderr

        sys.stdin = stream(inp)
        sys.stdout = stream()
        sys.stderr = stream()

        try:
            exit_code = func() or 0
        except SystemExit as e:
            exit_code = e.code
        except Exception:
            traceback.print_exc()
            exit_code = 1
        finally:
            out = sys.stdout.getvalue()
            err = sys.stderr.getvalue()

            sys.stdin = old_stdin
            sys.stdout = old_stdout
            sys.stderr = old_stderr

        return out, err, exit_code
示例#2
0
def sync_with_stdio(sync=True):
    global input, flush
    if sync:
        flush = sys.stdout.flush
    else:
        sys.stdin = stream(sys.stdin.read())
        input = lambda: sys.stdin.readline().rstrip('\r\n')
        sys.stdout = stream()
        register(lambda: sys.__stdout__.write(sys.stdout.getvalue()))
示例#3
0
def sync_with_stdio(sync=True):
    """Set whether the standard Python streams are allowed to buffer their I/O.
 
    Args:
        sync (bool, optional): The new synchronization setting.
 
    """
    global input, flush
 
    if sync:
        flush = sys.stdout.flush
    else:
        sys.stdin = stream(sys.stdin.read())
        input = lambda: sys.stdin.readline().rstrip('\r\n')
 
        sys.stdout = stream()
        register(lambda: sys.__stdout__.write(sys.stdout.getvalue()))
示例#4
0
from __future__ import division, print_function

import sys
from atexit import register

if sys.version_info[0] < 3:
    from io import BytesIO as stream
else:
    from io import StringIO as stream


sys.stdin = stream(sys.stdin.read())
input = lambda: sys.stdin.readline().rstrip('\r\n')

sys.stdout = stream()
register(lambda: sys.__stdout__.write(sys.stdout.getvalue()))