__init__.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. #
  2. # The Qubes OS Project, https://www.qubes-os.org/
  3. #
  4. # Copyright (C) 2015 Marek Marczykowski-Górecki
  5. # <marmarek@invisiblethingslab.com>
  6. #
  7. # This library is free software; you can redistribute it and/or
  8. # modify it under the terms of the GNU Lesser General Public
  9. # License as published by the Free Software Foundation; either
  10. # version 2.1 of the License, or (at your option) any later version.
  11. #
  12. # This library is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. # Lesser General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Lesser General Public
  18. # License along with this library; if not, see <https://www.gnu.org/licenses/>.
  19. #
  20. import io
  21. import sys
  22. class StdoutBuffer(object):
  23. def __init__(self):
  24. self.stdout = io.StringIO()
  25. def __enter__(self):
  26. sys.stdout = self.stdout
  27. return self.stdout
  28. def __exit__(self, exc_type, exc_val, exc_tb):
  29. sys.stdout = sys.__stdout__
  30. return False