diff options
Diffstat (limited to 'bsfs/query/validator.py')
-rw-r--r-- | bsfs/query/validator.py | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/bsfs/query/validator.py b/bsfs/query/validator.py index f0aa795..10ca492 100644 --- a/bsfs/query/validator.py +++ b/bsfs/query/validator.py @@ -1,9 +1,4 @@ -""" -Part of the BlackStar filesystem (bsfs) module. -A copy of the license is provided with the project. -Author: Matthias Baumgartner, 2022 -""" # imports import typing @@ -41,7 +36,11 @@ class Filter(): def __init__(self, schema: bsc.Schema): self.schema = schema - def __call__(self, root_type: bsc.Node, query: ast.filter.FilterExpression): + def __call__(self, root_type: bsc.Node, query: ast.filter.FilterExpression) -> bool: + """Alias for `Filter.validate`.""" + return self.validate(root_type, query) + + def validate(self, root_type: bsc.Node, query: ast.filter.FilterExpression) -> bool: """Validate a filter *query*, assuming the subject having *root_type*. Raises a `bsfs.utils.errors.ConsistencyError` if the query violates the schema. @@ -178,7 +177,7 @@ class Filter(): if not type_ <= dom: raise errors.ConsistencyError(f'expected type {dom}, found {type_}') # node.count is a numerical expression - self._parse_filter_expression(self.schema.literal(ns.bsfs.Number), node.count) + self._parse_filter_expression(self.schema.literal(ns.bsl.Number), node.count) def _distance(self, type_: bsc.Vertex, node: ast.filter.Distance): # type is a Literal @@ -219,7 +218,7 @@ class Filter(): if type_ not in self.schema.literals(): raise errors.ConsistencyError(f'literal {type_} is not in the schema') # type must be a numerical - if not type_ <= self.schema.literal(ns.bsfs.Number): + if not type_ <= self.schema.literal(ns.bsl.Number): raise errors.ConsistencyError(f'expected a number type, found {type_}') # FIXME: Check if node.value corresponds to type_ @@ -242,7 +241,11 @@ class Fetch(): def __init__(self, schema: bsc.Schema): self.schema = schema - def __call__(self, root_type: bsc.Node, query: ast.fetch.FetchExpression): + def __call__(self, root_type: bsc.Node, query: ast.fetch.FetchExpression) -> bool: + """Alias for `Fetch.validate`.""" + return self.validate(root_type, query) + + def validate(self, root_type: bsc.Node, query: ast.fetch.FetchExpression) -> bool: """Validate a fetch *query*, assuming the subject having *root_type*. Raises a `bsfs.utils.errors.ConsistencyError` if the query violates the schema. |