Sources

In order to keep the parser extensible, input sources are represented as Source objects. That way, the parser can work with any kind of input that adheres to this interface.

This implementation provides two source implementations, one for strings and one for files. Both implementations are considered internal and are only accessible through the parser interface.

Interface

class Source

Abstract base class for configuration sources.

abstractmethod open() None

Open the source.

Raises:

ConfIoError – If the source cannot be opened.

abstractmethod is_open() bool

Return True if the source is open, False otherwise.

abstractmethod readline() str

Read a single line from the source.

Returns:

The line read, or an empty string if the end of the source has been reached.

Raises:
abstractmethod start_digest_calculation()

Start or restart the digest calculation.

The digest calculation shall start at the next readline() call. If the digest calculation is already running, it shall be restarted.

Raises:

NotImplementedError – If the source does not support digest calculation.

abstractmethod get_digest() str

Get the digest of the source.

The document digest shall always be reported as a string in the format <algorithm> <digest>. Algorithm is the lowercase name of the algorithm used, e.g. sha3-256. Digest is the hexadecimal representation of the digest.

Returns:

The digest of the source or an empty string if digests are not supported.

abstractmethod close()

Close the source.

abstract property identifier: SourceIdentifier

Return the SourceIdentifier for this source.

class SourceIdentifier(name: str, path: str)

Identify the origin of configuration data.

Variables:
  • name – Human-readable type of the source, e.g. "file".

  • path – Location of the source, such as a file path.

to_text(*, compact=False) str

Return a user-friendly representation of the source identifier.

Parameters:

compact – If True, return a compact representation.