source: orange/Orange/OrangeCanvas/utils/redirect.py @ 11167:74773cf295d6

Revision 11167:74773cf295d6, 660 bytes checked in by Ales Erjavec <ales.erjavec@…>, 18 months ago (diff)

Added 'Output' window showing redirected stdout/stderr.

Line 
1import sys
2from contextlib import contextmanager
3
4
5@contextmanager
6def redirect_stdout(replacement=None):
7    old = sys.stdout
8    if replacement is not None:
9        sys.stdout = replacement
10
11    try:
12        yield
13    finally:
14        sys.stdout = old
15
16
17@contextmanager
18def redirect_stderr(replacement=None):
19    old = sys.stderr
20    if replacement is not None:
21        sys.stderr = replacement
22
23    try:
24        yield
25    finally:
26        sys.stderr = old
27
28
29@contextmanager
30def redirect_stdin(replacement=None):
31    old = sys.stdin
32    if replacement is not None:
33        sys.stdin = replacement
34
35    try:
36        yield
37    finally:
38        sys.stdin = old
Note: See TracBrowser for help on using the repository browser.