當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。