labapi.tree.mixins.AbstractTreeNode#

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

Bases: AbstractBaseTreeNode

Abstract base class for a non-container node within the LabArchives tree structure.

This class extends AbstractBaseTreeNode with functionalities for modifying the node’s name, copying, moving, and deleting the node.

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

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.

copy_to(destination)

Copy this node into destination.

delete()

Move this node into the special API Deleted Items directory.

is_dir()

Return whether this node is a directory.

move_to(destination)

Move this node into destination.

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 name: str#

Return the tree node name.

Returns:

The name of the node.

abstract copy_to(
destination: AbstractTreeContainer,
) Self[source]#

Copy this node into destination.

Parameters:

destination – The target container to copy the node to.

Returns:

A new instance of the copied node in the destination.

move_to(
destination: AbstractTreeContainer,
) Self[source]#

Move this node into destination.

This operation updates the node’s parent in LabArchives via an API call and updates the local tree structure.

Parameters:

destination – The target container to move the node to.

Returns:

The instance of the moved node.

delete() Self[source]#

Move this node into the special API Deleted Items directory.

If the “API Deleted Items” directory does not exist, it will be created. The node’s name will be updated to reflect its deletion time.

Returns:

The instance of the deleted node.

as_dir() AbstractTreeContainer#

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#

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).

abstract property id: str#

Return the node identifier.

Returns:

The node’s ID.

abstract is_dir() bool#

Return whether this node is a directory.

Returns:

True if the node is a directory, False otherwise.

property parent: AbstractTreeContainer#

Return this node’s parent container.

Returns:

The parent tree container.

property path: NotebookPath#

Return the cached absolute path for this node.

abstract refresh() Self#

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.

property root: AbstractTreeContainer#

Return the root node of the tree.

Returns:

The root tree container.

traverse(
path: str | NotebookPath,
) AbstractBaseTreeNode#

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 AbstractBaseTreeNode found at the specified path.

Raises:

TraversalError – If traversal cannot continue through a segment.

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 user: User#

Return the authenticated user associated with this node.

Returns:

The user object.