Top Inners Fields Constructors Methods
org.python.jsr223

public Class PyScriptEngine

extends AbstractScriptEngine
implements Compilable, Invocable, AutoCloseable
Class Inheritance
All Implemented Interfaces
java.lang.AutoCloseable, javax.script.Invocable, javax.script.Compilable
Imports
java.lang.reflect.Method, .InvocationHandler, .Proxy, org.python.core.*, java.io.Reader, javax.script.AbstractScriptEngine, .Bindings, .Compilable, .CompiledScript, .Invocable, .ScriptContext, .ScriptEngine, .ScriptEngineFactory, .ScriptException, .SimpleBindings, org.python.util.PythonInterpreter

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class

Field Summary

Modifier and TypeField and Description
private final ScriptEngineFactory
private final PythonInterpreter
Inherited from javax.script.AbstractScriptEngine:
context

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
close()

Implements java.lang.AutoCloseable.close.

Closes this resource, relinquishing any underlying resources.

public CompiledScript
compile(String
The source of the script, represented as a String.
script
)

Implements javax.script.Compilable.compile.

Compiles the script (source represented as a String) for later execution.

public CompiledScript
compile(Reader
The reader from which the script source is obtained.
reader
)

Implements javax.script.Compilable.compile.

Compiles the script (source read from Reader) for later execution.

private PyCode
private PyCode
public Bindings
createBindings()

Implements javax.script.ScriptEngine.createBindings.

Returns an uninitialized Bindings.

public Object
eval(String
The script to be executed by the script engine.
script
,
ScriptContext
A ScriptContext exposing sets of attributes in different scopes. The meanings of the scopes ScriptContext.GLOBAL_SCOPE, and ScriptContext.ENGINE_SCOPE are defined in the specification.

The ENGINE_SCOPE Bindings of the ScriptContext contains the bindings of scripting variables to application objects to be used during this script execution.
context
)

Implements javax.script.ScriptEngine.eval.

Causes the immediate execution of the script whose source is the String passed as the first argument.

private Object
eval(PyCode code, ScriptContext context)

public Object
eval(Reader
The source of the script to be executed by the script engine.
reader
,
ScriptContext
The ScriptContext passed to the script engine.
context
)

Implements javax.script.ScriptEngine.eval.

Same as eval(String, ScriptContext) where the source of the script is read from a Reader.

public ScriptEngineFactory
getFactory()

Implements javax.script.ScriptEngine.getFactory.

Returns a ScriptEngineFactory for the class to which this ScriptEngine belongs.

public <T> T
getInterface(Class<T>
The Class object of the interface to return.
clazz
)

Implements javax.script.Invocable.getInterface.

Returns an implementation of an interface using functions compiled in the interpreter.

public <T> T
getInterface(Object
The scripting object whose member functions are used to implement the methods of the interface.
obj
,
Class<T>
The Class object of the interface to return.
clazz
)

Implements javax.script.Invocable.getInterface.

Returns an implementation of an interface using member functions of a scripting object compiled in the interpreter.

public Object
invokeFunction(String
of the procedure or function to call
name
,
Object...
Arguments to pass to the procedure or function
args
)

Implements javax.script.Invocable.invokeFunction.

Used to call top-level procedures and functions defined in scripts.

public Object
invokeMethod(Object
If the procedure is a member of a class defined in the script and thiz is an instance of that class returned by a previous execution or invocation, the named method is called through that instance.
thiz
,
String
The name of the procedure to be called.
name
,
Object...
Arguments to pass to the procedure. The rules for converting the arguments to scripting variables are implementation-specific.
args
)

Implements javax.script.Invocable.invokeMethod.

Calls a method on a script object compiled during a previous script execution, which is retained in the state of the ScriptEngine.

private static ScriptException
Inherited from javax.script.AbstractScriptEngine:
evalevalevalevalgetgetBindingsgetContextgetScriptContextputsetBindingssetContext

Field Detail

factoryback to summary
private final ScriptEngineFactory factory
interpback to summary
private final PythonInterpreter interp

Constructor Detail

PyScriptEngineback to summary
pack-priv PyScriptEngine(ScriptEngineFactory factory)

Method Detail

closeback to summary
public void close()

Implements java.lang.AutoCloseable.close.

Doc from java.lang.AutoCloseable.close.

Closes this resource, relinquishing any underlying resources. This method is invoked automatically on objects managed by the try-with-resources statement.

compileback to summary
public CompiledScript compile(String script) throws ScriptException

Implements javax.script.Compilable.compile.

Doc from javax.script.Compilable.compile.

Compiles the script (source represented as a String) for later execution.

Parameters
script:String

The source of the script, represented as a String.

Returns:CompiledScript

An instance of a subclass of CompiledScript to be executed later using one of the eval methods of CompiledScript.

Exceptions
ScriptException:
if compilation fails.

compileback to summary
public CompiledScript compile(Reader reader) throws ScriptException

Implements javax.script.Compilable.compile.

Doc from javax.script.Compilable.compile.

Compiles the script (source read from Reader) for later execution. Functionality is identical to compile(String) other than the way in which the source is passed.

Parameters
reader:Reader

The reader from which the script source is obtained.

Returns:CompiledScript

An instance of a subclass of CompiledScript to be executed later using one of its eval methods of CompiledScript.

Exceptions
ScriptException:
if compilation fails.

compileScriptback to summary
private PyCode compileScript(String script, ScriptContext context) throws ScriptException
compileScriptback to summary
private PyCode compileScript(Reader reader, ScriptContext context) throws ScriptException
createBindingsback to summary
public Bindings createBindings()

Implements javax.script.ScriptEngine.createBindings.

Doc from javax.script.ScriptEngine.createBindings.

Returns an uninitialized Bindings.

Returns:Bindings

A Bindings that can be used to replace the state of this ScriptEngine.

evalback to summary
public Object eval(String script, ScriptContext context) throws ScriptException

Implements javax.script.ScriptEngine.eval.

Doc from javax.script.ScriptEngine.eval.

Causes the immediate execution of the script whose source is the String passed as the first argument. The script may be reparsed or recompiled before execution. State left in the engine from previous executions, including variable values and compiled procedures may be visible during this execution.

Parameters
script:String

The script to be executed by the script engine.

context:ScriptContext

A ScriptContext exposing sets of attributes in different scopes. The meanings of the scopes ScriptContext.GLOBAL_SCOPE, and ScriptContext.ENGINE_SCOPE are defined in the specification.

The ENGINE_SCOPE Bindings of the ScriptContext contains the bindings of scripting variables to application objects to be used during this script execution.

Returns:Object

The value returned from the execution of the script.

Exceptions
ScriptException:
if an error occurs in script. ScriptEngines should create and throw ScriptException wrappers for checked Exceptions thrown by underlying scripting implementations.

evalback to summary
private Object eval(PyCode code, ScriptContext context) throws ScriptException
evalback to summary
public Object eval(Reader reader, ScriptContext context) throws ScriptException

Implements javax.script.ScriptEngine.eval.

Doc from javax.script.ScriptEngine.eval.

Same as eval(String, ScriptContext) where the source of the script is read from a Reader.

Parameters
reader:Reader

The source of the script to be executed by the script engine.

context:ScriptContext

The ScriptContext passed to the script engine.

Returns:Object

The value returned from the execution of the script.

Exceptions
ScriptException:
if an error occurs in script. ScriptEngines should create and throw ScriptException wrappers for checked Exceptions thrown by underlying scripting implementations.

getFactoryback to summary
public ScriptEngineFactory getFactory()

Implements javax.script.ScriptEngine.getFactory.

Doc from javax.script.ScriptEngine.getFactory.

Returns a ScriptEngineFactory for the class to which this ScriptEngine belongs.

Returns:ScriptEngineFactory

The ScriptEngineFactory

getInterfaceback to summary
public <T> T getInterface(Class<T> clazz)

Implements javax.script.Invocable.getInterface.

Doc from javax.script.Invocable.getInterface.

Returns an implementation of an interface using functions compiled in the interpreter. The methods of the interface may be implemented using the invokeFunction method.

Parameters
<T>
the type of the interface to return
clazz:Class<T>

The Class object of the interface to return.

Returns:T

An instance of requested interface - null if the requested interface is unavailable, i. e. if compiled functions in the ScriptEngine cannot be found matching the ones in the requested interface.

getInterfaceback to summary
public <T> T getInterface(Object obj, Class<T> clazz)

Implements javax.script.Invocable.getInterface.

Doc from javax.script.Invocable.getInterface.

Returns an implementation of an interface using member functions of a scripting object compiled in the interpreter. The methods of the interface may be implemented using the invokeMethod method.

Parameters
<T>
the type of the interface to return
obj:Object

The scripting object whose member functions are used to implement the methods of the interface.

clazz:Class<T>

The Class object of the interface to return.

Returns:T

An instance of requested interface - null if the requested interface is unavailable, i. e. if compiled methods in the ScriptEngine cannot be found matching the ones in the requested interface.

invokeFunctionback to summary
public Object invokeFunction(String name, Object... args) throws ScriptException, NoSuchMethodException

Implements javax.script.Invocable.invokeFunction.

Doc from javax.script.Invocable.invokeFunction.

Used to call top-level procedures and functions defined in scripts.

Parameters
name:String

of the procedure or function to call

args:Object[]

Arguments to pass to the procedure or function

Returns:Object

The value returned by the procedure or function

Exceptions
ScriptException:
if an error occurs during invocation of the method.
NoSuchMethodException:
if method with given name or matching argument types cannot be found.

invokeMethodback to summary
public Object invokeMethod(Object thiz, String name, Object... args) throws ScriptException, NoSuchMethodException

Implements javax.script.Invocable.invokeMethod.

Doc from javax.script.Invocable.invokeMethod.

Calls a method on a script object compiled during a previous script execution, which is retained in the state of the ScriptEngine.

Parameters
thiz:Object

If the procedure is a member of a class defined in the script and thiz is an instance of that class returned by a previous execution or invocation, the named method is called through that instance.

name:String

The name of the procedure to be called.

args:Object[]

Arguments to pass to the procedure. The rules for converting the arguments to scripting variables are implementation-specific.

Returns:Object

The value returned by the procedure. The rules for converting the scripting variable returned by the script method to a Java Object are implementation-specific.

Exceptions
ScriptException:
if an error occurs during invocation of the method.
NoSuchMethodException:
if method with given name or matching argument types cannot be found.

scriptExceptionback to summary
private static ScriptException scriptException(PyException pye)
org.python.jsr223 back to summary

private Class PyScriptEngine.PyCompiledScript

extends CompiledScript
Class Inheritance

Field Summary

Modifier and TypeField and Description
private PyCode

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public Object
eval(ScriptContext
A ScriptContext that is used in the same way as the ScriptContext passed to the eval methods of ScriptEngine.
ctx
)

Implements abstract javax.script.CompiledScript.eval.

Executes the program stored in this CompiledScript object.

public ScriptEngine
getEngine()

Implements abstract javax.script.CompiledScript.getEngine.

Returns the ScriptEngine whose compile method created this CompiledScript.

Inherited from javax.script.CompiledScript:
evaleval

Field Detail

codeback to summary
private PyCode code

Constructor Detail

PyCompiledScriptback to summary
pack-priv PyCompiledScript(PyCode code)

Method Detail

evalback to summary
public Object eval(ScriptContext ctx) throws ScriptException

Implements abstract javax.script.CompiledScript.eval.

Doc from javax.script.CompiledScript.eval.

Executes the program stored in this CompiledScript object.

Parameters
ctx:ScriptContext

A ScriptContext that is used in the same way as the ScriptContext passed to the eval methods of ScriptEngine.

Returns:Object

The value returned by the script execution, if any. Should return null if no value is returned by the script execution.

Annotations
@Override
Exceptions
ScriptException:
if an error occurs.

getEngineback to summary
public ScriptEngine getEngine()

Implements abstract javax.script.CompiledScript.getEngine.

Doc from javax.script.CompiledScript.getEngine.

Returns the ScriptEngine whose compile method created this CompiledScript. The CompiledScript will execute in this engine.

Returns:ScriptEngine

The ScriptEngine that created this CompiledScript

Annotations
@Override