BaseHandler#

class fourinsight.engineroom.utils.BaseHandler(*args, **kwargs)[source]#

Abstract class for push/pull text content from a remote/persistent source.

The class inherits from io.TextIOWrapper, and will behave like a stream.

Parameters:
  • *args (tuple) – Passed on to the TextIOWrapper’s constructor.

  • **kwargs (dict, optional) – Passed on to the TextIOWrapper’s constructor.

close()#

Flush and close the IO object.

This method has no effect if the file is already closed.

detach()#

Separate the underlying buffer from the TextIOBase and return it.

After the underlying buffer has been detached, the TextIO is in an unusable state.

encoding#
errors#
fileno()#

Return underlying file descriptor if one exists.

Raise OSError if the IO object does not use a file descriptor.

flush()#

Flush write buffers, if applicable.

This is not implemented for read-only and non-blocking streams.

getvalue()[source]#

Get all stream content (without changing the stream position).

Returns:

Retrieve the entire content of the object.

Return type:

str

isatty()#

Return whether this is an ‘interactive’ stream.

Return False if it can’t be determined.

newlines#
pull(raise_on_missing=True)[source]#

Pull text content from source, and overwrite the original content of the stream.

Parameters:

raise_on_missing (bool) – Raise exception if content can not be pulled from source.

push()[source]#

Push text content to source.

read(size=-1, /)#

Read at most size characters from stream.

Read from underlying buffer until we have size characters or we hit EOF. If size is negative or omitted, read until EOF.

readable()#

Return whether object was opened for reading.

If False, read() will raise OSError.

readline(size=-1, /)#

Read until newline or EOF.

Return an empty string if EOF is hit immediately. If size is specified, at most size characters will be read.

readlines(hint=-1, /)#

Return a list of lines from the stream.

hint can be specified to control the number of lines read: no more lines will be read if the total size (in bytes/characters) of all lines so far exceeds hint.

reconfigure(*, encoding=None, errors=None, newline=None, line_buffering=None, write_through=None)#

Reconfigure the text stream with new parameters.

This also does an implicit stream flush.

seek(cookie, whence=0, /)#

Set the stream position, and return the new stream position.

cookie

Zero or an opaque number returned by tell().

whence

The relative position to seek from.

Four operations are supported, given by the following argument combinations:

  • seek(0, SEEK_SET): Rewind to the start of the stream.

  • seek(cookie, SEEK_SET): Restore a previous position; ‘cookie’ must be a number returned by tell().

  • seek(0, SEEK_END): Fast-forward to the end of the stream.

  • seek(0, SEEK_CUR): Leave the current stream position unchanged.

Any other argument combinations are invalid, and may raise exceptions.

seekable()#

Return whether object supports random access.

If False, seek(), tell() and truncate() will raise OSError. This method may need to do a test seek().

tell()#

Return the stream position as an opaque number.

The return value of tell() can be given as input to seek(), to restore a previous stream position.

truncate(pos=None, /)#

Truncate file to size bytes.

File pointer is left unchanged. Size defaults to the current IO position as reported by tell(). Return the new size.

writable()#

Return whether object was opened for writing.

If False, write() will raise OSError.

write(text, /)#

Write string s to stream.

Return the number of characters written (which is always equal to the length of the string).

writelines(lines, /)#

Write a list of lines to stream.

Line separators are not added, so it is usual for each of the lines provided to have a line separator at the end.