Provide a utility class CodeRunner for use by handlers that execute Python source code.
CodeRunner
Compile and run Python source code.
__init__
source (str) – A string containing Python source code to execute
path (str) – A filename to use in any debugging or error output
argv (list[str]) – A list of string arguments to make available as sys.argv when the code executes
sys.argv
package (bool) – An optional package module to configure
ValueError, if package is specified for an __init__.py –
new_module
Make a fresh module to run in.
Module
reset_run_errors
Clears any transient error conditions from a previous run.
None
run
Execute the configured source code in a module and run any post checks.
module (Module) – A module to execute the configured code in.
post_check (callable, optional) – A function that raises an exception if expected post-conditions are not met after code execution.
error
If code execution fails, may contain a related error message.
error_detail
If code execution fails, may contain a traceback or other details.
failed
True if code execution failed
True
path
The path that new modules will be configured with.
source
The configured source code that will be executed when run is called.