rbtools.commands.base.output¶
Output management for commands.
New in version 5.0.
Classes
|
Output wrapper for JSON output. |
|
Wrapper for output of a command. |
- class rbtools.commands.base.output.JSONOutput(output_stream: TextIO)[source]¶
Bases:
object
Output wrapper for JSON output.
JSON outputter class that stores Command outputs in python dictionary and outputs as JSON object to output stream object. Commands should add any structured output to this object. JSON output is then enabled with the –json argument.
Changed in version 5.0: This moved from
rbtools.commands
torbtools.commands.base.commands
.New in version 3.0.
- __init__(output_stream: TextIO) None [source]¶
Initialize JSONOutput class.
- Parameters:
output_stream (
io.IOBase
) – Object to output JSON object to.
- append(key: str, value: Any) None [source]¶
Add new value to an existing list associated with key.
Changed in version 5.0: When appending to a non-list, a
TypeError
is now raised instead of aAttributeError
.
- add_error(error: str) None [source]¶
Add a new error to the “errors” key.
Append a new error to the
errors
key, creating one if needed.- Parameters:
error (
str
) – The error that will be added toerrors
.
- class rbtools.commands.base.output.OutputWrapper(output_stream: IO)[source]¶
Bases:
Generic
Wrapper for output of a command.
Wrapper around some output object that handles outputting messages. Child classes specify the default object. The wrapper can handle messages in either unicode or bytes.
Changed in version 5.0: This moved from
rbtools.commands
torbtools.commands.base.commands
.New in version 3.0.
- __init__(output_stream: IO) None [source]¶
Initialize with an output object to stream to.
- Parameters:
output_stream (
io.IOBase
) – The output stream to send command output to.
- __orig_bases__ = (typing.Generic[~AnyStr],)¶
- __parameters__ = (~AnyStr,)¶
- write(msg: ~typing.Optional[AnyStr] = None, end: ~typing.Union[AnyStr, ~rbtools.commands.base.output._Newline] = <rbtools.commands.base.output._Newline object>) None [source]¶
Write a message to the output stream.
Changed in version 5.0: This now handles incoming strings of either bytes or Unicode under the hood, but callers should take care to always use the intended string type. This behavior may change in future versions.