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 {}'.format(node.id)
, node.start_mark
)
mapping = collections.OrderedDict()
for key_node, value_node in node.value:
key = self.construct_object(key_node, deep=deep)
try:
hash(key)
except TypeError as ex:
raise yaml.constructor.ConstructorError(
'while constructing a mapping'
, node.start_mark
, 'found unacceptable key `{}`'.format(ex)
, key_node.start_mark
)
value = self.construct_object(value_node, deep=deep)
mapping[key] = value
return mapping
ordered_dict_yaml_loader.py 文件源码
python
阅读 26
收藏 0
点赞 0
评论 0
评论列表
文章目录