Example #1
0
def MakeFile_PY3(sock, mode='r', bufsize=io.DEFAULT_BUFFER_SIZE):
    if 'r' in mode:
        return io.BufferedReader(socket.SocketIO(sock, mode), bufsize)
    else:
        return BufferedWriter(socket.SocketIO(sock, mode), bufsize)
Example #2
0
    setattr(module, 'BufferedRWPair', _pyio.BufferedRWPair)
    setattr(module, 'BufferedWriter', _pyio.BufferedWriter)
    setattr(module, 'BufferedReader', _pyio.BufferedReader)
    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:
Example #3
0
            _pyio.IncrementalNewlineDecoder)
    setattr(module, 'BufferedRandom', _pyio.BufferedRandom)
    setattr(module, 'BufferedRWPair', _pyio.BufferedRWPair)
    setattr(module, 'BufferedWriter', _pyio.BufferedWriter)
    setattr(module, 'BufferedReader', _pyio.BufferedReader)
    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
def MakeFile_PY3(sock, mode='r', bufsize=io.DEFAULT_BUFFER_SIZE):
    """File object attached to a socket object."""
    if 'r' in mode:
        return io.BufferedReader(socket.SocketIO(sock, mode), bufsize)
    else:
        return BufferedWriter(socket.SocketIO(sock, mode), bufsize)