load_user_files.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:ansible-container 作者: Freifunk-Hennef 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号