AsdfSearchResult

class asdf.search.AsdfSearchResult(identifiers, node, filters=[], parent_node=None, max_rows=24, max_cols=120, show_values=True)[source]

Bases: object

Result of a call to AsdfFile.search.

Attributes Summary

node

Retrieve the leaf node of a tree with one search result.

nodes

Retrieve all leaf nodes in the search results.

path

Retrieve the path to the leaf node of a tree with one search result.

paths

Retrieve the paths to all leaf nodes in the search results.

Methods Summary

format([max_rows, max_cols, show_values])

Change formatting parameters of the rendered tree.

replace(value)

Assign a new value in place of all leaf nodes in the search results.

schema_info([key, preserve_list, ...])

Get a nested dictionary of the schema information for a given key, relative to this search result.

search([key, type, value, filter])

Further narrow the search.

Attributes Documentation

node

Retrieve the leaf node of a tree with one search result.

Returns:
object

the single node of the search result

nodes

Retrieve all leaf nodes in the search results.

Returns:
list of object

every node in the search results (breadth-first order)

path

Retrieve the path to the leaf node of a tree with one search result.

Returns:
str

the path to the searched node

paths

Retrieve the paths to all leaf nodes in the search results.

Returns:
list of str

the path to every node in the search results

Methods Documentation

format(max_rows=NotSet, max_cols=NotSet, show_values=NotSet)[source]

Change formatting parameters of the rendered tree.

Parameters:
max_rowsint, tuple, None, or NotSet, optional

Maximum number of lines to print. Nodes that cannot be displayed will be elided with a message. If int, constrain total number of displayed lines. If tuple, constrain lines per node at the depth corresponding to the tuple index. If None, display all lines. If NotSet, retain existing value.

max_colsint, None or NotSet, optional

Maximum length of line to print. Nodes that cannot be fully displayed will be truncated with a message. If int, constrain length of displayed lines. If None, line length is unconstrained. If NotSet, retain existing value.

show_valuesbool or NotSet, optional

Set to False to disable display of primitive values in the rendered tree. Set to NotSet to retain existign value.

Returns:
AsdfSearchResult

the reformatted search result

replace(value)[source]

Assign a new value in place of all leaf nodes in the search results.

Parameters:
valueobject
schema_info(key='description', preserve_list=True, refresh_extension_manager=False)[source]

Get a nested dictionary of the schema information for a given key, relative to this search result.

Parameters:
keystr

The key to look up. Default: “description”

preserve_listbool

If True, then lists are preserved. Otherwise, they are turned into dicts.

refresh_extension_managerbool

If True, refresh the extension manager before looking up the key. This is useful if you want to make sure that the schema data for a given key is up to date.

search(key=NotSet, type=NotSet, value=NotSet, filter=None)[source]

Further narrow the search.

Parameters:
keyNotSet, str, or any other object

Search query that selects nodes by dict key or list index. If NotSet, the node key is unconstrained. If str, the input is searched among keys/indexes as a regular expression pattern. If any other object, node’s key or index must equal the queried key.

typeNotSet, str, or builtins.type

Search query that selects nodes by type. If NotSet, the node type is unconstrained. If str, the input is searched among (fully qualified) node type names as a regular expression pattern. If builtins.type, the node must be an instance of the input.

valueNotSet, str, or any other object

Search query that selects nodes by value. If NotSet, the node value is unconstrained. If str, the input is searched among values as a regular expression pattern. If any other object, node’s value must equal the queried value.

filtercallable

Callable that filters nodes by arbitrary criteria. The callable accepts one or two arguments:

  • the node

  • the node’s list index or dict key (optional)

and returns True to retain the node, or False to remove it from the search results.

Returns:
AsdfSearchResult

the subsequent search result