OutputCapture   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __exit__() 0 4 1
A __enter__() 0 4 1
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