OutputCapture.__exit__()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
import sys 
2
from cStringIO import StringIO 
3
4
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