blob: a5159701e4c688a325de8fdffb588c5907f5f233 (
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
|
"""Utilities for handling privileges."""
from typing import Union, Sequence, TypeAlias
Operator: TypeAlias = str # Valid operators: "AND", "OR"
Privilege: TypeAlias = str
PrivilegesList: TypeAlias = Sequence[Privilege]
ParseTree = tuple[Operator,
# Leaves (`PrivilegesList` objects) on the left,
# trees (`ParseTree` objects) on the right
Union[PrivilegesList, tuple[PrivilegesList, 'ParseTree']]]
class SpecificationValueError(ValueError):
"""Raised when there is an error in the specification string."""
pass
def parse(spec: str) -> ParseTree:
"""Parse a string specification for privileges and return a tree of data
objects of the form (<operator> (<check>))"""
# if(spec.strip() == ""):
# raise SpecificationValueError(
# "You passed an empty specification. I do not know what to do.")
return tuple()
def check(spec: str, privileges: tuple[str, ...]) -> bool:
"""Check that the sequence of `privileges` satisfies `spec`."""
return False
|