onaplogging: Docstrings, refactor, type hinting
[logging-analytics.git] / pylog / onaplogging / utils / tools.py
1 # Copyright (c) 2020 Deutsche Telekom.
2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at:
5 #       http://www.apache.org/licenses/LICENSE-2.0
6 #
7 # Unless required by applicable law or agreed to in writing, software
8 # distributed under the License is distributed on an "AS IS" BASIS,
9 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
11 import yaml
12
13 from deprecated import deprecated
14
15
16 def yaml_to_dict(filepath):
17     # type: (str) -> dict
18     """YAML to Python dict converter.
19
20     Args:
21         filepath    : The filepath to a YAML file.
22     Returns:
23         dict        : Python dictionary object.
24     """
25     with open(filepath, 'rt') as f:
26         return yaml.load(f.read())
27
28
29 @deprecated(reason="Will be removed. Call yaml_to_dict(filepath) instead.")
30 def _yaml2Dict(filename):
31     """YAML to dict. See yaml_to_dict(filepath)."""
32     return yaml_to_dict(filename)