Total Complexity | 2 |
Total Lines | 15 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | import sys |
||
5 | class OutputCapture(object): |
||
6 | """Context manager which records stdout writes. |
||
7 | |||
8 | Used when recording python-based transformations. |
||
9 | """ |
||
10 | |||
11 | def __enter__(self): |
||
12 | self.oldstdout = sys.stdout |
||
13 | sys.stdout = self.stdout = StringIO() |
||
14 | return self |
||
15 | |||
16 | def __exit__(self, type, value, traceback): |
||
17 | sys.stdout = self.oldstdout |
||
18 | self.output = self.stdout.getvalue() |
||
19 | self.stdout.close() |
||
20 |