Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
validate : bool
When `True` (default) validate the resulting tree.
"""
type_index = self.type_index
if not type_index.has_hook(hookname):
return
def walker(node):
hook = type_index.get_hook_for_type(hookname, type(node),
self.version_string)
if hook is not None:
return hook(node, self)
return node
tree = treeutil.walk_and_modify(self.tree, walker)
if validate:
self._validate(tree)
self._tree = tree
return self._tree
def custom_tree_to_tagged_tree(tree, ctx):
"""
Convert a tree, possibly containing custom data types that aren't
directly representable in YAML, to a tree of basic data types,
annotated with tags.
"""
def walker(node):
tag = ctx.type_index.from_custom_type(type(node), ctx.version_string)
if tag is not None:
return tag.to_tree_tagged(node, ctx)
return node
return treeutil.walk_and_modify(tree, walker)