aboutsummaryrefslogtreecommitdiffstats
path: root/bsfs/graph/nodes.py
diff options
context:
space:
mode:
authorMatthias Baumgartner <dev@igsor.net>2023-03-01 12:39:42 +0100
committerMatthias Baumgartner <dev@igsor.net>2023-03-01 12:39:42 +0100
commitf9eec185bf3d857c220e5d78de75ec6713437330 (patch)
treee59a4a0fa57f3602e774891ebe4dba52b7518a7a /bsfs/graph/nodes.py
parent9b490d19dcebc0fc24cb2ab89a783f1f7d6147f7 (diff)
downloadbsfs-f9eec185bf3d857c220e5d78de75ec6713437330.tar.gz
bsfs-f9eec185bf3d857c220e5d78de75ec6713437330.tar.bz2
bsfs-f9eec185bf3d857c220e5d78de75ec6713437330.zip
Construct Graph and Nodes with AC instead of user
Diffstat (limited to 'bsfs/graph/nodes.py')
-rw-r--r--bsfs/graph/nodes.py41
1 files changed, 20 insertions, 21 deletions
diff --git a/bsfs/graph/nodes.py b/bsfs/graph/nodes.py
index bc71a32..91cbb5d 100644
--- a/bsfs/graph/nodes.py
+++ b/bsfs/graph/nodes.py
@@ -37,8 +37,8 @@ class Nodes():
# triple store backend.
_backend: TripleStoreBase
- # user uri.
- _user: URI
+ # access controls.
+ _ac: ac.AccessControlBase
# node type.
_node_type: bsc.Node
@@ -49,31 +49,30 @@ class Nodes():
def __init__(
self,
backend: TripleStoreBase,
- user: URI,
+ access_control: ac.AccessControlBase,
node_type: bsc.Node,
guids: typing.Iterable[URI],
):
# set main members
self._backend = backend
- self._user = user
+ self._ac = access_control
self._node_type = node_type
self._guids = set(guids)
# create helper instances
# FIXME: Assumes that the schema does not change while the instance is in use!
- self._ac = ac.NullAC(self._backend, self._user)
def __eq__(self, other: typing.Any) -> bool:
return isinstance(other, Nodes) \
and self._backend == other._backend \
- and self._user == other._user \
+ and self._ac == other._ac \
and self._node_type == other._node_type \
and self._guids == other._guids
def __hash__(self) -> int:
- return hash((type(self), self._backend, self._user, self._node_type, tuple(sorted(self._guids))))
+ return hash((type(self), self._backend, self._ac, self._node_type, tuple(sorted(self._guids))))
def __repr__(self) -> str:
- return f'{typename(self)}({self._backend}, {self._user}, {self._node_type}, {self._guids})'
+ return f'{typename(self)}({self._backend}, {self._ac}, {self._node_type}, {self._guids})'
def __str__(self) -> str:
return f'{typename(self)}({self._node_type}, {self._guids})'
@@ -94,44 +93,44 @@ class Nodes():
return self._backend.schema
def __add__(self, other: typing.Any) -> 'Nodes':
- """Concatenate guids. Backend, user, and node type must match."""
+ """Concatenate guids. Backend, AC, and node type must match."""
if not isinstance(other, type(self)):
return NotImplemented
if self._backend != other._backend:
raise ValueError(other)
- if self._user != other._user:
+ if self._ac != other._ac:
raise ValueError(other)
if self.node_type != other.node_type:
raise ValueError(other)
- return Nodes(self._backend, self._user, self.node_type, self._guids | other._guids)
+ return Nodes(self._backend, self._ac, self.node_type, self._guids | other._guids)
def __or__(self, other: typing.Any) -> 'Nodes':
- """Concatenate guids. Backend, user, and node type must match."""
+ """Concatenate guids. Backend, AC, and node type must match."""
return self.__add__(other)
def __sub__(self, other: typing.Any) -> 'Nodes':
- """Subtract guids. Backend, user, and node type must match."""
+ """Subtract guids. Backend, AC, and node type must match."""
if not isinstance(other, type(self)):
return NotImplemented
if self._backend != other._backend:
raise ValueError(other)
- if self._user != other._user:
+ if self._ac != other._ac:
raise ValueError(other)
if self.node_type != other.node_type:
raise ValueError(other)
- return Nodes(self._backend, self._user, self.node_type, self._guids - other._guids)
+ return Nodes(self._backend, self._ac, self.node_type, self._guids - other._guids)
def __and__(self, other: typing.Any) -> 'Nodes':
- """Intersect guids. Backend, user, and node type must match."""
+ """Intersect guids. Backend, AC, and node type must match."""
if not isinstance(other, type(self)):
return NotImplemented
if self._backend != other._backend:
raise ValueError(other)
- if self._user != other._user:
+ if self._ac != other._ac:
raise ValueError(other)
if self.node_type != other.node_type:
raise ValueError(other)
- return Nodes(self._backend, self._user, self.node_type, self._guids & other._guids)
+ return Nodes(self._backend, self._ac, self.node_type, self._guids & other._guids)
def __len__(self) -> int:
"""Return the number of guids."""
@@ -140,7 +139,7 @@ class Nodes():
def __iter__(self) -> typing.Iterator['Nodes']:
"""Iterate over individual guids. Returns `Nodes` instances."""
return iter(
- Nodes(self._backend, self._user, self.node_type, {guid})
+ Nodes(self._backend, self._ac, self.node_type, {guid})
for guid in self._guids
)
@@ -266,12 +265,12 @@ class Nodes():
# process triples
for root, name, raw in triples:
# get node
- node = Nodes(self._backend, self._user, self.node_type, {root})
+ node = Nodes(self._backend, self._ac, self.node_type, {root})
# get path
path, tail = name2path[name]
# covert raw to value
if isinstance(tail.range, bsc.Node):
- value = Nodes(self._backend, self._user, tail.range, {raw})
+ value = Nodes(self._backend, self._ac, tail.range, {raw})
else:
value = raw
# emit triple