pyhit.pyhit
The following is the documentation for the public API of the pyhit python package within MOOSE.
pyhit.Node
pyhit.Node(parent=None, hitnode=None, offset=0)
An moosetree.Node object for building a HIT tree.
Add a new node to the input file tree that is a child of parent. The supplied parent must be pyhit.Node
object. The hitnode is name of the node, as a string.
The hitnode input can also be an object from the hit C bindings. However, this second form is not intended for general use; it is used when creating a tree from a file when loading from a file.
append(name, **kwargs)
Append a child input block, with the given name, to the end of current block.
The keyword arguments supplied are added as parameters to the added block.
attributes
Return the a 'attributes' (key, value pairs supplied in construction) for this node.
children
Return a list of children.
The list is a copy but the Node objects in the list are not.
comment(param=None)
Return a copy of the comment for the block or parameter given by param.
When this method is called without arguments it returns the comments for the block itself. When called with the param name, the comment for that parameter is returned.
This method returns a copy of the comment text. To modify the comment, the "setComment" method must be used.
count
Return the number of all descendants
descendants
Return a list of all descendants, children's children etc.
filename(name=None, default=None)
Return the file name for node itself or for the supplied name. When the name is not included the file name for the beginning of the block is returned; and when it is included the file name is returned. When name is used and the parameter is not located, the default is returned.
format(**kwargs)
Return a string of the node that is rendered with C hit library with formatting.
An optional keyword argument canonical_section_markers can be supplied with True
or False
to enable/disable the use of "./" and "../" section markings. By default these markings this are removed.
fullpath
Return the node full path as a string.
get(name, default=None)
Return a parameter, if it does not exist return the default.
insert(index, name, **kwargs)
Insert a child input block, with the given name, to the current block before the index.
The keyword arguments supplied are added as parameters to the inserted block.
is_root
Return True if the Node is a root, i.e., is the parent node object set to None.
items()
Return the dict() iterator to the attributes, i.e., k, v in node.items()
.
line(name=None, default=None)
Return the line number for node itself or for the supplied name.
When the name is not included the line number for the beginning of the block is returned; and when it is included the line number is returned.
When name is used and the parameter is not located, the default is returned.
name
Return the name of the Node.
next
Return the next sibling, if it exists.
params()
Return key, value for the parameters of this node.
for k, v in node.params():
...
parent
Return the parent Node object, which is None for a root node.
path
Return the nodes that lead to the root node of the tree from this node.
previous
Return the previous sibling, if it exists.
remove()
Remove this node form the tree.
removeParam(name)
Remove the supplied parameter with name from the node.
render(**kwargs)
Return a string of the node this rendered with the C hit library without formatting.
root
Return the root node of the tree.
setComment(*args)
Add/Set comment for the block or parameter.
There are two modes of operation. The first (setComment(text)
) sets the comment of the block itself to the supplied text. The second (setComment(param, text)
sets the comment of the supplied param with the value of text.
siblings
Return a list of sibling nodes.
load(filename, root=None)
Read and parse a HIT file given in filename.
The function return a pyhit.Node
object which is the root node of the loaded tree. The specific node object that should be populated can be supplied with the root input. If it is provided this same node will be returned.
write(filename, root)
Write the supplied tree in root to a text file filename.
parse(content, root=None, filename='')
Parse a hit tree from a content string and return a pyhit.Node
object.
The returned object is the root of the loaded tree. The root input can provide a node object for the tree to populate; if it is given this same node is returned. The filename, if provided, will be used for error reporting when manipulating the tree.