AsdfSearchResult

class asdf.search.AsdfSearchResult(identifiers, node, filters=None, 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 NOT_SET, 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 NOT_SET, retain existing value.

max_colsint, None or NOT_SET, 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 NOT_SET, retain existing value.

show_valuesbool or NOT_SET, optional

Set to False to disable display of primitive values in the rendered tree. Set to NOT_SET 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)[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.

search(key=NotSet, type_=NotSet, value=NotSet, filter_=None)[source]

Further narrow the search.

Parameters:
keyNOT_SET, str, or any other object

Search query that selects nodes by dict key or list index. If NOT_SET, 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.

type_NOT_SET, str, or builtins.type

Search query that selects nodes by type. If NOT_SET, 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.

valueNOT_SET, str, or any other object

Search query that selects nodes by value. If NOT_SET, 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.

filter_callable

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