本文整理匯總了Java中org.python.core.PyObject.__tojava__方法的典型用法代碼示例。如果您正苦於以下問題:Java PyObject.__tojava__方法的具體用法?Java PyObject.__tojava__怎麽用?Java PyObject.__tojava__使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.python.core.PyObject
的用法示例。
在下文中一共展示了PyObject.__tojava__方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: create
import org.python.core.PyObject; //導入方法依賴的package包/類
public static NifiClient create(String address, int port) {
NifiClientFactory factory = new NifiClientFactory();
PyObject clientObject = factory.nifiClientClass.__call__(new PyString(address),
new PyString(Integer.toString(port)));
return (NifiClient)clientObject.__tojava__(NifiClient.class);
}
示例2: getChildren
import org.python.core.PyObject; //導入方法依賴的package包/類
@Override
public ArrayList<PyObjectAdapter> getChildren(Object object) {
if (!(object instanceof PyDictionary))
throw new IllegalArgumentException("object is not instance of PyDictionary");
final PyDictionary pyDict = (PyDictionary)object;
PyList pyList = pyDict.keys();
int count = pyList.__len__();
ArrayList<PyObjectAdapter> list = new ArrayList<PyObjectAdapter>(count);
PyObject obj;
for (int i = 0; i < count; ++i){
final PyObject pyKey = pyList.__getitem__(i);
Object name = pyKey.__tojava__(String.class);
if ((name == Py.NoConversion) || (!(name instanceof String))) continue;
obj = pyDict.__finditem__(pyKey);
list.add(
new PyObjectAdapter(
(String)name,
new PyObjectPlace(){
private PyObject myPlace = pyKey;
@Override
public void set(PyObject newValue) {
pyDict.__setitem__(myPlace, newValue);
}
@Override
public PyObject get(){
try{
return pyDict.__finditem__(myPlace);
} catch (Exception e){
return null;
}
}
}
)
);
}
return list;
}
示例3: isatty
import org.python.core.PyObject; //導入方法依賴的package包/類
public static boolean isatty(PyObject fdObj) {
if (fdObj instanceof PyInteger) {
FileDescriptor fd;
switch (fdObj.asInt()) {
case 0:
fd = FileDescriptor.in;
break;
case 1:
fd = FileDescriptor.out;
break;
case 2:
fd = FileDescriptor.err;
break;
default:
throw Py.NotImplementedError("Integer file descriptor compatibility only "
+ "available for stdin, stdout and stderr (0-2)");
}
return posix.isatty(fd);
}
Object tojava = fdObj.__tojava__(FileDescriptor.class);
if (tojava != Py.NoConversion) {
return posix.isatty((FileDescriptor)tojava);
}
tojava = fdObj.__tojava__(IOBase.class);
if (tojava == Py.NoConversion) {
throw Py.TypeError("a file descriptor is required");
}
return ((IOBase)tojava).isatty();
}
示例4: getString
import org.python.core.PyObject; //導入方法依賴的package包/類
public String getString(String name, String def) {
PyObject value = this.args.get(name);
if(value == null) {
return def;
}
return (String)value.__tojava__(String.class);
}
示例5: getChildren
import org.python.core.PyObject; //導入方法依賴的package包/類
@Override
public ArrayList<PyObjectAdapter> getChildren(Object object) {
if (!(object instanceof PyInstance))
throw new IllegalArgumentException("object is not instance of PyInstance");
PyInstance pyInstance = (PyInstance)object;
PyList keys = null;
if (pyInstance.__dict__ instanceof PyDictionary)
keys = ((PyDictionary)pyInstance.__dict__).keys();
if (pyInstance.__dict__ instanceof PyStringMap)
keys = ((PyStringMap)pyInstance.__dict__).keys();
if (keys == null)
return null;
final PyObject pyDict = pyInstance.__dict__;
int count = keys.__len__();
ArrayList<PyObjectAdapter> list = new ArrayList<PyObjectAdapter>(count);
PyObject obj;
for (int i = 0; i < count; ++i){
final PyObject key = keys.__getitem__(i);
Object name = (String)key.__tojava__(String.class);
if ((name == Py.NoConversion) || (!(name instanceof String))) continue;
obj = pyDict.__finditem__(key);
list.add(
new PyObjectAdapter(
(String)name,
new PyObjectPlace(){
private PyObject myPlace = key;
@Override
public void set(PyObject newValue) {
pyDict.__setitem__(myPlace, newValue);
}
@Override
public PyObject get(){
try{
return pyDict.__finditem__(myPlace);
} catch (Exception e){
return null;
}
}
}
)
);
}
return list;
}
示例6: getScriptedObject
import org.python.core.PyObject; //導入方法依賴的package包/類
/** {@inheritDoc} */
public Object getScriptedObject(ScriptSource scriptSourceLocator, Class<?>... scriptInterfaces) throws IOException, ScriptCompilationException {
String basePath = "";
/* TODO: how to do this when running under Tomcat?
ContextHandler handler = WebAppContext.getCurrentWebAppContext();
if (handler != null) {
File root = handler.getBaseResource().getFile();
if (root != null && root.exists()) {
basePath = root.getAbsolutePath() + File.separator + "WEB-INF" + File.separator;
}
}
*/
String strScript = scriptSourceLocator.getScriptAsString();
if (scriptInterfaces.length > 0) {
try {
PySystemState state = new PySystemState();
if (!"".equals(basePath)) {
// Add webapp paths that can contain classes and .jar files to python search path
state.path.insert(0, Py.newString(basePath + "classes"));
File jarRoot = new File(basePath + "lib");
if (jarRoot.exists()) {
for (String filename : jarRoot.list(new FilenameFilter() {
public boolean accept(File dir, String name) {
return (name.endsWith(".jar"));
}
})) {
state.path.insert(1, Py.newString(basePath + "lib" + File.separator + filename));
}
}
}
@SuppressWarnings("resource")
PythonInterpreter interp = new PythonInterpreter(null, state);
interp.exec(strScript);
PyObject getInstance = interp.get("getInstance");
if (!(getInstance instanceof PyFunction)) {
throw new ScriptCompilationException("\"getInstance\" is not a function.");
}
PyObject _this;
if (arguments == null) {
_this = ((PyFunction) getInstance).__call__();
} else {
PyObject[] args = new PyObject[arguments.length];
for (int i = 0; i < arguments.length; i++) {
args[i] = PyJavaType.wrapJavaObject(arguments[i]);
}
_this = ((PyFunction) getInstance).__call__(args);
}
return _this.__tojava__(scriptInterfaces[0]);
} catch (Exception ex) {
logger.error("Error while loading script.", ex);
if (ex instanceof IOException) {
// Raise to caller
throw (IOException) ex;
} else if (ex instanceof ScriptCompilationException) {
// Raise to caller
throw (ScriptCompilationException) ex;
}
throw new ScriptCompilationException(ex.getMessage());
}
}
logger.error("No scriptInterfaces provided.");
return null;
}