def construct_mapping(self, node, deep=False):
if not isinstance(node, nodes.MappingNode):
raise ConstructorError(
None, None,
'expected a mapping node, but found %s' % node.id,
node.start_mark
)
mapping = {}
for key_node, value_node in node.value:
key = self.construct_object(key_node, deep=deep)
if not isinstance(key, collections.Hashable):
self.echoerr(
'While constructing a mapping', node.start_mark,
'found unhashable key', key_node.start_mark
)
continue
elif type(key.value) != unicode:
self.echoerr(
'Error while constructing a mapping', node.start_mark,
'found key that is not a string', key_node.start_mark
)
continue
elif key in mapping:
self.echoerr(
'Error while constructing a mapping', node.start_mark,
'found duplicate key', key_node.start_mark
)
continue
value = self.construct_object(value_node, deep=deep)
mapping[key] = value
return mapping
评论列表
文章目录