Skip to content

Commit

Permalink
fix: Fix loading of yaml files with = as list items
Browse files Browse the repository at this point in the history
  • Loading branch information
codablock committed Jan 5, 2022
1 parent de92008 commit ead8e2d
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions kluctl/utils/yaml_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,21 @@
print("Failed to load fast LibYAML bindings. You should install them to speed up kluctl.", file=sys.stderr)
from yaml import SafeLoader as SafeLoader, SafeDumper as SafeDumper


def construct_value(load, node):
if not isinstance(node, yaml.ScalarNode):
raise yaml.constructor.ConstructorError(
"while constructing a value",
node.start_mark,
"expected a scalar, but found %s" % node.id, node.start_mark
)
yield str(node.value)


# See https://github.com/yaml/pyyaml/issues/89
SafeLoader.add_constructor(u'tag:yaml.org,2002:value', construct_value)


def multiline_str_representer(dumper, data):
if len(data.splitlines()) > 1: # check for multiline string
return dumper.represent_scalar('tag:yaml.org,2002:str', data, style='|')
Expand Down

0 comments on commit ead8e2d

Please sign in to comment.