# -*- coding: utf-8 -*-1"""2Set Up Input/output34Output should always be unbuffered so that it appears immediately on5the terminal.6"""78# ****************************************************************************9# Copyright (C) 2015 Volker Braun <[email protected]>10#11# This program is free software: you can redistribute it and/or modify12# it under the terms of the GNU General Public License as published by13# the Free Software Foundation, either version 2 of the License, or14# (at your option) any later version.15# https://www.gnu.org/licenses/16# ****************************************************************************17import sys181920class UnbufferedStream(object):2122def __init__(self, stream):23self.stream = stream2425def write(self, data):26self.stream.write(data)27self.stream.flush()2829def __getattr__(self, attr):30return getattr(self.stream, attr)313233REAL_STDOUT = sys.stdout34REAL_STDERR = sys.stderr353637def init_streams(config):38if not config.interactive:39sys.stdout = UnbufferedStream(REAL_STDOUT)404142def flush():43REAL_STDOUT.flush()44REAL_STDERR.flush()454647