本文整理汇总了Python中yaml.add_multi_constructor方法的典型用法代码示例。如果您正苦于以下问题:Python yaml.add_multi_constructor方法的具体用法?Python yaml.add_multi_constructor怎么用?Python yaml.add_multi_constructor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yaml
的用法示例。
在下文中一共展示了yaml.add_multi_constructor方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: initialize
# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import add_multi_constructor [as 别名]
def initialize():
"""
Initialize the configuration system by installing YAML handlers.
Automatically done on first call to load() specified in this file.
"""
global is_initialized
# Add the custom multi-constructor
yaml.add_multi_constructor('!obj:', multi_constructor_obj)
yaml.add_multi_constructor('!pkl:', multi_constructor_pkl)
yaml.add_multi_constructor('!import:', multi_constructor_import)
yaml.add_constructor('!import', constructor_import)
yaml.add_constructor("!float", constructor_float)
pattern = re.compile(SCIENTIFIC_NOTATION_REGEXP)
yaml.add_implicit_resolver('!float', pattern)
is_initialized = True
###############################################################################
# Callbacks used by PyYAML
示例2: get_yaml_or_json_file
# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import add_multi_constructor [as 别名]
def get_yaml_or_json_file(cls, url, working_dir):
"""
Load yaml or json from filesystem or s3
:param url: str
:param working_dir: str
:return: dict
"""
file_content = cls.get_file(url, working_dir)
try:
if url.lower().endswith(".json"):
return json.loads(file_content, encoding='utf-8')
elif url.lower().endswith(".template"):
return json.loads(file_content, encoding='utf-8')
elif url.lower().endswith(".yml") or url.lower().endswith(".yaml"):
if hasattr(yaml, 'FullLoader'):
loader = yaml.FullLoader
else:
loader = yaml.Loader
yaml.add_multi_constructor(u"", cls.handle_yaml_constructors, Loader=loader)
return yaml.load(file_content, Loader=loader)
else:
raise CfnSphereException(
"Invalid suffix, use [json|template|yml|yaml]")
except Exception as e:
raise CfnSphereException(e)
示例3: __init__
# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import add_multi_constructor [as 别名]
def __init__(self):
self.clients = {}
yaml.add_multi_constructor("!ruby/object:Puppet", default_constructor)