本文整理匯總了Python中yaml.MappingNode方法的典型用法代碼示例。如果您正苦於以下問題:Python yaml.MappingNode方法的具體用法?Python yaml.MappingNode怎麽用?Python yaml.MappingNode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類yaml
的用法示例。
在下文中一共展示了yaml.MappingNode方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: construct_mapping
# 需要導入模塊: import yaml [as 別名]
# 或者: from yaml import MappingNode [as 別名]
def construct_mapping(self, node, deep=False):
if isinstance(node, yaml.MappingNode):
self.flatten_mapping(node)
else:
msg = 'expected a mapping node, but found %s' % node.id
raise yaml.constructor.ConstructError(None,
None,
msg,
node.start_mark)
mapping = OrderedDict()
for key_node, value_node in node.value:
key = self.construct_object(key_node, deep=deep)
try:
hash(key)
except TypeError as err:
raise yaml.constructor.ConstructError(
'while constructing a mapping', node.start_mark,
'found unacceptable key (%s)' % err, key_node.start_mark)
value = self.construct_object(value_node, deep=deep)
mapping[key] = value
return mapping
示例2: construct_mapping
# 需要導入模塊: import yaml [as 別名]
# 或者: from yaml import MappingNode [as 別名]
def construct_mapping(cls, loader, node, deep=False):
"""Based on yaml.loader.BaseConstructor.construct_mapping."""
if not isinstance(node, yaml.MappingNode):
raise yaml.loader.ConstructorError(
None, None, "expected a mapping node, but found %s" % node.id,
node.start_mark)
mapping = OrderedYamlDict()
for key_node, value_node in node.value:
key = loader.construct_object(key_node, deep=deep)
try:
hash(key)
except TypeError as exc:
raise yaml.loader.ConstructorError(
"while constructing a mapping", node.start_mark,
"found unacceptable key (%s)" % exc, key_node.start_mark)
value = loader.construct_object(value_node, deep=deep)
mapping[key] = value
return mapping
示例3: construct_mapping
# 需要導入模塊: import yaml [as 別名]
# 或者: from yaml import MappingNode [as 別名]
def construct_mapping(cls, loader, node, deep=False):
"""Based on yaml.loader.BaseConstructor.construct_mapping."""
if not isinstance(node, yaml.MappingNode):
raise yaml.loader.ConstructorError(
None, None, "expected a mapping node, but found %s" % node.id,
node.start_mark)
mapping = OrderedYamlDict()
for key_node, value_node in node.value:
key = loader.construct_object(key_node, deep=deep)
try:
hash(key)
except TypeError as exc:
raise yaml.loader.ConstructorError(
"while constructing a mapping", node.start_mark,
"found unacceptable key (%s)" % exc, key_node.start_mark)
value = loader.construct_object(value_node, deep=deep)
mapping[key] = value
return mapping
示例4: construct_mapping
# 需要導入模塊: import yaml [as 別名]
# 或者: from yaml import MappingNode [as 別名]
def construct_mapping(self, node, deep=False):
if isinstance(node, yaml.MappingNode):
self.flatten_mapping(node)
else:
raise yaml.constructor.ConstructorError(None, None,
'expected a mapping node, but found %s' % node.id, node.start_mark)
mapping = OrderedDict()
for key_node, value_node in node.value:
key = self.construct_object(key_node, deep=deep)
try:
hash(key)
except TypeError as exc:
raise yaml.constructor.ConstructorError('while constructing a mapping',
node.start_mark, 'found unacceptable key (%s)' % exc, key_node.start_mark)
value = self.construct_object(value_node, deep=deep)
mapping[key] = value
return mapping
示例5: construct_mapping
# 需要導入模塊: import yaml [as 別名]
# 或者: from yaml import MappingNode [as 別名]
def construct_mapping(self, node, deep=False):
if not isinstance(node, yaml.MappingNode):
raise ConstructorError(None, None,
"expected a mapping node, but found %s" % node.id,
node.start_mark)
key_set = set()
for key_node, value_node in node.value:
if not isinstance(key_node, yaml.ScalarNode):
continue
k = key_node.value
if k in key_set:
raise ConstructorError(
"while constructing a mapping", node.start_mark,
"found duplicate key", key_node.start_mark)
key_set.add(k)
return super(DuplicateKeyCheckLoader, self).construct_mapping(node, deep)
示例6: multi_constructor
# 需要導入模塊: import yaml [as 別名]
# 或者: from yaml import MappingNode [as 別名]
def multi_constructor(loader, tag_suffix, node):
"""
Deal with !Ref style function format
"""
if tag_suffix not in UNCONVERTED_SUFFIXES:
tag_suffix = '{}{}'.format(FN_PREFIX, tag_suffix)
constructor = None
if tag_suffix == 'Fn::GetAtt':
constructor = construct_getatt
elif isinstance(node, ScalarNode):
constructor = loader.construct_scalar
elif isinstance(node, SequenceNode):
constructor = loader.construct_sequence
elif isinstance(node, MappingNode):
constructor = loader.construct_mapping
else:
raise 'Bad tag: !{}'.format(tag_suffix)
return dict_node({tag_suffix: constructor(node)}, node.start_mark, node.end_mark)
示例7: multi_constructor
# 需要導入模塊: import yaml [as 別名]
# 或者: from yaml import MappingNode [as 別名]
def multi_constructor(loader, tag_suffix, node):
"""
Deal with !Ref style function format
"""
if tag_suffix not in UNCONVERTED_SUFFIXES:
tag_suffix = "{}{}".format(FN_PREFIX, tag_suffix)
constructor = None
if tag_suffix == "Fn::GetAtt":
constructor = construct_getatt
elif isinstance(node, yaml.ScalarNode):
constructor = loader.construct_scalar
elif isinstance(node, yaml.SequenceNode):
constructor = loader.construct_sequence
elif isinstance(node, yaml.MappingNode):
constructor = loader.construct_mapping
else:
raise Exception("Bad tag: !{}".format(tag_suffix))
return ODict((
(tag_suffix, constructor(node)),
))
示例8: represent_odict
# 需要導入模塊: import yaml [as 別名]
# 或者: from yaml import MappingNode [as 別名]
def represent_odict(dump, tag, mapping, flow_style=None):
value = []
node = yaml.MappingNode(tag, value, flow_style=flow_style)
if dump.alias_key is not None:
dump.represented_objects[dump.alias_key] = node
best_style = True
if hasattr(mapping, 'items'):
mapping = mapping.items()
for item_key, item_value in mapping:
node_key = dump.represent_data(item_key)
node_value = dump.represent_data(item_value)
if not (isinstance(node_key, yaml.ScalarNode) and not node_key.style):
best_style = False
if not (isinstance(node_value, yaml.ScalarNode)
and not node_value.style):
best_style = False
value.append((node_key, node_value))
if flow_style is None:
if dump.default_flow_style is not None:
node.flow_style = dump.default_flow_style
else:
node.flow_style = best_style
return node
示例9: represent_odict
# 需要導入模塊: import yaml [as 別名]
# 或者: from yaml import MappingNode [as 別名]
def represent_odict(self, dump, tag, mapping, flow_style=None):
value = []
node = yaml.MappingNode(tag, value, flow_style=flow_style)
if dump.alias_key is not None:
dump.represented_objects[dump.alias_key] = node
best_style = True
if hasattr(mapping, 'items'):
mapping = mapping.items()
for item_key, item_value in mapping:
node_key = dump.represent_data(item_key)
node_value = dump.represent_data(item_value)
if not (isinstance(node_key, yaml.ScalarNode)
and not node_key.style):
best_style = False
if not (isinstance(node_value, yaml.ScalarNode)
and not node_value.style):
best_style = False
value.append((node_key, node_value))
if flow_style is None:
if dump.default_flow_style is not None:
node.flow_style = dump.default_flow_style
else:
node.flow_style = best_style
return node
示例10: construct_mapping
# 需要導入模塊: import yaml [as 別名]
# 或者: from yaml import MappingNode [as 別名]
def construct_mapping(self, node, deep=False):
if isinstance(node, yaml.MappingNode):
self.flatten_mapping(node)
else:
raise yaml.constructor.ConstructorError(None, None,
'expected a mapping node, but found %s' % node.id, node.start_mark)
mapping = OrderedDict()
for key_node, value_node in node.value:
key = self.construct_object(key_node, deep=deep)
try:
hash(key)
except TypeError, exc:
raise yaml.constructor.ConstructorError('while constructing a mapping',
node.start_mark, 'found unacceptable key (%s)' % exc, key_node.start_mark)
value = self.construct_object(value_node, deep=deep)
mapping[key] = value
示例11: construct_mapping
# 需要導入模塊: import yaml [as 別名]
# 或者: from yaml import MappingNode [as 別名]
def construct_mapping(self, node, deep=False):
if isinstance(node, yaml.MappingNode):
self.flatten_mapping(node)
else:
raise yaml.constructor.ConstructorError(None, None,
'expected a mapping node, but found %s' %
node.id, node.start_mark)
mapping = OrderedDict()
for key_node, value_node in node.value:
key = self.construct_object(key_node, deep=deep)
try:
hash(key)
except TypeError as exc:
raise yaml.constructor.ConstructorError('while constructing a mapping',
node.start_mark,
'found unacceptable key (%s)' % exc,
key_node.start_mark)
value = self.construct_object(value_node, deep=deep)
mapping[key] = value
return mapping
示例12: represent_odict
# 需要導入模塊: import yaml [as 別名]
# 或者: from yaml import MappingNode [as 別名]
def represent_odict(dump, tag, mapping, flow_style=None):
"""Like BaseRepresenter.represent_mapping, but does not issue the sort().
"""
value = []
node = yaml.MappingNode(tag, value, flow_style=flow_style)
if dump.alias_key is not None:
dump.represented_objects[dump.alias_key] = node
best_style = True
if hasattr(mapping, 'items'):
mapping = mapping.items()
for item_key, item_value in mapping:
node_key = dump.represent_data(item_key)
node_value = dump.represent_data(item_value)
if not (isinstance(node_key, yaml.ScalarNode) and not node_key.style):
best_style = False
if not (isinstance(node_value, yaml.ScalarNode) and not node_value.style):
best_style = False
value.append((node_key, node_value))
if flow_style is None:
if dump.default_flow_style is not None:
node.flow_style = dump.default_flow_style
else:
node.flow_style = best_style
return node
示例13: construct_mapping
# 需要導入模塊: import yaml [as 別名]
# 或者: from yaml import MappingNode [as 別名]
def construct_mapping(self, node, deep=False):
if isinstance(node, yaml.MappingNode):
self.flatten_mapping(node)
else: # pragma: no cover
raise yaml.constructor.ConstructorError(None, None,
'expected a mapping node, but found %s' % node.id, node.start_mark)
mapping = OrderedDict()
for key_node, value_node in node.value:
key = self.construct_object(key_node, deep=deep)
try:
hash(key)
except TypeError as exc: # pragma: no cover
raise yaml.constructor.ConstructorError('while constructing a mapping',
node.start_mark, 'found unacceptable key (%s)'
% exc, key_node.start_mark)
value = self.construct_object(value_node, deep=deep)
mapping[key] = value
return mapping
示例14: include
# 需要導入模塊: import yaml [as 別名]
# 或者: from yaml import MappingNode [as 別名]
def include(self, node):
if isinstance(node, yaml.ScalarNode):
return self.extractFile(self.construct_scalar(node))
elif isinstance(node, yaml.SequenceNode):
result = []
for i in self.construct_sequence(node):
i = general_function.get_absolute_path(i, self._root)
for j in general_files_func.get_ofs(i):
result += self.extractFile(j)
return result
elif isinstance(node, yaml.MappingNode):
result = {}
for k,v in self.construct_mapping(node).iteritems():
result[k] = self.extractFile(v)
return result
else:
print ('Error:: unrecognised node type in !include statement')
raise yaml.constructor.ConstructorError
示例15: represent_odict
# 需要導入模塊: import yaml [as 別名]
# 或者: from yaml import MappingNode [as 別名]
def represent_odict(dump, tag, mapping, flow_style=None):
"""
Like BaseRepresenter.represent_mapping, but does not issue the sort().
"""
value = []
node = yaml.MappingNode(tag, value, flow_style=flow_style)
if dump.alias_key is not None:
dump.represented_objects[dump.alias_key] = node
best_style = True
if hasattr(mapping, 'items'):
mapping = mapping.items()
for item_key, item_value in mapping:
node_key = dump.represent_data(item_key)
node_value = dump.represent_data(item_value)
if not (isinstance(node_key, yaml.ScalarNode) and not node_key.style):
best_style = False
if not (isinstance(node_value, yaml.ScalarNode) and not node_value.style):
best_style = False
value.append((node_key, node_value))
if flow_style is None:
if dump.default_flow_style is not None:
node.flow_style = dump.default_flow_style
else:
node.flow_style = best_style
return node