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):
""" return snapshot value of stdout/stderr capturings. """
if hasattr(self, "out"):
out = self._readsnapshot(self.out.tmpfile)
else:
out = ""
if hasattr(self, "err"):
err = self._readsnapshot(self.err.tmpfile)
else:
err = ""
return [out, err]
out = self._readsnapshot('out')
err = self._readsnapshot('err')
return out, err
def _readsnapshot(self, name):
if hasattr(self, name):
f = getattr(self, name).tmpfile
else:
return ''
def _readsnapshot(self, f):
f.seek(0)
res = f.read()
enc = getattr(f, "encoding", None)