class ACMEPContext(PContext):
Constructor: ACMEPContext(script, preFunc, postFunc, errorFunc, ...)
Child class of the PContext context class that adds further functions and details.
| Method | __init__ |
Initializer for the context class. |
| Method | do |
Clear the console. |
| Method | do |
Execute a "create-resource" request to create a resource on a CSE. |
| Method | do |
Return a list of CSE attribute infos for the given attribute name. The search is done over the short and long names of the attributes using a fuzzy search when searching the long names. |
| Method | do |
Retrieve the CSE status. |
| Method | do |
Execute a "delete-resource" request on the CSE. |
| Method | do |
Get a setting from the CSE's configuration. |
| Method | do |
Get the log level of the CSE. This will be one of the following strings: |
| Method | do |
Retrieve a value for key from the persistent storage storage. |
| Method | do |
Test for the existence of a key in the CSE's configuration. |
| Method | do |
Test for the existence of a key in the persistent storage. |
| Method | do |
Making a http(s) request. |
| Method | do |
Import a raw resource. Not much verification is done, and a full resource representation, including, for example, the parent resource ID, must be provided. |
| Method | do |
Print a divider line to the log (on DEBUG level). |
| Method | do |
Execute a NOTIFY request. The originator must be set before this function. |
| Method | do |
Open a web browser with the given URL. |
| Method | do |
Ping a TCP service (server) to check if it is available and reachable. |
| Method | do |
Print a beautified JSON to the console. |
| Method | do |
Store a value in the persistent storage. |
| Method | do |
Run a comparison query against a JSON structure. This compares to the oneM2M advanced query filtering in RETRIEVE/DISCOVERY requests. |
| Method | do |
Check and refresh the registrations to the registrars. |
| Method | do |
Either remove a value from the persistent storage, or remove all values from the storage with a given storage ID. |
| Method | do |
Reset the CSE. |
| Method | do |
Restart the CSE. This will stop the CSE and all running services. |
| Method | do |
Execute a RETRIEVE request. |
| Method | do |
Run another script. |
| Method | do |
Determine whether the CSE currently runs in an IPython environment, such as Jupyter Notebooks. |
| Method | do |
Determine whether the CSE currently runs in Text UI mode. |
| Method | do |
Schedule the next script to run after the current script has finished. |
| Method | do |
Set the description of a category. |
| Method | do |
Set a CSE configuration. The configuration must be an existing configuration. No new configurations can be created this way. |
| Method | do |
Enable/disable the console logging. |
| Method | do |
Shut down the CSE. This will stop the CSE and all running services. |
| Method | do |
Show a TUI confirmation dialog. |
| Method | do |
Show a TUI notification. |
| Method | do |
Refresh the TUI resources. This will update the resource Tree and the resource details. |
| Method | do |
Execute a TUI visual bell. This shortly flashes the script's menu entry. |
| Method | do |
Execute an UPDATE request. |
| Method | filename |
Set the script's filename (to the filename meta information). |
| Method | log |
Callback for normal log messages. |
| Method | log |
Callback for error log messages. |
| Method | prnt |
Callback for print function messages. |
| Class Variable | __slots__ |
Slots of class attributes. |
| Class Variable | dispatcher |
Injected Dispatcher instance. |
| Class Variable | factory |
Injected Factory instance. |
| Class Variable | management |
Injected ManagementSupport instance. |
| Class Variable | registration |
Injected RegistrationManager instance. |
| Class Variable | request |
Injected RequestManager instance. |
| Class Variable | reset |
Injected function to reset the CSE. |
| Class Variable | script |
Injected ScriptManager instance. |
| Class Variable | text |
Injected TextUI plugin, if available. |
| Class Variable | validator |
Injected Validator instance. |
| Instance Variable | file |
The script file's latest modified timestamp. |
| Instance Variable | max |
Number of seconds that is a script allowed to run. |
| Instance Variable | next |
The next script to be executed. Used for chaining scripts. |
| Instance Variable | script |
The script filename. |
| Property | error |
Format and return an error message. |
| Property | filename |
Return the script's filename (from the filename meta information). |
| Method | _handle |
Internally handle a request, either via a direct URL or through an originator. |
| Method | _pcontext |
Update a PContext instance from a CSE Result. |
| Method | _validate |
Validate the script |
Inherited from PContext:
| 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. |
| 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 | 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, preFunc: PFuncCallable | None = None, postFunc: PFuncCallable | None = None, errorFunc: PFuncCallable | None = None, filename: str | None = None, fallbackFunc: PSymbolCallable = None, monitorFunc: PSymbolCallable = None, allowBrackets: bool = False):
¶
Initializer for the context class.
| Parameters | |
script:str | A script contained in a string or a list of strings. |
prePFuncCallable | None | An optional callback that is called with the PContext object just before the script is executed. Returning None prevents the script execution. |
postPFuncCallable | None | An optional callback that is called with the PContext object just after the script finished execution. |
errorPFuncCallable | None | An optional callback that is called with the PContext object when encountering an error during script execution. |
filename:str | None | The script's filename. |
fallbackPSymbolCallable | Undocumented |
monitorPSymbolCallable | Undocumented |
allowbool | Allow "[" and "]" for opening and closing lists as well. |
Execute a "create-resource" request to create a resource on a CSE.
The function has the following arguments:
- originator of the request
- target resource ID
- JSON resource
- Optional: JSON with additional request arguments
The function returns a quoted list as a result with the following symbols:
- Response status
- Response resource
Example
(create-resource "originator" "cse-in" { "m2m:cnt": { "rn": "myCnt" }} [<request arguments>]) -> ( <status> <resource> )
| Parameters | |
pcontext:PContext | PContext object of the running script. |
symbol:SSymbol | The symbol to execute. |
| Returns | |
PContext | The updated PContext object with the operation result. |
Return a list of CSE attribute infos for the given attribute name. The search is done over the short and long names of the attributes using a fuzzy search when searching the long names.
The function has the following arguments:
- attribute name. This could be a short name or a long name.
The function returns a quoted list where each entry is another quoted list with the following symbols:
- attribute short name
- attribute long name
- attribute type
Example
(cse-attribute-info "acop") -> ( ( "acop" "accessControlOperations" "nonNegInteger" ) )
| Parameters | |
pcontext:PContext | PContext object of the running script. |
symbol:SSymbol | The symbol to execute. |
| Returns | |
PContext | The updated PContext object with the operation result. |
Execute a "delete-resource" request on the CSE.
The function has the following arguments:
- originator of the request
- target resource ID
- Optional: JSON with additional request arguments
The function returns a quoted list as a result with the following symbols:
- Response status
- Response resource
Example
(delete-resource "originator "cse-in/myCnt" [<request arguments>]) -> ( <status> <resource> )
| Parameters | |
pcontext:PContext | PContext object of the running script. |
symbol:SSymbol | The symbol to execute. |
| Returns | |
PContext | The updated PContext object with the operation result. |
Get a setting from the CSE's configuration.
Example
(get-configuration "cse.cseID") -> "id-in
| Parameters | |
pcontext:PContext | PContext object of the running script. |
symbol:SSymbol | The symbol to execute. |
| Returns | |
PContext | The updated PContext object with the operation result. |
| Raises | |
PUndefinedError | In case the configuration key is undefined |
Get the log level of the CSE. This will be one of the following strings:
- "DEBUG"
- "INFO"
- "WARNING"
- "ERROR"
- "OFF"
Example
(get-loglevel) -> "INFO"
| Parameters | |
pcontext:PContext | PContext object of the running script. |
symbol:SSymbol | The symbol to execute. |
| Returns | |
PContext | The updated PContext object with the operation result. |
Retrieve a value for key from the persistent storage storage.
Example
(get-storage "aStorageID" "aKey") -> value
| Parameters | |
pcontext:PContext | PContext object of the running script. |
symbol:SSymbol | The symbol to execute. |
| Returns | |
PContext | The updated PContext object with the operation result. |
| Raises | |
PUndefinedError | If the key is undefined in the persistent storage. |
Making a http(s) request.
Example
(http post "https://example.com"
('("aHeader" "a header value")
'("anotherHeader" "another header value"))
"body content")
| Parameters | |
pcontext:PContext | PContext object of the running script. |
symbol:SSymbol | The symbol to execute. |
| Returns | |
PContext | The updated PContext object with the operation result. |
| Raises | |
PInvalidArgumentError | In case the operation is undefined or an invalid header definion is encountered. |
Import a raw resource. Not much verification is done, and a full resource representation, including, for example, the parent resource ID, must be provided.
Example
(import-raw <originator> <resource JSON> )
| Parameters | |
pcontext:PContext | PContext object of the running script. |
symbol:SSymbol | The symbol to execute. |
| Returns | |
PContext | The updated PContext object with the operation result. |
| Raises | |
PRuntimeError | In case an error during the import and create is encountered. |
Print a divider line to the log (on DEBUG level).
Optionally add a message that is centered on the line.
Example
(log-divider "Hello, World")
| Parameters | |
pcontext:PContext | PContext object of the running script. |
symbol:SSymbol | The symbol to execute. |
| Returns | |
PContext | The updated PContext object with the operation result. |
Execute a NOTIFY request. The originator must be set before this function.
The function has the following arguments:
- originator of the request
- target resource ID
- JSON resource
- Optional: JSON with additional request arguments
The function returns a quoted list as a result with the following symbols:
- Response status
- Response resource
Example
(send-notification <originator> <target> <resource JSON> [<headers JSON>]) -> ( <status> <resource> )
| Parameters | |
pcontext:PContext | PContext object of the running script. |
symbol:SSymbol | The symbol to execute. |
| Returns | |
PContext | The updated PContext object with the operation result. |
Open a web browser with the given URL.
The function has the following arguments:
- URL to open in the browser.
The function returns a boolean as a result, indicating if the browser could be opened.
Example
(open-web-browser <url>) -> boolean
| Parameters | |
pcontext:PContext | PContext object of the running script. |
symbol:SSymbol | The symbol to execute. |
| Returns | |
PContext | The updated PContext object with the operation result. |
Ping a TCP service (server) to check if it is available and reachable.
The function has the following arguments:
- server name or IP address.
- port number.
- Optional: timeout in seconds (default: 10).
The function returns a boolean as a result, indicating if the service is reachable.
Example
(ping-service <server> <port> [<timeout>]) -> boolean
| Parameters | |
pcontext:PContext | PContext object of the running script. |
symbol:SSymbol | The symbol to execute. |
| Returns | |
PContext | The updated PContext object with the operation result. |
Print a beautified JSON to the console.
Nothing will be printed if the CSE is running in headless mode.
Example
(print-json { "a" : "b" })
| Parameters | |
pcontext:PContext | PContext object of the running script. |
symbol:SSymbol | The symbol to execute. |
| Returns | |
PContext | The updated PContext object with the operation result. |
Run a comparison query against a JSON structure. This compares to the oneM2M advanced query filtering in RETRIEVE/DISCOVERY requests.
The first argument is an s-expression that only contains comparisons.
Example
(query-resource '(== rn "cnt1234")) { "rn": "cnt1234", "x": 123 })
| Parameters | |
pcontext:PContext | PContext object of the running script. |
symbol:SSymbol | The symbol to execute. |
| Returns | |
PContext | The updated PContext object with the operation result. |
Either remove a value from the persistent storage, or remove all values from the storage with a given storage ID.
Example
(storage-remove "aStorageID" "aKey") (storage-remove "aStorageID")
| Parameters | |
pcontext:PContext | PContext object of the running script. |
symbol:SSymbol | The symbol to execute. |
| Returns | |
PContext | The updated PContext object with the operation result. |
Restart the CSE. This will stop the CSE and all running services.
This function returns normally, but the CSE will start to shut down after returning. The script will be stopped at any time after this function returns.
The difference to the "shutdown-cse" function is that this function will quit with a return code of 82, while the "shutdown-cse" function will quit with a return code of 0.
Example
(restart-cse) -> nil
| Parameters | |
pcontext:PContext | PContext object of the running script. |
symbol:SSymbol | The symbol to execute. |
| Returns | |
PContext | The updated PContext object with the operation result. |
Execute a RETRIEVE request.
The function has the following arguments:
- originator of the request
- target resource ID
- Optional: JSON with additional request arguments
The function returns a quoted list as a result with the following symbols:
- Response status
- Response resource
Example
(retrieve-resource "originator" "cse-in" [(<headers JSON>)] -> ( <status> <resource> )
| Parameters | |
pcontext:PContext | PContext object of the running script. |
symbol:SSymbol | The symbol to execute. |
| Returns | |
PContext | The updated PContext object with the operation result. |
Run another script.
The result of the script is passed as the result of this function.
Example
(run-script <script name> [<arguments>]* ) -> ( <status> <resource> )
| Parameters | |
pcontext:PContext | PContext object of the running script. |
symbol:SSymbol | The symbol to execute. |
isbool | Boolean indicator whether the script result (functions, variables) shall be added to the currently running script. |
| Returns | |
PContext | The updated PContext object with the operation result. |
| Raises | |
PUndefinedError | In case there is no script with that name. |
PRuntimeError | In case the script exits with an error. |
Determine whether the CSE currently runs in an IPython environment, such as Jupyter Notebooks.
Example
(runs-in-ipython)
| Parameters | |
pcontext:PContext | PContext object of the running script. |
symbol:SSymbol | The symbol to execute. |
| Returns | |
PContext | The updated PContext object with the operation result, ie. a boolean value. |
Schedule the next script to run after the current script has finished.
Example
(schedule-next-script "scriptName" "arg1" "arg2" ...) (schedule-next-script "scriptName")
| Parameters | |
pcontext:PContext | PContext object of the running script. |
symbol:SSymbol | The symbol to execute. |
| Returns | |
PContext | The updated PContext object. |
Set a CSE configuration. The configuration must be an existing configuration. No new configurations can be created this way.
Example
(set-config <configuration key> <value>)
| Parameters | |
pcontext:PContext | PContext object of the running script. |
symbol:SSymbol | The symbol to execute. |
| Returns | |
PContext | The updated PContext object with the operation result. |
| Raises | |
PInvalidTypeError | In case the data types of the configuration setting and the new value are different from each other. |
PUnsupportedError | In case the data type is not supported. |
PInvalidArgumentError | In case the setting could not be updated. |
PUndefinedError | In case the key references an undefined configuration setting. |
Shut down the CSE. This will stop the CSE and all running services.
This function returns normally, but the CSE will start to shut down after returning. The script will be stopped at any time after this function returns.
Example
(shutdown-cse) -> nil
| Parameters | |
pcontext:PContext | PContext object of the running script. |
symbol:SSymbol | The symbol to execute. |
| Returns | |
PContext | The updated PContext object with the operation result. |
Show a TUI confirmation dialog.
This function is only available in TUI mode. It has the following arguments.
- text: The text to show in the confirmation dialog.
- title: The title of the confirmation dialog.
- confirmButtonText: (Optional) The text for the confirm button. Default: "OK".
- cancelButtonText: (Optional) The text for the cancel button. Default: "Cancel".
The function returns a boolean value indicating whether the user confirmed or cancelled the dialog, or NIL if the dialog was closed without a selection.
Example
(tui-confirm "Do you want to continue?" "Confirmation") -> true
| Parameters | |
pcontext:PContext | PContext object of the running script. |
symbol:SSymbol | The symbol to execute. |
| Returns | |
PContext | The updated PContext object with the operation result. |
Show a TUI notification.
This function is only available in TUI mode. It has the following arguments.
- message: The message to show.
- title: (Optional) The title of the notification.
- severity: (Optional) The severity of the notification. Can be one of the following values: information, warning, error.
- timeout: (Optional) The timeout in seconds after which the notification will disappear. If not specified, the notification will disappear after 3 seconds.
The function returns NIL.
Example
(tui-notify "This is a notification") -> nil
| Parameters | |
pcontext:PContext | PContext object of the running script. |
symbol:SSymbol | The symbol to execute. |
| Returns | |
PContext | The updated PContext object. |
Execute an UPDATE request.
The function has the following arguments:
- originator of the request
- target resource ID
- JSON resource
- Optional: JSON with additional request arguments
The function returns a quoted list as a result with the following symbols:
- Response status
- Response resource
Example
(update-resource "originator" "cse-in/myCnt" { "m2m:cnt" { "lbl": ["aLabel"] }} [<request arguments>]) -> ( <status> <resource> )
| Parameters | |
pcontext:PContext | PContext object of the running script. |
symbol:SSymbol | The symbol to execute. |
| Returns | |
PContext | The updated PContext object with the operation result. |
Set the script's filename (to the filename meta information).
| Parameters | |
filename:str | The full filename. |
Callback for normal log messages.
| Parameters | |
pcontext:PContext | Script context. Not used. |
msg:str | log message. |
Callback for error log messages.
| Parameters | |
pcontext:PContext | Script context. Not used. |
msg:str | The log message. |
exception:Exception | None | Optional exception to log. |
Callback for print function messages.
| Parameters | |
pcontext:PContext | Script context. Not used. |
msg:str | The log message. |
Return the script's filename (from the filename meta information).
| Returns | |
| String with the full filename. |
Internally handle a request, either via a direct URL or through an originator.
Return status and resources in the variables result.status and result.resource respectively.
| Parameters | |
pcontext:PContext | PContext object of the running script. |
symbol:SSymbol | The symbol to execute. |
operation:Operation | The operation to perform. |
| Returns | |
PContext | The updated PContext object with the operation result. |
| Raises | |
PInvalidArgumentError | In case the input, e.g. the resource, is incorrect. |