class PContext:
Known subclasses: acme.runtime.ScriptManager.ACMEPContext
Constructor: PContext(script, symbols, logFunc, logErrorFunc, ...)
Process context for a single script.
This is the main runtime object for the interpreter.
To run a script, create a PContext object, and call its run() method.
To add new symbols to the interpreter, inherit from PContext
and add them to the symbols dictionary during initialization.
A PContext object can be re-used.
| Method | __init__ |
Initialization of a PContext object. |
| Method | arguments |
Set the arguments for the current call scope. |
| Method | clear |
Remove all environment variables. |
| Method | copy |
Copy the error attributes from another PContext object. |
| Method | del |
Delete a variable for a name. If the variable exists in the global scope, it is deleted in all scopes. Otherwise, it is only deleted in the current scope. |
| Method | get |
Return an evironment variable for a case insensitive name. |
| Method | get |
Return the argument of meta data, or an empty string. |
| Method | get |
Return all variables and values which names match a regular expression. |
| Method | has |
Check if a meta data key exists. |
| Method | log |
Log a symbol in verbose mode to the script's log function. |
| Method | pop |
Remove a call from the stack.. |
| Method | push |
Save various stack information to the script's call stack. This creates a new PCall object. |
| Method | reset |
Reset the context / script. |
| Method | run |
Run the script in the PContext instance. |
| Method | script |
Set the name of the script in the meta data. |
| Method | set |
Clear old environment and assign a new environment. |
| Method | set |
Set an environment variable for a name. |
| Method | set |
Set the internal state and error codes. |
| Method | set |
Set the maximum runtime of the script. |
| Method | set |
Set the result symbol. The difference to directly setting the result attribute is that his method return self. |
| Method | set |
Set a variable for a name. If the variable exists in the global scope, it is updated or set in all scopes. Otherwise, it is only updated or set in the current scope. |
| Class Variable | __slots__ |
Slots of class attributes. |
| Instance Variable | allow |
Allow "[" and "]" for opening and closing lists as well. |
| Instance Variable | argv |
List of string that are arguments to the script. |
| Instance Variable | ast |
The script's abstract syntax tree. |
| Instance Variable | environment |
Dictionary of variables that are passed by the application to the script. Similar to variables, but the environment is not cleared. |
| Instance Variable | error |
Error state. |
| Instance Variable | error |
An optional function that is called when an error occured. |
| Instance Variable | evaluate |
Check and execute inline expressions in strings. |
| Instance Variable | fallback |
An optional function to retrieve unknown symbols from the caller. |
| Instance Variable | functions |
Dictoonary of defined script functions. |
| Instance Variable | log |
An optional function that receives error log messages. |
| Instance Variable | log |
An optional function that receives non-error log messages. |
| Instance Variable | match |
An optional function that is used to run regex comparisons. |
| Instance Variable | max |
Number of seconds that is a script allowed to run. |
| Instance Variable | meta |
Dictionary of the script's meta tags and their arguments. |
| Instance Variable | monitor |
An optional function to monitor function calls, e.g. to forbid them during particular executions. |
| Instance Variable | post |
An optional function that is called after running a script. |
| Instance Variable | pre |
An optional function that is called before running a script. |
| Instance Variable | print |
An optional function for printing messages to the screen, console, etc. |
| Instance Variable | result |
Intermediate and final results during the execution. |
| Instance Variable | script |
The script to run. |
| Instance Variable | startup |
The built-in commands. This original list will be restored later during reset. |
| Instance Variable | state |
The internal state of a script. |
| Instance Variable | symbols |
A dictionary of new symbols / functions to add to the interpreter. |
| Instance Variable | verbose |
Print more debug messages. |
| Property | arguments |
Return the arguments of the current call. |
| Property | current |
Get the current call as a PCall object. |
| Property | script |
The name of the script (from the meta data). |
| Property | variables |
The variables of the current scope. |
| Class Variable | _macro |
Regex for matching macros in strings and JSON. |
| Instance Variable | _call |
The internal call stack (internal). |
| Instance Variable | _max |
The max timestamp until the script may run (internal). |
str, symbols: PSymbolDict | None = None, logFunc: PLogCallable | None = lambda pcontext, msg: print(f'** {msg}'), logErrorFunc: PErrorLogCallable | None = lambda pcontext, msg, exception: print(f'!! {msg}'), printFunc: PLogCallable | None = lambda pcontext, msg: print(msg), preFunc: PFuncCallable | None = None, postFunc: PFuncCallable | None = None, errorFunc: PFuncCallable | None = None, matchFunc: PMatchCallable | None = lambda pcontext, l, r: l == r, maxRuntime: float | None = None, fallbackFunc: PSymbolCallable | None = None, monitorFunc: PSymbolCallable | None = None, allowBrackets: bool | None = False, verbose: bool | None = False):
¶
acme.runtime.ScriptManager.ACMEPContextInitialization of a PContext object.
| Parameters | |
script:str | The script to run. |
symbols:PSymbolDict | None | An optional dictionary of new symbols / functions to add to the interpreter. |
logPLogCallable | None | An optional function that receives non-error log messages. |
logPErrorLogCallable | None | An optional function that receives error log messages. |
printPLogCallable | None | An optional function for printing messages to the screen, console, etc. |
prePFuncCallable | None | An optional function that is called before running a script. |
postPFuncCallable | None | An optional function that is called after running a script. |
errorPFuncCallable | None | An optional function that is called when an error occured. |
matchPMatchCallable | None | An optional function that is used to run regex comparisons. |
maxfloat | None | Number of seconds that is a script allowed to run. |
fallbackPSymbolCallable | None | An optional function to retrieve unknown symbols from the caller. |
monitorPSymbolCallable | None | An optional function to monitor function calls, e.g. to forbid them during particular executions. |
allowbool | None | Allow "[" and "]" for opening and closing lists as well. |
verbose:bool | None | Print more debug messages. |
Set the arguments for the current call scope.
| Parameters | |
value:dict[ | The arguments for the current call scope. |
Delete a variable for a name. If the variable exists in the global scope, it is deleted in all scopes. Otherwise, it is only deleted in the current scope.
| Parameters | |
key:str | Variable name |
| Returns | |
SSymbol | None | Variable content, or None if variable is not defined. |
Return an evironment variable for a case insensitive name.
| Parameters | |
key:str | Environment variable name |
| Returns | |
SSymbol | Environment variable content, or None. |
Return the argument of meta data, or an empty string.
| Parameters | |
key:str | Key of the meta data to look for. |
default:str | None | Default value to return if the key is not found. |
| Returns | |
str | String, value or the default value. |
Return all variables and values which names match a regular expression.
| Parameters | |
expression:str | A string with the regular expression. |
| Returns | |
list[ | List of tuples ( variable name, variable value ). |
Check if a meta data key exists.
| Parameters | |
key:str | Key of the meta data to look for. |
| Returns | |
bool | True if the key exists, False otherwise. |
Run the script in the PContext instance.
| Parameters | |
arguments:list[ | Optional list of string arguments to the script. They are available to the script via the argv function. |
isbool | None | Optional indicator whether the script is called from another script. |
| Returns | |
PContext | PContext object with the result and the termination reason. |
Clear old environment and assign a new environment.
This includes the meta tags in the format meta.<tag>.
| Parameters | |
environment:dict[ | Dictionary with the new environment |
Set an environment variable for a name.
| Parameters | |
key:str | Environment variable name |
value:SSymbol | Value to store |
PError, msg: str, state: PState | None = PState.terminatedWithError, expression: SSymbol = None, exception: Exception | None = None) -> PContext:
¶
Set the internal state and error codes.
These can be retrieved by accessing the state and error attributes.
| Parameters | |
error:PError | PError to indicate the type of error. |
msg:str | String that further explains the error. |
state:PState | None | PState to indicate the state of the script. Default is "terminatedWithError". |
expression:SSymbol | The original SSymbol that caused the error. |
exception:Exception | None | Optional exception to provide with the error message. |
| Returns | |
PContext | Self. |
Set a variable for a name. If the variable exists in the global scope, it is updated or set in all scopes. Otherwise, it is only updated or set in the current scope.
| Parameters | |
key:str | Variable name |
value:SSymbol | Value to store |
Dictionary of variables that are passed by the application to the script. Similar to variables, but the environment is not cleared.
acme.runtime.ScriptManager.ACMEPContextNumber of seconds that is a script allowed to run.
An optional function to monitor function calls, e.g. to forbid them during particular executions.