def parse_yaml(self, data, path_hint=None):
''' convert a yaml string to a data structure. Also supports JSON, ssssssh!!!'''
stripped_data = data.lstrip()
loaded = None
if stripped_data.startswith("{") or stripped_data.startswith("["):
# since the line starts with { or [ we can infer this is a JSON document.
try:
loaded = json.loads(data)
except ValueError as ve:
if path_hint:
self.module.fail_json(msg=path_hint + ": " + str(ve))
else:
self.module.fail_json(msg=str(ve))
else:
# else this is pretty sure to be a YAML document
loaded = yaml.load(data, Loader=Loader)
return loaded
load_user_files.py 文件源码
python
阅读 24
收藏 0
点赞 0
评论 0
评论列表
文章目录