epochs package

Submodules

epochs.configparser module

Module defining parsers. The ConfigParser is an extended configparser that can use a specification file to define types/default values for the config files options, as well as to validate the file against. The EpochParser is a parser which organizes options by date. An option value is found by matching the option in the section with the latest datetime before the given datetime.

class epochs.configparser.ConfigParser(spec_filename: str = None, **kwargs)[source]

Bases: configparser.ConfigParser

ConfigParser subclass which can verify a config file against a specification and uses types/defaults from the specification.

get(section: str, option: str, raw: bool = False, use_spec: bool = True, **kwargs) → OptionValue[source]

Get an option using the type and default from the specification file

Parameters:
  • section (str) – section name
  • option (str) – option name
  • raw (bool) – set to True to not interpolate
  • use_spec (bool) – set to False to not use the specification
is_valid(allow_extra_options: bool = False) → bool[source]

Verify that the ConfigParser matches the specification. A ConfigParser without a spec is automatically valid.

write(file: FileType, space_around_delimiters: bool = True) → None[source]

Write config file to a file-like object

Parameters:
  • file (FileType) – file-like object to write to
  • space_around_delimiters (bool) – whether to put spaces around the delimiter, i.e., “:” or “=”
class epochs.configparser.EpochConfigParser(spec_filename: str = None, **kwargs)[source]

Bases: object

EpochConfigParser parses config files with dates as section name. Retrieving an option for a given date returns the option value on the date closest, but before, the given date.

date
formats
get(option: str, date: DateValue = None, raw: bool = False, **kwargs) → OptionValue[source]

Get an option using the type and default from the specification file

Parameters:
  • option (str) – option name
  • date (FileValue) – date as a string or datetime.datetime
  • raw (bool) – set to True is disable interpolation
is_valid(allow_extra_options: bool = False) → bool[source]

Verify that the EpochParser matches the specification. A configparser without a spec is automatically valid.

read(files)[source]

Attempt to read and parse an iterable of filenames, returning a list of filenames which were successfully parsed.

write(file: FileType, space_around_delimiters: bool = True) → None[source]

Write config file to a file-like object

Parameters:
  • file (FileType) – file-like object to write to
  • space_around_delimiters (bool) – whether to put spaces around the delimiter, i.e., “:” or “=”
class epochs.configparser.OptionSpec

Bases: tuple

Specification for an option

default
list
required
type

Module contents

Top-level package for epochs.