labapi.tree.mixins.AbstractBaseTreeNode#

class labapi.tree.mixins.AbstractBaseTreeNode(
tree_id: str,
name: str,
root: AbstractTreeContainer,
parent: AbstractTreeContainer,
user: User,
)[source]#

Bases: ABC, HasNameMixin

Abstract base class for any node within the LabArchives tree structure.

This class provides fundamental properties and methods common to all tree nodes, such as ID, name, references to parent and root, and the associated user.

Parameters:
  • tree_id – The unique identifier for this node within the LabArchives tree.

  • name – The display name of the node.

  • root – The root node of the tree (e.g., the Notebook).

  • parent – The parent node of this node in the tree.

  • user – The authenticated user associated with this node.

__init__(
tree_id: str,
name: str,
root: AbstractTreeContainer,
parent: AbstractTreeContainer,
user: User,
)[source]#

Initialize a tree node with IDs, hierarchy pointers, and user state.

Methods

__init__(tree_id, name, root, parent, user)

Initialize a tree node with IDs, hierarchy pointers, and user state.

as_dir()

Return this node cast to AbstractTreeContainer.

as_page()

Return this node cast to NotebookPage.

is_dir()

Return whether this node is a directory.

refresh()

Refresh this node's cached data from the LabArchives API.

traverse(path)

Traverse the notebook tree and return the node at path.

Attributes

id

Return the node identifier.

name

Return the tree node name.

parent

Return this node's parent container.

path

Return the cached absolute path for this node.

root

Return the root node of the tree.

tree_id

Return the node identifier within the LabArchives tree.

user

Return the authenticated user associated with this node.

property root: AbstractTreeContainer#

Return the root node of the tree.

Returns:

The root tree container.

property parent: AbstractTreeContainer#

Return this node’s parent container.

Returns:

The parent tree container.

property user: User#

Return the authenticated user associated with this node.

Returns:

The user object.

abstract property id: str#

Return the node identifier.

Returns:

The node’s ID.

property tree_id: str#

Return the node identifier within the LabArchives tree.

This is often the same as id but can be used to distinguish if needed.

Returns:

The tree ID of the node.

property path: NotebookPath#

Return the cached absolute path for this node.

abstract is_dir() bool[source]#

Return whether this node is a directory.

Returns:

True if the node is a directory, False otherwise.

abstract refresh() Self[source]#

Refresh this node’s cached data from the LabArchives API.

This method updates the node’s properties (such as name, ID, and children) by fetching the latest data from the server. This is useful when the node’s state may have changed externally.

traverse(
path: str | NotebookPath,
) AbstractBaseTreeNode[source]#

Traverse the notebook tree and return the node at path.

String path segments should be separated by ‘/’. Each segment is treated as a name to look up in the current container. Paths starting with ‘/’ are absolute (relative to the notebook root), while paths without a leading ‘/’ are relative to the current container.

Special path segments: - ‘..’ navigates to the parent container

Note

  • When multiple children have the same name, this method returns the first match.

Warning

Nodes with names that are literally ‘..’ cannot be accessed via this method, as ‘..’ is reserved for parent navigation.

Parameters:

path – The slash-separated path to the desired node (e.g., “My Folder/My Page” or “/Folder/Subfolder/Page”).

Returns:

The AbstractTreeContainer or AbstractTreeNode found at the specified path.

Raises:

TraversalError – If traversal cannot continue through a segment.

as_dir() AbstractTreeContainer[source]#

Return this node cast to AbstractTreeContainer.

This method provides a convenient way to perform directory-specific operations on a node after checking its type, with static type checking support.

Returns:

The node cast to an AbstractTreeContainer.

Raises:

TypeError – If the node is not a directory (i.e., is_dir() returns False).

as_page() NotebookPage[source]#

Return this node cast to NotebookPage.

This method provides a convenient way to perform page-specific operations on a node after checking its type, with static type checking support.

Returns:

The node cast to a NotebookPage.

Raises:

TypeError – If the node is not a page (i.e., is_dir() returns True).

property name: str#

Return the tree node name.

Returns:

The name of the node.