permission
tuprolog.solve.exception.error.permission
¶
Permission errors: an operation is not allowed on some object, e.g. changing a static predicate.
ISO Prolog's permission_error(Operation, Kind, Culprit) error, thrown as
error(permission_error(Operation, Kind, Culprit), Extra), means that Operation (e.g.
modify, access, input) is not allowed on Culprit, an object of kind Kind (e.g.
private_procedure, stream): e.g. assertz(atom(x)) throws
permission_error(modify, private_procedure, atom/1), as library predicates cannot be changed.
The error is a PermissionError (the JVM class: import it explicitly, as it shadows Python's
built-in name), the operations are the values of the Operation enumeration (also available as
the OPERATION_* constants), and the kinds of objects those of the Permission enumeration (also
available as the PERMISSION_* constants). Build errors with permission_error.
Examples:
>>> from tuprolog.solve.prolog import prolog_solver
>>> prolog_solver().solve_once("catch(assertz(atom(x)), error(E, _), true)")["E"]
permission_error(modify, private_procedure, atom/1)
See Also
tuprolog.solve.primitive.ensuring_procedure_has_permission, raising these errors;
2P-Kt's documentation on
errors and exceptions.
Operation
module-attribute
¶
Operation = PermissionError.Operation
The enumeration of the operations of permission errors (2P-Kt's PermissionError.Operation).
Each value (also available as an OPERATION_* constant) is the Operation of a
permission_error(Operation, Kind, Culprit) term: to_term() gives it as an atom (e.g.
modify), and operation as a string. Operation.of(name) and Operation.fromTerm(term) look
a value up (see operation).
Permission
module-attribute
¶
Permission = PermissionError.Permission
The enumeration of the kinds of objects of permission errors (2P-Kt's Permission).
Each value (also available as a PERMISSION_* constant) is the Kind of a
permission_error(Operation, Kind, Culprit) term: to_term() gives it as an atom (e.g.
static_procedure), and permission as a string. Permission.of(name) and
Permission.fromTerm(term) look a value up (see permission_type).
OPERATION_ACCESS
module-attribute
¶
OPERATION_ACCESS = Operation.ACCESS
access: the operation of accessing an object.
E.g. reading a private procedure's clauses, or a private attribute through OOPLib.
OPERATION_ADD_ALIAS
module-attribute
¶
OPERATION_ADD_ALIAS = Operation.ADD_ALIAS
add_alias: the operation of adding an alias (e.g. to a stream, or an OOPLib alias in use).
OPERATION_CLOSE
module-attribute
¶
OPERATION_CLOSE = Operation.CLOSE
close: the operation of closing a stream.
OPERATION_CREATE
module-attribute
¶
OPERATION_CREATE = Operation.CREATE
create: the operation of creating an object (e.g. an operator, or a flag).
OPERATION_INPUT
module-attribute
¶
OPERATION_INPUT = Operation.INPUT
input: the operation of reading from a stream.
OPERATION_INVOKE
module-attribute
¶
OPERATION_INVOKE = Operation.INVOKE
invoke: the operation of invoking a method through OOPLib.
OPERATION_MODIFY
module-attribute
¶
OPERATION_MODIFY = Operation.MODIFY
modify: the operation of modifying an object (e.g. asserting or retracting clauses).
OPERATION_OPEN
module-attribute
¶
OPERATION_OPEN = Operation.OPEN
open: the operation of opening a source or sink.
OPERATION_OUTPUT
module-attribute
¶
OPERATION_OUTPUT = Operation.OUTPUT
output: the operation of writing on a stream.
OPERATION_REPOSITION
module-attribute
¶
OPERATION_REPOSITION = Operation.REPOSITION
reposition: the operation of repositioning a stream.
PERMISSION_BINARY_STREAM
module-attribute
¶
PERMISSION_BINARY_STREAM = Permission.BINARY_STREAM
binary_stream: the object is a binary stream.
PERMISSION_FLAG
module-attribute
¶
PERMISSION_FLAG = Permission.FLAG
flag: the object is a Prolog flag (e.g. a read-only one).
Also used by OOPLib for aliases already registered.
PERMISSION_OPERATOR
module-attribute
¶
PERMISSION_OPERATOR = Permission.OPERATOR
operator: the object is an operator (e.g. ,, which cannot be redefined).
PERMISSION_PAST_END_OF_STREAM
module-attribute
¶
PERMISSION_PAST_END_OF_STREAM = (
Permission.PAST_END_OF_STREAM
)
past_end_of_stream: the object is a stream already past its end.
PERMISSION_PRIVATE_PROCEDURE
module-attribute
¶
PERMISSION_PRIVATE_PROCEDURE = Permission.PRIVATE_PROCEDURE
private_procedure: the object is a private procedure, i.e. a predicate defined by a library.
PERMISSION_SOURCE_SINK
module-attribute
¶
PERMISSION_SOURCE_SINK = Permission.SOURCE_SINK
source_sink: the object is a source or sink of streams.
PERMISSION_STATIC_PROCEDURE
module-attribute
¶
PERMISSION_STATIC_PROCEDURE = Permission.STATIC_PROCEDURE
static_procedure: the object is a static procedure (of the static knowledge base).
PERMISSION_OOP_METHOD
module-attribute
¶
PERMISSION_OOP_METHOD = Permission.OOP_METHOD
oop_method: the object is a method or attribute of an object, accessed through OOPLib.
PERMISSION_STREAM
module-attribute
¶
PERMISSION_STREAM = Permission.STREAM
stream: the object is a stream.
PERMISSION_TEXT_STREAM
module-attribute
¶
PERMISSION_TEXT_STREAM = Permission.TEXT_STREAM
text_stream: the object is a text stream.
permission_error
¶
permission_error(
context: ExecutionContext,
procedure: Signature,
operation: Operation,
permission: Permission,
culprit: Term,
) -> PermissionError
Creates a permission error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
ExecutionContext
|
the execution context in which the error occurs (e.g. a request's |
required |
procedure
|
Signature
|
the signature of the predicate raising the error (e.g. a request's |
required |
operation
|
Operation
|
the attempted operation (e.g. |
required |
permission
|
Permission
|
the kind of the object (e.g. |
required |
culprit
|
Term
|
the object. |
required |
Returns:
| Type | Description |
|---|---|
PermissionError
|
The error, thrown as |
Examples:
>>> from tuprolog.solve import signature
>>> from tuprolog.solve.exception.error import *
>>> from tuprolog.solve.prolog import prolog_solver
>>> context = prolog_solver().current_context
>>> from tuprolog.core import indicator
>>> error = permission_error(
... context,
... signature("assertz", 1),
... OPERATION_MODIFY,
... PERMISSION_STATIC_PROCEDURE,
... indicator("foo", 2),
... )
>>> error.type
permission_error(modify, static_procedure, foo/2)
operation
¶
The Operation named by a string or an atom.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str | Term
|
the name, as a string (case-insensitive) or a |
required |
Returns:
| Type | Description |
|---|---|
Operation
|
The matching |
Raises:
| Type | Description |
|---|---|
IllegalArgumentException
|
if no |
Examples:
>>> from tuprolog.core import atom
>>> from tuprolog.solve.exception.error.permission import *
>>> operation("modify") == operation(atom("modify")) == OPERATION_MODIFY
True
permission_type
¶
permission_type(name: str | Term) -> Permission
The Permission named by a string or an atom.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str | Term
|
the name, as a string (case-insensitive) or a |
required |
Returns:
| Type | Description |
|---|---|
Permission
|
The matching |
Raises:
| Type | Description |
|---|---|
IllegalArgumentException
|
if no |
Examples:
>>> from tuprolog.solve.exception.error.permission import *
>>> permission_type("static_procedure") == PERMISSION_STATIC_PROCEDURE
True