aboutsummaryrefslogtreecommitdiffstats
path: root/bsie/utils/node.py
blob: ecf39cde431145435c487daf0884a99a7606b9d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""Lighweight Node to bridge to BSFS.

Part of the bsie module.
A copy of the license is provided with the project.
Author: Matthias Baumgartner, 2022
"""
# imports
import typing

# bsie imports
from bsie.utils import bsfs

# exports
__all__: typing.Sequence[str] = (
    'Node',
    )


## code ##

class Node():
    """Lightweight Node, disconnected from any bsfs structures."""

    # node type.
    node_type: bsfs.URI

    # node URI.
    uri: bsfs.URI

    def __init__(
            self,
            node_type: bsfs.URI,
            uri: bsfs.URI,
            ):
        # assign members
        self.node_type = bsfs.URI(node_type)
        self.uri = bsfs.URI(uri)

    def __eq__(self, other: typing.Any) -> bool:
        return isinstance(other, Node) \
            and other.node_type == self.node_type \
            and other.uri == self.uri

    def __hash__(self) -> int:
        return hash((type(self), self.node_type, self.uri))

    def __str__(self) -> str:
        return f'{bsfs.typename(self)}({self.node_type}, {self.uri})'

    def __repr__(self) -> str:
        return f'{bsfs.typename(self)}({self.node_type}, {self.uri})'

## EOF ##