parser.py 文件源码

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

项目:bilean 作者: openstack 项目源码 文件源码
def simple_parse(in_str):
    try:
        out_dict = jsonutils.loads(in_str)
    except ValueError:
        try:
            out_dict = yaml.load(in_str, Loader=YamlLoader)
        except yaml.YAMLError as yea:
            yea = six.text_type(yea)
            msg = _('Error parsing input: %s') % yea
            raise ValueError(msg)
        else:
            if out_dict is None:
                out_dict = {}

    if not isinstance(out_dict, dict):
        msg = _('The input is not a JSON object or YAML mapping.')
        raise ValueError(msg)

    return out_dict
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号