Skip to content

octoprint.filemanager.util#

AbstractFileWrapper #

Wrapper for file representations to save to storages.

Parameters:

Name Type Description Default
filename str

The file's name

required

save(path, permissions=None) #

Saves the file's content to the given absolute path.

Parameters:

Name Type Description Default
path str

The absolute path to where to save the file

required
permissions int

The permissions to set on the file

None

stream() #

Returns a Python stream object (subclass of io.IOBase) representing the file's contents.

Returns:

Type Description

io.IOBase: The file's contents as a stream.

DiskFileWrapper #

Bases: AbstractFileWrapper

An implementation of :class:.AbstractFileWrapper that wraps an actual file on disk. The save implementations will either copy the file to the new path (preserving file attributes) or -- if move is True (the default) -- move the file.

Parameters:

Name Type Description Default
filename str

The file's name

required
path str

The file's absolute path

required
move boolean

Whether to move the file upon saving (True, default) or copying.

True

LineProcessorStream #

Bases: io.RawIOBase

While reading from this stream the provided input_stream is read line by line, calling the (overridable) method :meth:.process_line for each read line.

Sub classes can thus modify the contents of the input_stream in line, while it is being read. Keep in mind that process_line will receive the line as a byte stream - if underlying code needs to operate on unicode you'll need to do the decoding yourself.

Parameters:

Name Type Description Default
input_stream io.RawIOBase

The stream to process on the fly.

required

process_line(line) #

Called from the read Method of this stream with each line read from self.input_stream.

By returning None the line will not be returned from the read stream, effectively being stripped from the wrapper input_stream.

Parameters:

Name Type Description Default
line bytes

The line as read from self.input_stream in byte representation

required

Returns:

Type Description

bytes or None: The processed version of the line (might also be multiple lines), or None if the line is to be stripped from the processed stream.

MultiStream #

Bases: io.RawIOBase

A stream implementation which when read reads from multiple streams, one after the other, basically concatenating their contents in the order they are provided to the constructor.

Parameters:

Name Type Description Default
*streams

One or more 🇵🇾class:io.IOBase streams to concatenate.

()

StreamWrapper #

Bases: AbstractFileWrapper

A wrapper allowing processing of one or more consecutive streams.

Parameters:

Name Type Description Default
*streams

One or more 🇵🇾class:io.IOBase streams to process one after another to save to storage.

()

save(path, permissions=None) #

Will dump the contents of all streams provided during construction into the target file, in the order they were provided.

stream() #

If more than one stream was provided to the constructor, will return a :class:.MultiStream wrapping all provided streams in the order they were provided, else the first and only stream is returned directly.

Back to top