Package com.illumon.iris.db.util
Class PythonScopeJpyImpl
java.lang.Object
com.illumon.iris.db.util.PythonScopeJpyImpl
- All Implemented Interfaces:
PythonScope<org.jpy.PyObject>
public class PythonScopeJpyImpl extends Object implements PythonScope<org.jpy.PyObject>
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
PythonScopeJpyImpl.CallableWrapper
When given a pyObject that is a callable, we stick it inside the callable wrapper, which implements a call() varargs method, so that we can call it using __call__ without all of the JPy nastiness. -
Constructor Summary
Constructors Constructor Description PythonScopeJpyImpl(org.jpy.PyDictWrapper dict)
-
Method Summary
Modifier and Type Method Description boolean
containsKey(String name)
Finds out if a variable is in scopestatic Object
convert(org.jpy.PyObject pyObject)
Converts a pyObject into an appropriate Java object for use outside of JPy.String
convertStringKey(org.jpy.PyObject key)
The helper method to turn a raw key into a string key.Object
convertValue(org.jpy.PyObject value)
The helper method to turn a raw value into an implementation specific object.Stream<Map.Entry<org.jpy.PyObject,org.jpy.PyObject>>
getEntriesRaw()
Retrieves all keys and values from the given scope.Stream<org.jpy.PyObject>
getKeysRaw()
Retrieves all keys from the give scope.Optional<org.jpy.PyObject>
getValueRaw(String name)
Retrieves a value from the given scope.org.jpy.PyDictWrapper
globals()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.illumon.iris.db.util.PythonScope
getEntries, getEntriesMap, getKeys, getKeysCollection, getValue, getValue, getValueUnchecked
-
Constructor Details
-
PythonScopeJpyImpl
public PythonScopeJpyImpl(org.jpy.PyDictWrapper dict)
-
-
Method Details
-
getValueRaw
Description copied from interface:PythonScope
Retrieves a value from the given scope.No conversion is done.
- Specified by:
getValueRaw
in interfacePythonScope<org.jpy.PyObject>
- Parameters:
name
- the name of the python variable- Returns:
- the value, or empty
-
getKeysRaw
Description copied from interface:PythonScope
Retrieves all keys from the give scope.No conversion is done.
Technically, the keys can be tuples...
- Specified by:
getKeysRaw
in interfacePythonScope<org.jpy.PyObject>
- Returns:
- the keys
-
getEntriesRaw
Description copied from interface:PythonScope
Retrieves all keys and values from the given scope.No conversion is done.
- Specified by:
getEntriesRaw
in interfacePythonScope<org.jpy.PyObject>
- Returns:
- the keys and values
-
containsKey
Description copied from interface:PythonScope
Finds out if a variable is in scope- Specified by:
containsKey
in interfacePythonScope<org.jpy.PyObject>
- Parameters:
name
- the name of the python variable- Returns:
- true iff the scope contains the variable
-
convertStringKey
Description copied from interface:PythonScope
The helper method to turn a raw key into a string key.Note: this assumes that all the keys are strings, which is not always true. Keys can also be tuples. TODO: revise interface as appropriate if this becomes an issue.
- Specified by:
convertStringKey
in interfacePythonScope<org.jpy.PyObject>
- Parameters:
key
- the raw key- Returns:
- the string key
-
convertValue
Description copied from interface:PythonScope
The helper method to turn a raw value into an implementation specific object.This method should NOT convert PyObj of None type to null - we need to preserve the None object so it works with other Optional return values.
- Specified by:
convertValue
in interfacePythonScope<org.jpy.PyObject>
- Parameters:
value
- the raw value- Returns:
- the converted object value
-
convert
Converts a pyObject into an appropriate Java object for use outside of JPy.If we're a List, Dictionary, or Callable, then we wrap them in a java object.
If it is a primitive (or a wrapped Java object); we convert it to the java object.
Otherwise we return the raw PyObject and the user can do with it what they will.
- Parameters:
pyObject
- the JPy wrapped PyObject.- Returns:
- a Java object representing the underlying JPy object.
-
globals
public org.jpy.PyDictWrapper globals()- Specified by:
globals
in interfacePythonScope<org.jpy.PyObject>
-