Coverage for src/configuraptor/loaders/loaders_shared.py: 100%

1"""

2 File loaders that work regardless of Python version.

3"""

4

5 import json as json_lib

6 from typing import BinaryIO

7

8 import tomlkit

9 import yaml as yaml_lib

10

11 from ._types import T_config, as_tconfig

12

13

14 def json(f: BinaryIO) -> T_config:

15 """

16 Load a JSON file.

17 """

18 data = json_lib.load(f)

19 return as_tconfig(data)

20

21

22 def 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)

28

29

30 def toml(f: BinaryIO) -> T_config:

31 """

32 Load a toml file.

33 """

34 data = tomlkit.load(f)

35 return as_tconfig(data)