nbox.nbxlib.astea
Functions
generic function to calculate SHA256 hash of a string
generic function to return the code section for a node
Classes
returns all the valid index types
- fname -
the file name to parse. If this is not provided, then all other values must be provided.
- code -
the code text can be provided instead of the.
- name -
The name of the node. Defaults to "".
- type -
The type of the node. Defaults to None.
- node -
The AST node. Defaults to None.
- code_lines -
The code lines. Defaults to None.
- order_index -
The order index of the node. Defaults to -1.
This is an AST node, that can be called upon itself to traverse in a natural human way. Only fname
is an important argument, others will be populated automatically.
Example:
# Creating a simple tea:
from nbox.nbxlib import astea as A
tea = A.Astea(fname = A.__file__)
Get the docstring of the current node, is valid only for functions and classes. This will automatically perform relevant dedentation and return the docstring as a single string.
Returns a list of all the AST nodes (same Astea
) in the current node. This is a recursive function and user/bot is expected to go over this to traverse.
- x -
If provided, will find the name of the item to search for
- types -
The type of items to search for. Defaults to None.
Find all the instances of x in the current node, and return a list of IndexItems.
- if there is a '.' (dot) in
x
,find
will try to perform a recursive search, you can escape the dot with a backslash - This currently does not work correctly when the same name is used in different types
- if both
x
andtypes
is not provided, then this behaves just like.index
Example:
# Create a tea:
from nbox.nbxlib import astea as A
tea = A.Astea(fname = A.__file__)
# Find things inside the tea:
cls_obj = tea.find("Astea")[0] # search by name
fn_obj = cls_obj.find('find') # search inside any Astea
fn_obj = tea.find("Astea.find")[0] # search inside things by using . (dot)
Returns:
List['Astea']
: A list of IndexItems that match the search