pygvisuals.io package

Package for interacting with io-streams and similar.

class pygvisuals.io.StreamRedirector(stream, callback, timestampFormat='[%x %X] ')[source]

Bases: io.IOBase

Class for redirecting a stream to a callback-function. Whenever a new line is written into the underlying stream, the callback-function will be called with the input. Any write-operation applied to a StreamRedirector will still also be fully applied to the underlying stream.

Initialisation of a StreamRedirector.

Parameters
  • stream – A stream-like object to redirect from.

  • callback – A callback-function that recieves data as a string (single parameter).

  • timestampFormat – A string for formating a timestamp that will be prefixed to each data-string for the callback-function only. The format will be interpreted via time.strftime(timestampFormat); default is ‘[%x %X] ‘. If an empty string or any falsy expression is supplied, no prefix will be produced.

close()[source]

Close the underlying stream and flush the current buffer.

flush()[source]

Flush the underlying stream and the current buffer.

read(*args)[source]

Raise io.UnsupportedOperation as this stream-like object can not be read from.

writable()[source]

Return True as this stream-like object is writable.

write(input)[source]

Write to the underlying stream. If a new line is found also call the callback-function with every line.

Parameters

input – An appropriate object for the underlying stream to write.

property closed

True if the underlying stream is closed.

Submodules

pygvisuals.io.stream_redirector module

class pygvisuals.io.stream_redirector.StreamRedirector(stream, callback, timestampFormat='[%x %X] ')[source]

Bases: io.IOBase

Class for redirecting a stream to a callback-function. Whenever a new line is written into the underlying stream, the callback-function will be called with the input. Any write-operation applied to a StreamRedirector will still also be fully applied to the underlying stream.

Initialisation of a StreamRedirector.

Parameters
  • stream – A stream-like object to redirect from.

  • callback – A callback-function that recieves data as a string (single parameter).

  • timestampFormat – A string for formating a timestamp that will be prefixed to each data-string for the callback-function only. The format will be interpreted via time.strftime(timestampFormat); default is ‘[%x %X] ‘. If an empty string or any falsy expression is supplied, no prefix will be produced.

close()[source]

Close the underlying stream and flush the current buffer.

flush()[source]

Flush the underlying stream and the current buffer.

read(*args)[source]

Raise io.UnsupportedOperation as this stream-like object can not be read from.

writable()[source]

Return True as this stream-like object is writable.

write(input)[source]

Write to the underlying stream. If a new line is found also call the callback-function with every line.

Parameters

input – An appropriate object for the underlying stream to write.

property closed

True if the underlying stream is closed.