Ejemplo n.º 1
0
    setattr(module, 'StringIO', _pyio.StringIO)
    setattr(module, '_IOBase', _pyio.IOBase)
    setattr(module, 'BufferedIOBase', _pyio.BufferedIOBase)
    setattr(module, 'RawIOBase', _pyio.RawIOBase)
    setattr(module, 'FileIO', _pyio.FileIO)
    setattr(module, 'BytesIO', _pyio.BytesIO)
    setattr(module, '_TextIOBase', _pyio.TextIOBase)

setattr(builtins, 'open', open)

sys.stdin = _pyio.TextIOWrapper(_pyio.BufferedReader(sys.stdin),
                                encoding="utf-8",
                                line_buffering=True)
sys.stdin.mode = "r"
sys.__stdin__ = sys.stdin
sys.stdout = _pyio.TextIOWrapper(_pyio.BufferedWriter(sys.stdout),
                                 encoding="utf-8",
                                 line_buffering=True)
sys.stdout.mode = "w"
sys.__stdout__ = sys.stdout
sys.stderr = _pyio.TextIOWrapper(_pyio.BufferedWriter(sys.stderr),
                                 encoding="utf-8",
                                 errors="backslashreplace",
                                 line_buffering=True)
sys.stderr.mode = "w"
sys.__stderr__ = sys.stderr

# Try to close the std streams when we exit.
# To make this work reliably, we probably have to implement the _io module in Java
import atexit
Ejemplo n.º 2
0
    setattr(module, 'StringIO', _pyio.StringIO)
    setattr(module, '_IOBase', _pyio.IOBase)
    setattr(module, 'BufferedIOBase', _pyio.BufferedIOBase)
    setattr(module, 'RawIOBase', _pyio.RawIOBase)
    setattr(module, 'FileIO', _pyio.FileIO)
    setattr(module, 'BytesIO', _pyio.BytesIO)
    setattr(module, '_TextIOBase', _pyio.TextIOBase)


setattr(builtins, 'open', open)


sys.stdin = _pyio.TextIOWrapper(_pyio.BufferedReader(sys.stdin), encoding="utf-8", line_buffering=True)
sys.stdin.mode = "r"
sys.__stdin__ = sys.stdin
sys.stdout = _pyio.TextIOWrapper(_pyio.BufferedWriter(sys.stdout), encoding="utf-8", line_buffering=True)
sys.stdout.mode = "w"
sys.__stdout__ = sys.stdout
sys.stderr = _pyio.TextIOWrapper(_pyio.BufferedWriter(sys.stderr), encoding="utf-8", line_buffering=True)
sys.stderr.mode = "w"
sys.__stderr__ = sys.stderr


# Try to close the std streams when we exit. This currently doesn't work due to GR-25185
# To make this work reliably, we probably have to implement the _io module in Java
# import atexit
# def close_stdouts(so=sys.stdout, se=sys.stderr):
#     try:
#         so.close()
#     except:
#         pass