Coverage for src/configuraptor/loaders/loaders_shared.py: 100%
14 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-15 14:30 +0200
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-15 14:30 +0200
1"""
2File loaders that work regardless of Python version.
3"""
5import json as json_lib
6from typing import BinaryIO
8import yaml as yaml_lib
9import tomlkit
11from ._types import T_config, as_tconfig
14def json(f: BinaryIO) -> T_config:
15 """
16 Load a JSON file.
17 """
18 data = json_lib.load(f)
19 return as_tconfig(data)
22def yaml(f: BinaryIO) -> T_config:
23 """
24 Load a YAML file.
25 """
26 data = yaml_lib.load(f, yaml_lib.SafeLoader)
27 return as_tconfig(data)
30def toml(f: BinaryIO) -> T_config:
31 """
32 Load a toml file.
33 """
34 data = tomlkit.load(f)
35 return as_tconfig(data)