walk_and_modify¶
- asdf.treeutil.walk_and_modify(top, callback, postorder=True, _context=None)[source]¶
Modify a tree by walking it with a callback function. It also has the effect of doing a deep copy.
- Parameters:
- topobject
The root of the tree. May be a dict, list or other Python object.
- callbackcallable
A function to call at each node in the tree. It takes either one or two arguments:
an instance from the tree
a json id (optional)
It may return a different instance in order to modify the tree. If the singleton instance
_RemoveNodeis returned, the node will be removed from the tree.The json id is the context under which any relative URLs should be resolved. It may be
Noneif no ids are in the fileThe tree is traversed depth-first, with order specified by the
postorderargument.- postorderbool
Determines the order in which the callable is invoked on nodes of the tree. If
True, the callable will be invoked on children before their parents. IfFalse, the callable is invoked on the parents first. Defaults toTrue.
- Returns:
- treeobject
The modified tree.