My dotfiles
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 

34 lignes
633 B

  1. # Copyright (c) Microsoft Corporation. All rights reserved.
  2. # Licensed under the MIT License.
  3. import contextlib
  4. try:
  5. from io import StringIO
  6. except ImportError:
  7. from StringIO import StringIO # 2.7
  8. import sys
  9. @contextlib.contextmanager
  10. def noop_cm():
  11. yield
  12. @contextlib.contextmanager
  13. def hide_stdio():
  14. """Swallow stdout and stderr."""
  15. ignored = IgnoredIO()
  16. sys.stdout = ignored
  17. sys.stderr = ignored
  18. try:
  19. yield
  20. finally:
  21. sys.stdout = sys.__stdout__
  22. sys.stderr = sys.__stderr__
  23. class IgnoredIO(StringIO):
  24. """A noop "file"."""
  25. def write(self, msg):
  26. pass