本文整理匯總了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)