PythonScript

class PythonScript(nullGlobalContext: Boolean = false) : AbstractScript

A script engine wrapper for dynamically evaluating Python source code using the Jython engine.

Variables are bound directly to the engine without type parameter support, since Python is dynamically typed.

Code is checked before it runs, on a best-effort basis: literal JVM-termination calls and Python's sys.exit(), exit(), quit(), and raise SystemExit are rejected. The checks match text, including inside string literals and comments, and they are not a security sandbox; see PythonGuards for what they do and do not catch. Run untrusted scripts in an isolated process or JVM. Method calls and definitions such as obj.exit() and def exit(self): are allowed.

Parameters

nullGlobalContext

if true, sets the global scope bindings to null on initialization

See also

Constructors

Link copied to clipboard
constructor(nullGlobalContext: Boolean = false)

Properties

Link copied to clipboard

Functions

Link copied to clipboard
open override fun add(name: String, value: Any, vararg types: KType)

Adds a named variable to the script context.

Link copied to clipboard
open override fun close()
Link copied to clipboard

Evaluates Python code and returns its result.

Link copied to clipboard
open fun params(name: String, types: Array<out KType>): String
Link copied to clipboard
fun resetContext(nullGlobalContext: Boolean)
Link copied to clipboard
open fun resetForReuse(nullGlobalContext: Boolean)