specio.core.Request

class specio.core.Request(uri, **kwargs)[source][source]

Interface between a plugin and the spectra resource.

Represents a request for reading an spectra resource. This object wraps information to that request and acts as an interface for the plugins to several resources; it allows the user to read from filenames, files but offer a simple interface to the plugins via get_file() and specio.get_local_filename().

For each read operation a single Request instance is used and passed to the can_read method of a format, and subsequently to the Reader class. This allows rudimentary passing of information between different formats and between a format and associated reader.

Parameters:

uri : {str, file}

The resource to load the image from.

kwargs : dict

Keywords to pass to the plugin.

__init__(uri, **kwargs)[source][source]

Methods

__init__(uri, **kwargs)
get_file() Get a file object for the resource.
get_local_filename() Get the filename of the resource.
filename

Filename of the resource.

firstbytes

The first 256 bytes of the file. These can be used to parse the header to determine the file-format.

get_file()[source][source]

Get a file object for the resource.

Get a file object for the resource associated with this request. This method is not thread safe. Plugins do not need to close the file when done.

This is the preferred way to read the data. But if a format cannot handle file-like objects, they should use get_local_filename().

Parameters:

None

Returns:

file : file object

The file object associated with the resource.

get_local_filename()[source][source]

Get the filename of the resource.

If the filename is an existing file on this filesystem, return that.

Parameters:

None

Returns:

filename : str

The filename associated with the resource.

kwargs

Keywords required to read the file.