Registry¶
The main operator registry class and related exceptions.
- exception jsonlogic.registry.AlreadyRegistered(operator_id: str, /)¶
The provided ID is already registered.
- exception jsonlogic.registry.UnknownOperator(operator_id: str, /)¶
The provided ID does not exist in the registry.
- class jsonlogic.registry.OperatorRegistry¶
A collection of
Operatorclasses.Acts as a wrapper over a mapping of operator IDs to the actual class.
>>> reg = OperatorRegistry() >>> reg.register("var", MyVarOperator) >>> reg.get("var") <class 'MyVarOperator'> >>> reg.get("unknown") Traceback (most recent call last): ... UnknownOperator: "unknown"
- register(operator_id: str, *, force: bool = False) Callable[[OperatorTypeT], OperatorTypeT]¶
- register(operator_id: str, operator_type: OperatorTypeT, *, force: bool = False) OperatorTypeT
Register an operator type under the provided ID.
- Parameters:
- Raises:
AlreadyRegistered – If
forcewasn’t set and the ID already exists.
Note
The method is usable as a decorator:
reg = OperatorRegistry() reg.register("==", EqualOperator) # Or: @reg.register("==") class EqualOperator(Operator): ...
- get(operator_id: str, /) type[Operator]¶
Get the operator class corresponding to the ID.
- Parameters:
operator_id¶ – The registered ID of the operator.
- Raises:
UnknownOperator – If the provided ID does not exist.
- remove(operator_id: str, /) None¶
Remove the operator from the registry.
- Parameters:
operator_id¶ – The registered ID of the operator to be removed.