PureSequencePath

class caqtus.session.PureSequencePath(path: PureSequencePath | str)

Bases: object

Represent a path in the sequence hierarchy.

A path is a string of names separated by a single backslash. For example, “\foo\bar” is a path with two parts, “foo” and “bar”. The root path is the single backslash “\”.

All methods of this class are pure in the sense that they do not interact with the storage system and only manipulate the path string.

property parts: tuple[str, ...]

Return the parts of the path.

The parts are the names that make up the path.

The root path has no parts and this attribute is an empty tuple for it.

Example

>>> path = PureSequencePath(r"\foo\bar")
>>> path.parts
('foo', 'bar')
property parent: PureSequencePath | None

Return the parent of this path.

Returns:

The parent of this path, or None if this path is the root path.

Example

>>> path = PureSequencePath(r"\foo\bar")
>>> path.parent
PureSequencePath("\\foo")
get_ancestors() Iterable[PureSequencePath]

Return the ancestors of this path.

Returns:

All the paths that are above this path in the hierarchy, ordered from the current path to the root, both included.

For the root path, the result will only contain the root path.

Example

>>> path = PureSequencePath(r"\foo\bar\baz")
>>> list(path.get_ancestors())
[
    PureSequencePath("\\foo\\bar\\baz"),
    PureSequencePath("\\foo\\bar"),
    PureSequencePath("\\foo"),
    PureSequencePath("\\"),
]
property name: str | None

Return the last part of the path.

The root path has no name and this attribute is None for it.

Example

>>> path = PureSequencePath(r"\foo\bar")
>>> path.name
'bar'
is_root() bool

Check if the path is the root path.

classmethod root() PureSequencePath

Returns the root path.

The root path is represented by the single backslash character “\”.

classmethod is_valid_name(name: str) bool

Check if a string is a valid name.

classmethod from_parts(
parts: Iterable[str],
) PureSequencePath

Create a path from its parts.

Raises:

InvalidPathFormatError – If one of the parts is not a valid name.

classmethod is_valid_path(path: str) bool

Check if a string is a valid path.

is_descendant_of(
other: PureSequencePath,
) bool

Check if this path is a descendant of another path.

A path is a descendant of another path if it starts with the other path.

A path is not a descendant of itself.

Example

>>> path = PureSequencePath(r"\foo\bar")
>>> other = PureSequencePath(r"\foo")
>>> path.is_descendant_of(other)
True