
This will likely also be very useful to use since it ensures we safely use/parse yaml. Change-Id: Ibc0f7dee46d2f199e2d65d9bc6444bfa72383704
41 lines
1.1 KiB
Python
41 lines
1.1 KiB
Python
# Copyright 2015 Canonical Ltd.
|
|
# This file is part of cloud-init. See LICENCE file for license information.
|
|
#
|
|
# vi: ts=4 expandtab
|
|
|
|
import yaml as _yaml
|
|
|
|
from cloudinit import util
|
|
|
|
|
|
YAMLError = _yaml.YAMLError
|
|
|
|
|
|
def load(path):
|
|
"""Load yaml string from a path and return the data represented.
|
|
|
|
Exception will be raised if types other than the following are found:
|
|
dict, int, float, string, list, unicode
|
|
"""
|
|
return loads(util.load_file(path))
|
|
|
|
|
|
def loads(blob):
|
|
"""Load yaml string and return the data represented.
|
|
|
|
Exception will be raised if types other than the following are found:
|
|
dict, int, float, string, list, unicode
|
|
"""
|
|
return _yaml.safe_load(blob)
|
|
|
|
|
|
def dumps(obj):
|
|
"""Dumps an object back into a yaml string."""
|
|
formatted = _yaml.safe_dump(obj,
|
|
line_break="\n",
|
|
indent=4,
|
|
explicit_start=True,
|
|
explicit_end=True,
|
|
default_flow_style=False)
|
|
return formatted
|