def _read_temp(data): tout = StringIO() tout.write(data) tout.seek(0) output = tout.read().splitlines() # Discard newlines tout.close() return output
class _DelegateIO(object): ''' This class defines an object that captures whatever is written to a stream or file. ''' def __init__(self, delegate): self._captured = StringIO() self.delegate = delegate def write(self, text): if six.PY2 and isinstance(text, six.text_type): text = text.encode(__salt_system_encoding__) self._captured.write(text) self.delegate.write(text) def __getattr__(self, attr): try: return getattr(self._captured, attr) except AttributeError: return getattr(self.delegate, attr)