Program for embedding and executing Python code.
More...
#include <QC_PythonProgram.dox.h>
|
| aliasDefinition (string python_source_path, string python_target_path) |
| Creates an alias in the Python program for the given symbol. More...
|
|
auto | callFunction (string func_name,...) |
| Call the given function and return the result. More...
|
|
auto | callFunctionArgs (string func_name, *softlist< auto > argv) |
| Call the given function and return the result. More...
|
|
auto | callMethod (string class_name, string method_name,...) |
| Call the given method and return the result. More...
|
|
auto | callMethodArgs (string class_name, string method_name, *softlist< auto > argv) |
| Call the given method and return the result. More...
|
|
| constructor (string source_code, string source_label) |
| Creates the object and parses and runs the given source code. More...
|
|
| destructor () |
| Destroys the interpreter context and invalidates the object.
|
|
auto | evalExpression (string source_code, string source_label="exp") |
| Parse, compile, and evaluate the given expression and return any result. More...
|
|
auto | evalStatement (string source_code, string source_label="stmt") |
| Parse, compile, and evaluate the given statement and return any result; declarations are not persistent. More...
|
|
auto | evalStatementKeep (string source_code, string source_label="stmt") |
| Parse, compile, and evaluate the given statement and return any result; declarations are persistent. More...
|
|
| importNamespace (string qore_ns_path, string py_module_path) |
| Imports the given Qore namespace to the Python program object under the given module path. More...
|
|
auto | run () |
| Runs the program. More...
|
|
| setSaveObjectCallback (*code save_object_callback) |
| Sets the "save object" callback for Qore objects created from Python code. More...
|
|
|
static auto | evalExpression (string source_code, string source_label="exp") |
| Parse, compile, and evaluate the given expression and return any result. More...
|
|
static auto | evalStatement (string source_code, string source_label="stmt") |
| Parse, compile, and evaluate one or more Python statements and return any result. More...
|
|
static auto | evalStatementKeep (string source_code, string source_label="stmt") |
| Parse, compile, and evaluate the given code and leave declarations in the Python program object. More...
|
|
static | setSaveObjectCallback (*code save_object_callback) |
| Sets the "save object" callback for Qore objects created from Python code in the root Qore Program context. More...
|
|
Program for embedding and executing Python code.
- Restrictions:
- Qore::PO_NO_EMBEDDED_LOGIC
◆ aliasDefinition()
Python::PythonProgram::aliasDefinition |
( |
string |
python_source_path, |
|
|
string |
python_target_path |
|
) |
| |
Creates an alias in the Python program for the given symbol.
- Parameters
-
python_source_path | the dotted path to the source definition (ex: "some.path.to.sometehing" ) |
python_target_path | the dotted path to the target definition (ex: "a.different.path" ) |
- Exceptions
-
PYTHON-ALIAS-ERROR | there was an error finding the source object or creating the target |
◆ callFunction()
auto Python::PythonProgram::callFunction |
( |
string |
func_name, |
|
|
|
... |
|
) |
| |
◆ callFunctionArgs()
auto Python::PythonProgram::callFunctionArgs |
( |
string |
func_name, |
|
|
*softlist< auto > |
argv |
|
) |
| |
◆ callMethod()
auto Python::PythonProgram::callMethod |
( |
string |
class_name, |
|
|
string |
method_name, |
|
|
|
... |
|
) |
| |
◆ callMethodArgs()
auto Python::PythonProgram::callMethodArgs |
( |
string |
class_name, |
|
|
string |
method_name, |
|
|
*softlist< auto > |
argv |
|
) |
| |
◆ constructor()
Python::PythonProgram::constructor |
( |
string |
source_code, |
|
|
string |
source_label |
|
) |
| |
Creates the object and parses and runs the given source code.
- Parameters
-
source_code | the Python source to parse and compile |
source_label | the label or file name of the source; this is used as the module name for the compiled Python code as well |
- Note
- The code is executed after parsing and compiling
- Exceptions parsing, compiling, or running the Python code are thrown according to Python Exception Handling
◆ evalExpression() [1/2]
auto Python::PythonProgram::evalExpression |
( |
string |
source_code, |
|
|
string |
source_label = "exp" |
|
) |
| |
Parse, compile, and evaluate the given expression and return any result.
- Parameters
-
source_code | the Python source to parse and compile |
source_label | the label or file name of the source |
- Exceptions
-
PYTHON-COMPILE-ERROR | error parsing or compiling the given source |
- Note
- This method uses a shared static PythonProgram object to parse, compile, and evaluate the input string
◆ evalExpression() [2/2]
static auto Python::PythonProgram::evalExpression |
( |
string |
source_code, |
|
|
string |
source_label = "exp" |
|
) |
| |
|
static |
Parse, compile, and evaluate the given expression and return any result.
- Parameters
-
source_code | the Python source to parse and compile |
source_label | the label or file name of the source |
- Exceptions
-
PYTHON-COMPILE-ERROR | error parsing or compiling the given source |
- Note
- This method uses a shared static PythonProgram object to parse, compile, and evaluate the input string
◆ evalStatement() [1/2]
auto Python::PythonProgram::evalStatement |
( |
string |
source_code, |
|
|
string |
source_label = "stmt" |
|
) |
| |
Parse, compile, and evaluate the given statement and return any result; declarations are not persistent.
- Parameters
-
source_code | the Python source to parse and compile |
source_label | the label or file name of the source |
- Exceptions
-
PYTHON-COMPILE-ERROR | error parsing or compiling the given source |
- See also
- evalStatementKeep()
◆ evalStatement() [2/2]
static auto Python::PythonProgram::evalStatement |
( |
string |
source_code, |
|
|
string |
source_label = "stmt" |
|
) |
| |
|
static |
Parse, compile, and evaluate one or more Python statements and return any result.
- Parameters
-
source_code | the Python source to parse and compile |
source_label | the label or file name of the source |
- Exceptions
-
PYTHON-COMPILE-ERROR | error parsing or compiling the given source |
- Note
- This method uses the PythonProgram context in the current program to parse, compile, and evaluate the input string
- Is parsed in a "standalone" mode without being able to access existing symbols in the program
- See also
- evalStatementKeep()
◆ evalStatementKeep() [1/2]
auto Python::PythonProgram::evalStatementKeep |
( |
string |
source_code, |
|
|
string |
source_label = "stmt" |
|
) |
| |
Parse, compile, and evaluate the given statement and return any result; declarations are persistent.
- Parameters
-
source_code | the Python source to parse and compile |
source_label | the label or file name of the source |
- Exceptions
-
PYTHON-COMPILE-ERROR | error parsing or compiling the given source |
- See also
- evalStatement()
◆ evalStatementKeep() [2/2]
static auto Python::PythonProgram::evalStatementKeep |
( |
string |
source_code, |
|
|
string |
source_label = "stmt" |
|
) |
| |
|
static |
Parse, compile, and evaluate the given code and leave declarations in the Python program object.
- Parameters
-
source_code | the Python source to parse and compile |
source_label | the label or file name of the source |
- Exceptions
-
PYTHON-COMPILE-ERROR | error parsing or compiling the given source |
- Note
- This method uses the PythonProgram context in the current program to parse, compile, and evaluate the input string
- See also
- evalStatement()
◆ importNamespace()
Python::PythonProgram::importNamespace |
( |
string |
qore_ns_path, |
|
|
string |
py_module_path |
|
) |
| |
Imports the given Qore namespace to the Python program object under the given module path.
- Parameters
-
qore_ns_path | the path to the Qore namespace (ex: "::Qore::Thread" ) |
py_module_path | the dot-separated path to the target Python module to be created (ex: "qore.qore.thread" ) |
- Exceptions
-
IMPORT-NS-ERROR | Qore namespace could not be found or the root namespace was given for import |
◆ run()
auto Python::PythonProgram::run |
( |
| ) |
|
◆ setSaveObjectCallback() [1/2]
Python::PythonProgram::setSaveObjectCallback |
( |
*code |
save_object_callback | ) |
|
Sets the "save object" callback for Qore objects created from Python code.
- Restrictions:
- Qore::PO_NO_PROCESS_CONTROL
- Example:
hash<string, object> object_cache;
code callback = sub (object obj) {
object_cache{obj.uniqueHash()} = obj;
}
pypgm.setSaveObjectCallback(callback);
- Parameters
-
save_object_callback | the callback to save any Qore objects created in Python code, must take an argument of type object |
Due to the differences in garbage collection approaches between Qore and Python, Qore objects must be managed with a deterministic life cycle; JaPythona objects have only weak references to Qore objects due to the lack of destructors in Python and the lack of determinism in the Python runtime for object lifecycle management.
The callback set here will be called any time a Qore object is created from Python code; if no callback is set, then the standard thread-local implementation is used where Qore objects are saved in a thread-local hash.
- See also
- Managing the Lifecycle of Qore objects from Python for more information
◆ setSaveObjectCallback() [2/2]
static Python::PythonProgram::setSaveObjectCallback |
( |
*code |
save_object_callback | ) |
|
|
static |
Sets the "save object" callback for Qore objects created from Python code in the root Qore Program context.
- Restrictions:
- Qore::PO_NO_PROCESS_CONTROL
- Example:
hash<string, object> object_cache;
code callback = sub (object obj) {
object_cache{obj.uniqueHash()} = obj;
}
PythonProgram::setSaveObjectCallback(callback);
- Parameters
-
save_object_callback | the callback to save any Qore objects created in Python code, must take an argument of type object |
Due to the differences in garbage collection approaches between Qore and Python, Qore objects must be managed with a deterministic life cycle; JaPythona objects have only weak references to Qore objects due to the lack of destructors in Python and the lack of determinism in the Python runtime for object lifecycle management.
The callback set here will be called any time a Qore object is created from Python code; if no callback is set, then the standard thread-local implementation is used where Qore objects are saved in a thread-local hash.
- See also
- Managing the Lifecycle of Qore objects from Python for more information
The documentation for this class was generated from the following file: