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

14 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-06-20 10:44 +0200

1""" 

2File loaders that work regardless of Python version. 

3""" 

4 

5import json as json_lib 

6from typing import BinaryIO 

7 

8import tomli 

9import yaml as yaml_lib 

10 

11from ._types import T_config, as_tconfig 

12 

13 

14def 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 

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) 

28 

29 

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

31 """ 

32 Load a toml file. 

33 """ 

34 data = tomli.load(f) 

35 return as_tconfig(data)