当前位置: 首页>>代码示例>>Python>>正文


Python yaml.resolver方法代码示例

本文整理汇总了Python中yaml.resolver方法的典型用法代码示例。如果您正苦于以下问题:Python yaml.resolver方法的具体用法?Python yaml.resolver怎么用?Python yaml.resolver使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在yaml的用法示例。


在下文中一共展示了yaml.resolver方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: parse_template

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import resolver [as 别名]
def parse_template(template_str):
    """
    Parse the SAM template.

    :param template_str: A packaged YAML or json CloudFormation template
    :type template_str: str
    :return: Dictionary with keys defined in the template
    :rtype: dict
    """
    try:
        # PyYAML doesn't support json as well as it should, so if the input
        # is actually just json it is better to parse it with the standard
        # json parser.
        return json.loads(template_str, object_pairs_hook=OrderedDict)
    except ValueError:
        yaml.SafeLoader.add_constructor(yaml.resolver.BaseResolver.DEFAULT_MAPPING_TAG, _dict_constructor)
        yaml.SafeLoader.add_multi_constructor('!', intrinsics_multi_constructor)
        return yaml.safe_load(template_str) 
开发者ID:awslabs,项目名称:aws-serverlessrepo-python,代码行数:20,代码来源:parser.py

示例2: yaml_load

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import resolver [as 别名]
def yaml_load(file_path: str):
    import yaml
    from yaml.resolver import BaseResolver

    def ordered_load(stream, loader_cls):
        class OrderedLoader(loader_cls):
            pass

        def construct_mapping(loader, node):
            loader.flatten_mapping(node)
            return odict(loader.construct_pairs(node))

        OrderedLoader.add_constructor(BaseResolver.DEFAULT_MAPPING_TAG, construct_mapping)
        return yaml.load(stream, OrderedLoader)

    return ordered_load(open(file_path, 'r'), yaml.SafeLoader) 
开发者ID:kororo,项目名称:excelcy,代码行数:18,代码来源:utils.py

示例3: yaml_load

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import resolver [as 别名]
def yaml_load(stream, Loader=yaml.Loader, object_pairs_hook=UnsortableOrderedDict):
    class MyLoader(Loader):
        pass

    # use UnsortableOrderedDict
    MyLoader.add_constructor(yaml.resolver.BaseResolver.DEFAULT_MAPPING_TAG,
                             lambda loader, node: object_pairs_hook(loader.construct_pairs(node)))
    # treat str as unicode

    def construct_yaml_str(self, node):
        return self.construct_scalar(node)

    MyLoader.add_constructor(u'tag:yaml.org,2002:str', construct_yaml_str)
    return yaml.load(stream, MyLoader) 
开发者ID:hvqzao,项目名称:report-ng,代码行数:16,代码来源:util.py

示例4: yaml_parse

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import resolver [as 别名]
def yaml_parse(yamlstr):
    """Parse a yaml string"""
    try:
        # PyYAML doesn't support json as well as it should, so if the input
        # is actually just json it is better to parse it with the standard
        # json parser.
        return json.loads(yamlstr, object_pairs_hook=OrderedDict)
    except ValueError:
        yaml.SafeLoader.add_constructor(yaml.resolver.BaseResolver.DEFAULT_MAPPING_TAG, _dict_constructor)
        yaml.SafeLoader.add_multi_constructor(
            "!", intrinsics_multi_constructor)
        return yaml.safe_load(yamlstr) 
开发者ID:gkrizek,项目名称:bash-lambda-layer,代码行数:14,代码来源:yamlhelper.py


注:本文中的yaml.resolver方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。