FileHandler

class typhon.files.handlers.common.FileHandler(reader=None, info=None, writer=None, **kwargs)[source]

Base file handler class.

This can be used alone or with the FileSet classes. You can either initialize specific reader ,*info* or writer functions or you can inherit from this class and override its methods. If you need a very specialised and reusable file handler class, you should consider following the second approach.

__init__(reader=None, info=None, writer=None, **kwargs)[source]

Initialize a filer handler object.

Parameters:
  • reader – Reference to a function that defines how to read a given file and returns an object with the read data. The function must accept a FileInfo object as first parameter.

  • info – Reference to a function that returns a FileInfo object with information about the given file. You cannot use the get_info() without setting this parameter. The function must accept a filename as string as first parameter.

  • writer – Reference to a function that defines how to write the data to a file. The function must accept the data object as first and a FileInfo object as second parameter.

Methods

__init__([reader, info, writer])

Initialize a filer handler object.

get_info(filename, **kwargs)

Return a FileInfo object with parameters about the file content.

read(filename, **kwargs)

Open a file by its name, read its content and return it

write(data, filename, **kwargs)

Store a data object to a file.