From 47a58715546d780a5df8d362ab5eeedd3813ecdb Mon Sep 17 00:00:00 2001 From: Eugene Triguba Date: Wed, 29 Jul 2020 21:32:57 -0500 Subject: Use ruamel.yaml for yaml parser --- config_file/parsers/yaml_parser.py | 13 ++++++------- 1 file 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 ) -- cgit v1.2.3