RedirectedStreams

class systemtools.RedirectedStreams(stdout=None, stderr=None)

A context manager for capturing stdout and stderr output.

>>> try:
...     from StringIO import StringIO
... except ImportError:
...     from io import StringIO
...
>>> string_io = StringIO()
>>> with systemtools.RedirectedStreams(stdout=string_io):
...     print("hello, world!")
...
>>> result = string_io.getvalue()
>>> string_io.close()
>>> print(result)
hello, world!

Redirected streams context manager is immutable.

Lineage

digraph InheritanceGraph { graph [background=transparent, bgcolor=transparent, color=lightslategrey, fontname=Arial, outputorder=edgesfirst, overlap=prism, penwidth=2, rankdir=LR, root="__builtin__.object", splines=spline, style="dotted, rounded", truecolor=true]; node [colorscheme=pastel19, fontname=Arial, fontsize=12, penwidth=2, style="filled, rounded"]; edge [color=lightsteelblue2, penwidth=2]; subgraph cluster_abctools { graph [label=abctools]; "abjad.tools.abctools.AbjadObject.AbjadObject" [color=1, group=0, label=AbjadObject, shape=box]; "abjad.tools.abctools.AbjadObject.AbstractBase" [color=1, group=0, label=AbstractBase, shape=box]; "abjad.tools.abctools.ContextManager.ContextManager" [color=1, group=0, label=ContextManager, shape=oval, style=bold]; "abjad.tools.abctools.AbjadObject.AbjadObject" -> "abjad.tools.abctools.ContextManager.ContextManager"; "abjad.tools.abctools.AbjadObject.AbstractBase" -> "abjad.tools.abctools.AbjadObject.AbjadObject"; } subgraph cluster_systemtools { graph [label=systemtools]; "abjad.tools.systemtools.RedirectedStreams.RedirectedStreams" [color=black, fontcolor=white, group=2, label=<<B>RedirectedStreams</B>>, shape=box, style="filled, rounded"]; } subgraph cluster_builtins { graph [label=builtins]; "builtins.object" [color=2, group=1, label=object, shape=box]; } "abjad.tools.abctools.ContextManager.ContextManager" -> "abjad.tools.systemtools.RedirectedStreams.RedirectedStreams"; "builtins.object" -> "abjad.tools.abctools.AbjadObject.AbstractBase"; }

Bases

Attribute summary

stderr Gets stderr of context manager.
stdout Gets stdout of context manager.
__enter__() Enters redirected streams context manager.
__eq__(expr) Is true when ID of expr equals ID of Abjad object.
__exit__(exc_type, exc_value, traceback) Exits redirected streams context manager.
__format__([format_specification]) Formats Abjad object.
__hash__() Hashes Abjad object.
__ne__(expr) Is true when Abjad object does not equal expr.
__repr__() Gets interpreter representation of context manager.

Read-only properties

RedirectedStreams.stderr

Gets stderr of context manager.

RedirectedStreams.stdout

Gets stdout of context manager.

Special methods

RedirectedStreams.__enter__()

Enters redirected streams context manager.

Returns none.

(AbjadObject).__eq__(expr)

Is true when ID of expr equals ID of Abjad object. Otherwise false.

Returns true or false.

RedirectedStreams.__exit__(exc_type, exc_value, traceback)

Exits redirected streams context manager.

Returns none.

(AbjadObject).__format__(format_specification='')

Formats Abjad object.

Set format_specification to ‘’ or ‘storage’. Interprets ‘’ equal to ‘storage’.

Returns string.

(AbjadObject).__hash__()

Hashes Abjad object.

Required to be explicitly redefined on Python 3 if __eq__ changes.

Returns integer.

(AbjadObject).__ne__(expr)

Is true when Abjad object does not equal expr. Otherwise false.

Returns true or false.

RedirectedStreams.__repr__()

Gets interpreter representation of context manager.

>>> context_manager = systemtools.RedirectedStreams()
>>> context_manager
<RedirectedStreams()>

Returns string.