"""Utilities for handling privileges.""" from typing import Union, TypeAlias PrivilegesList = tuple[str, ...] CheckObj = tuple[str, PrivilegesList] # where the first item is either "OR" or "AND" Checks: TypeAlias = Union[ CheckObj, tuple[str, tuple['Checks', ...]]] class SpecificationValueError(ValueError): """Raised when there is an error in the specification string.""" pass def parse(spec: str) -> Checks: """Parse a string specification for privileges and return a tree of data objects of the form ( ())""" # 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