simplify StdCaptureFD snapshot reading

This commit is contained in:
Ronny Pfannschmidt 2014-01-22 19:48:10 +01:00
parent ea18e9656b
commit e2bb81124c
1 changed files with 9 additions and 10 deletions

View File

@ -538,17 +538,16 @@ class StdCaptureFD(Capture):
def readouterr(self): def readouterr(self):
""" return snapshot value of stdout/stderr capturings. """ """ return snapshot value of stdout/stderr capturings. """
if hasattr(self, "out"): out = self._readsnapshot('out')
out = self._readsnapshot(self.out.tmpfile) err = self._readsnapshot('err')
else: return out, err
out = ""
if hasattr(self, "err"): def _readsnapshot(self, name):
err = self._readsnapshot(self.err.tmpfile) if hasattr(self, name):
else: f = getattr(self, name).tmpfile
err = "" else:
return [out, err] return ''
def _readsnapshot(self, f):
f.seek(0) f.seek(0)
res = f.read() res = f.read()
enc = getattr(f, "encoding", None) enc = getattr(f, "encoding", None)