public class PyObject extends Object implements AutoCloseable
PyObject*
) in the Python interpreter.Modifier and Type | Method and Description |
---|---|
PyDictWrapper |
asDict() |
List<PyObject> |
asList() |
<T> T |
call(Class<T> returnType,
String name,
Class<?>[] paramTypes,
Object[] args) |
<T,A0> T |
call(Class<T> returnType,
String name,
Class<A0> clazz0,
A0 arg0) |
<T,A0,A1> T |
call(Class<T> returnType,
String name,
Class<A0> clazz0,
A0 arg0,
Class<A1> clazz1,
A1 arg1) |
<T,A0,A1,A2> |
call(Class<T> returnType,
String name,
Class<A0> clazz0,
A0 arg0,
Class<A1> clazz1,
A1 arg1,
Class<A2> clazz2,
A2 arg2) |
PyObject |
call(String name,
Object... args)
Call the callable Python object with the given name and arguments.
|
PyObject |
callMethod(String name,
Object... args)
Call the callable Python method with the given name and arguments.
|
static int |
cleanup() |
void |
close()
Decreases the reference count of
this on first invocation. |
<T> T |
createProxy(Class<T> type)
Create a Java proxy instance of this Python object which contains compatible methods to the ones provided in the
interface given by the
type parameter. |
Object |
createProxy(PyLib.CallableKind callableKind,
Class<?>... types)
Create a Java proxy instance of this Python object (or module) which contains compatible methods
(or functions) to the ones provided in the interfaces given by all the
type parameters. |
void |
delAttribute(String name)
Deletes the value of a Python attribute.
|
boolean |
eq(Object other) |
boolean |
equals(Object o)
Indicates whether some other object is "equal to" this one.
|
static PyObject |
executeCode(String code,
PyInputMode mode)
Executes Python source code.
|
static PyObject |
executeCode(String code,
PyInputMode mode,
Object globals,
Object locals)
Executes Python source code in the context specified by the
globals and locals maps. |
static PyObject |
executeScript(String script,
PyInputMode mode)
Executes Python source script.
|
static PyObject |
executeScript(String script,
PyInputMode mode,
Object globals,
Object locals)
Executes Python source script in the context specified by the
globals and locals maps. |
PyObject |
getAttribute(String name)
Gets the Python value of a Python attribute.
|
<T> T |
getAttribute(String name,
Class<? extends T> valueType)
Gets the value of a Python attribute as Java object of a given type.
|
boolean |
getBooleanValue() |
double |
getDoubleValue() |
int |
getIntValue() |
long |
getLongValue() |
<T> T[] |
getObjectArrayValue(Class<? extends T> itemType)
Gets this Python object as Java
Object[] value of the given item type. |
Object |
getObjectValue()
Gets this Python object as Java
Object value. |
long |
getPointer() |
String |
getStringValue() |
PyObject |
getType()
Gets the Python type object for this wrapped object.
|
boolean |
hasAttribute(String name)
Checks for the existence of a Python attribute..
|
long |
hash()
Runs the python hash function on this object.
|
int |
hashCode()
Computes a hash code from this object's pointer value.
|
boolean |
isBoolean() |
boolean |
isCallable() |
boolean |
isConvertible() |
boolean |
isDict() |
boolean |
isFloat() |
boolean |
isFunction() |
boolean |
isInt() |
boolean |
isList() |
boolean |
isLong() |
boolean |
isModule() |
boolean |
isNone() |
boolean |
isString() |
boolean |
isTuple() |
String |
repr()
Gets a the python repr of this object
|
<T> void |
setAttribute(String name,
T value)
Sets the value of a Python attribute from the given Java object.
|
<T> void |
setAttribute(String name,
T value,
Class<? extends T> valueType)
Sets the value of a Python attribute from the given Java object and Java type (if given).
|
String |
str()
Runs the python str function on this object.
|
String |
toString()
Gets the python string representation of this object.
|
static PyObject |
unwrapProxy(Object object)
Unwraps the original Python object used to create
object . |
public static int cleanup()
public final void close()
this
on first invocation.close
in interface AutoCloseable
public static PyObject executeCode(String code, PyInputMode mode)
code
- The Python source code.mode
- The execution mode.public static PyObject executeScript(String script, PyInputMode mode) throws FileNotFoundException
script
- The Python source script.mode
- The execution mode.FileNotFoundException
public static PyObject executeCode(String code, PyInputMode mode, Object globals, Object locals)
globals
and locals
maps.
If a Java value in the globals
and locals
maps cannot be directly converted into a Python object, a Java wrapper will be created instead.
If a Java value is a wrapped Python object of type PyObject
, it will be unwrapped.
code
- The Python source code.mode
- The execution mode.globals
- The global variables to be set, or null
.locals
- The locals variables to be set, or null
.public static PyObject executeScript(String script, PyInputMode mode, Object globals, Object locals) throws FileNotFoundException
globals
and locals
maps.
If a Java value in the globals
and locals
maps cannot be directly converted into a Python object, a Java wrapper will be created instead.
If a Java value is a wrapped Python object of type PyObject
, it will be unwrapped.
script
- The Python source script.mode
- The execution mode.globals
- The global variables to be set, or null
.locals
- The locals variables to be set, or null
.FileNotFoundException
- if the script file is not foundpublic final long getPointer()
public int getIntValue()
int
value.public long getLongValue()
long
value.public boolean getBooleanValue()
boolean
value.public double getDoubleValue()
double
value.public String getStringValue()
String
value.public Object getObjectValue()
Object
value.
If this Python object cannot be converted into a Java object, a Java wrapper of type PyObject
will be returned.
If this Python object is a wrapped Java object, it will be unwrapped.
Object
value.public PyObject getType()
PyObject
wrapped value.public boolean isDict()
public boolean isList()
public boolean isBoolean()
public boolean isLong()
public boolean isInt()
public boolean isNone()
public boolean isFloat()
public boolean isCallable()
public boolean isFunction()
public boolean isModule()
public boolean isTuple()
public boolean isString()
public boolean isConvertible()
public PyDictWrapper asDict()
public <T> T[] getObjectArrayValue(Class<? extends T> itemType)
Object[]
value of the given item type.
Appropriate type conversions from Python to Java will be performed as needed.
If a Python item value cannot be converted into a Java item object, a Java wrapper of type PyObject
will be returned.
If a Python item value is a wrapped Java object, it will be unwrapped.
If this Python object value is a wrapped Java array object of given type, it will be unwrapped.
T
- The expected item type name.itemType
- The expected item type class.Object[]
value.public PyObject getAttribute(String name)
If the Python value cannot be converted into a Java object, a Java wrapper of type PyObject
will be returned.
If the Python value is a wrapped Java object, it will be unwrapped.
name
- A name of the Python attribute.public <T> T getAttribute(String name, Class<? extends T> valueType)
If the Python value cannot be converted into a Java object, a Java wrapper of type PyObject
will be returned.
If the Python value is a wrapped Java object, it will be unwrapped.
T
- The expected value type name.name
- A name of the Python attribute.valueType
- The type of the value or null
, if unknown.public <T> void setAttribute(String name, T value)
If the Java value
cannot be directly converted into a Python object, a Java wrapper will be created instead.
If the Java value
is a wrapped Python object of type PyObject
, it will be unwrapped.
T
- The value type name.name
- A name of the Python attribute.value
- The new attribute value as Java object. May be null
.public void delAttribute(String name)
name
- the name of the Python attribute.public boolean hasAttribute(String name)
name
- the name of the Python attribute.public <T> void setAttribute(String name, T value, Class<? extends T> valueType)
If the Java value
cannot be directly converted into a Python object, a Java wrapper will be created instead.
If the Java value
is a wrapped Python object of type PyObject
, it will be unwrapped.
T
- The value type name.name
- A name of the Python attribute.value
- The new attribute value as Java object.valueType
- The value type used for the conversion. May be null
.public PyObject callMethod(String name, Object... args)
If a Java value in args
cannot be directly converted into a Python object, a Java wrapper will be created instead.
If the Java value in args
is a wrapped Python object of type PyObject
, it will be unwrapped.
name
- A name of a Python attribute that evaluates to a callable object.args
- The arguments for the method call.public PyObject call(String name, Object... args)
If a Java value in args
cannot be directly converted into a Python object, a Java wrapper will be created instead.
If the Java value in args
is a wrapped Python object of type PyObject
, it will be unwrapped.
name
- A name of a Python attribute that evaluates to a callable object,args
- The arguments for the call.public <T,A0,A1> T call(Class<T> returnType, String name, Class<A0> clazz0, A0 arg0, Class<A1> clazz1, A1 arg1)
public <T,A0,A1,A2> T call(Class<T> returnType, String name, Class<A0> clazz0, A0 arg0, Class<A1> clazz1, A1 arg1, Class<A2> clazz2, A2 arg2)
public <T> T createProxy(Class<T> type)
type
parameter.T
- The interface name.type
- The interface class.public Object createProxy(PyLib.CallableKind callableKind, Class<?>... types)
type
parameters.callableKind
- The kind of calls to be made.types
- The interface types.public static PyObject unwrapProxy(Object object)
object
. The inverse of
createProxy(Class)
.object
- The object that may be a proxy.public final String toString()
toString
in class Object
getPointer()
public final String repr()
getPointer()
public final String str()
public final long hash()
public final boolean eq(Object other)
public final boolean equals(Object o)
equals
in class Object
o
- The other object.true
if the other object is an instance of PyObject
and if their pointers are equal, false
otherwise.getPointer()
public final int hashCode()
hashCode
in class Object
getPointer()
Copyright © 2014–2022 Brockmann Consult GmbH. All rights reserved.