def construct_mapping(self, node, deep=None):
if isinstance(node, yaml.MappingNode):
self.flatten_mapping(node)
else:
if hasattr(node, 'id') and hasattr(node, 'start_mark'):
error = 'expected a mapping node, but found {}'.format(node.id)
raise yaml.constructorConstructorError(None, None, error, node.start_mark)
else:
error = 'Invalid type for node variable: {} - {}'.format(type(node), node)
raise TypeError(error)
mapping = self.container()
for key_node, value_node in node.value:
key = self.construct_object(key_node, deep=deep)
try:
hash(key)
except TypeError as e:
raise yaml.constructorConstructorError(
'while constructing a mapping',
node.start_mark,
'found unacceptable key ({})'.format(e),
key_node.start_mark
)
value = self.construct_object(value_node, deep=deep)
mapping[key] = value
return mapping
评论列表
文章目录