aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEugene Triguba <eugenetriguba@gmail.com>2020-07-29 21:32:57 -0500
committerEugene Triguba <eugenetriguba@gmail.com>2020-07-29 21:32:57 -0500
commit47a58715546d780a5df8d362ab5eeedd3813ecdb (patch)
tree035e46cfb5707fe77bbe71db51c93fbd9ceb8785
parentRemove duplication from `can_be_parsed_as_float` (diff)
downloadconfig-file-47a58715546d780a5df8d362ab5eeedd3813ecdb.zip
Use ruamel.yaml for yaml parser
-rw-r--r--config_file/parsers/yaml_parser.py13
1 files changed, 6 insertions, 7 deletions
diff --git a/config_file/parsers/yaml_parser.py b/config_file/parsers/yaml_parser.py
index 77b59fe..1937e17 100644
--- a/config_file/parsers/yaml_parser.py
+++ b/config_file/parsers/yaml_parser.py
@@ -1,12 +1,7 @@
try:
- import yaml
+ from ruamel.yaml import YAML, YAMLError, round_trip_dump, round_trip_load
YAML_AVAILABLE = True
-
- # Conform yaml to json and
- # toml package syntax
- yaml.loads = yaml.load
- yaml.dumps = yaml.dump
except ImportError:
YAML_AVAILABLE = False
@@ -23,7 +18,11 @@ class YamlParser(BaseParser):
"file was attempted to be used. Install the `toml` "
"extra first with `pip install config-file[toml]`."
)
+
+ yaml = YAML(typ='safe')
+ yaml.loads = round_trip_load
+ yaml.dumps = round_trip_dump
super().__init__(
- file_contents=file_contents, module=yaml, decode_error=yaml.YAMLError
+ file_contents=file_contents, module=yaml, decode_error=YAMLError
)