rechu.io package
rechu.io.base module
Abstract base classes for file reading, writing and parsing.
-
class rechu.io.base.Reader(path: Path, updated: datetime = datetime.datetime(1, 1, 1, 0, 0))[source]
Bases: Generic[T]
File reader.
-
abstractmethod parse(file: TextIO) → Iterator[T][source]
Parse an open file and yield specific models from it.
This method raises TypeError or subclasses if certain data in the
file does not have the correct type, and ValueError or subclasses if
the data has inconsistent or out-of-range values.
-
property path: Path
Retrieve the path from which to read the models.
-
read() → Iterator[T][source]
Read the file from the path and yield specific models from it.
-
class rechu.io.base.Writer(path: Path, models: Collection[T], updated: datetime | None = None)[source]
Bases: Generic[T]
File writer.
-
property path: Path
Retrieve the path to which to write the models.
-
abstractmethod serialize(file: TextIO) → None[source]
Write a serialized variant of the models to the open file.
-
write() → None[source]
Write the models to the path.
-
class rechu.io.base.YAMLReader(path: Path, updated: datetime = datetime.datetime(1, 1, 1, 0, 0))[source]
Bases: Reader[T]
YAML file reader.
-
load(file: TextIO, expected: type[RT]) → RT[source]
Load the YAML file as a Python value.
-
class rechu.io.base.YAMLTag(*values)[source]
Bases: str, Enum
Explicit type tags for YAML.
-
FLOAT = 'tag:yaml.org,2002:float'
-
INT = 'tag:yaml.org,2002:int'
-
STR = 'tag:yaml.org,2002:str'
-
class rechu.io.base.YAMLWriter(path: Path, models: Collection[T], updated: datetime | None = None)[source]
Bases: Writer[T], Generic[T, RT]
YAML file writer.
-
save(data: RT, file: TextIO) → None[source]
Save the YAML file from a Python value.
rechu.io.products module
Products matching metadata file handling.
-
final class rechu.io.products.ProductsReader(path: Path, updated: datetime = datetime.datetime(1, 1, 1, 0, 0))[source]
Bases: YAMLReader[Product]
File reader for products metadata.
-
parse(file: TextIO) → Iterator[Product][source]
Parse an open file and yield specific models from it.
This method raises TypeError or subclasses if certain data in the
file does not have the correct type, and ValueError or subclasses if
the data has inconsistent or out-of-range values.
-
final class rechu.io.products.ProductsWriter(path: Path, models: Collection[Product], updated: datetime | None = None, shared_fields: Iterable[Literal['shop', 'brand', 'category', 'type']] = ('shop', 'category', 'type'))[source]
Bases: YAMLWriter[Product, _InventoryGroup]
File writer for products metadata.
-
serialize(file: TextIO) → None[source]
Write a serialized variant of the models to the open file.
rechu.io.receipt module
Receipt file handling.
-
final class rechu.io.receipt.ReceiptReader(path: Path, updated: datetime = datetime.datetime(1, 1, 1, 0, 0))[source]
Bases: YAMLReader[Receipt]
Receipt file reader.
-
parse(file: TextIO) → Iterator[Receipt][source]
Parse an open file and yield specific models from it.
This method raises TypeError or subclasses if certain data in the
file does not have the correct type, and ValueError or subclasses if
the data has inconsistent or out-of-range values.
-
final class rechu.io.receipt.ReceiptWriter(path: Path, models: Collection[Receipt], updated: datetime | None = None)[source]
Bases: YAMLWriter[Receipt, _Receipt]
Receipt file writer.
-
serialize(file: TextIO) → None[source]
Write a serialized variant of the models to the open file.
rechu.io.shops module
Shops metadata file handling.
-
final class rechu.io.shops.ShopsReader(path: Path, updated: datetime = datetime.datetime(1, 1, 1, 0, 0))[source]
Bases: YAMLReader[Shop]
File reader for shops metadata.
-
parse(file: TextIO) → Iterator[Shop][source]
Parse an open file and yield specific models from it.
This method raises TypeError or subclasses if certain data in the
file does not have the correct type, and ValueError or subclasses if
the data has inconsistent or out-of-range values.
-
final class rechu.io.shops.ShopsWriter(path: Path, models: Collection[T], updated: datetime | None = None)[source]
Bases: YAMLWriter[Shop, list[_Shop]]
File writer for shops metadata.
-
serialize(file: TextIO) → None[source]
Write a serialized variant of the models to the open file.
Module contents
Models for file reading and writing.
-
class rechu.io.ProductsReader(path: Path, updated: datetime = datetime.datetime(1, 1, 1, 0, 0))[source]
Bases: YAMLReader[Product]
File reader for products metadata.
-
parse(file: TextIO) → Iterator[Product][source]
Parse an open file and yield specific models from it.
This method raises TypeError or subclasses if certain data in the
file does not have the correct type, and ValueError or subclasses if
the data has inconsistent or out-of-range values.
-
class rechu.io.ProductsWriter(path: Path, models: Collection[Product], updated: datetime | None = None, shared_fields: Iterable[Literal['shop', 'brand', 'category', 'type']] = ('shop', 'category', 'type'))[source]
Bases: YAMLWriter[Product, _InventoryGroup]
File writer for products metadata.
-
serialize(file: TextIO) → None[source]
Write a serialized variant of the models to the open file.
-
class rechu.io.ReceiptReader(path: Path, updated: datetime = datetime.datetime(1, 1, 1, 0, 0))[source]
Bases: YAMLReader[Receipt]
Receipt file reader.
-
parse(file: TextIO) → Iterator[Receipt][source]
Parse an open file and yield specific models from it.
This method raises TypeError or subclasses if certain data in the
file does not have the correct type, and ValueError or subclasses if
the data has inconsistent or out-of-range values.
-
class rechu.io.ReceiptWriter(path: Path, models: Collection[Receipt], updated: datetime | None = None)[source]
Bases: YAMLWriter[Receipt, _Receipt]
Receipt file writer.
-
serialize(file: TextIO) → None[source]
Write a serialized variant of the models to the open file.
-
class rechu.io.ShopsReader(path: Path, updated: datetime = datetime.datetime(1, 1, 1, 0, 0))[source]
Bases: YAMLReader[Shop]
File reader for shops metadata.
-
parse(file: TextIO) → Iterator[Shop][source]
Parse an open file and yield specific models from it.
This method raises TypeError or subclasses if certain data in the
file does not have the correct type, and ValueError or subclasses if
the data has inconsistent or out-of-range values.
-
class rechu.io.ShopsWriter(path: Path, models: Collection[T], updated: datetime | None = None)[source]
Bases: YAMLWriter[Shop, list[_Shop]]
File writer for shops metadata.
-
serialize(file: TextIO) → None[source]
Write a serialized variant of the models to the open file.