本文整理汇总了Java中org.python.core.Py.NoConversion方法的典型用法代码示例。如果您正苦于以下问题:Java Py.NoConversion方法的具体用法?Java Py.NoConversion怎么用?Java Py.NoConversion使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.python.core.Py
的用法示例。
在下文中一共展示了Py.NoConversion方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getChildren
import org.python.core.Py; //导入方法依赖的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;
}
示例2: isatty
import org.python.core.Py; //导入方法依赖的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();
}
示例3: createInstance
import org.python.core.Py; //导入方法依赖的package包/类
protected static <T> T createInstance(PythonInterpreter interp, File file, Class<T> type)
throws ServletException {
Matcher m = FIND_NAME.matcher(file.getName());
if (!m.find()) {
throw new ServletException("I can't guess the name of the class from "
+ file.getAbsolutePath());
}
String name = m.group(1);
try {
interp.set("__file__", file.getAbsolutePath());
interp.execfile(file.getAbsolutePath());
PyObject cls = interp.get(name);
if (cls == null) {
throw new ServletException("No callable (class or function) named " + name + " in "
+ file.getAbsolutePath());
}
PyObject pyServlet = cls.__call__();
Object o = pyServlet.__tojava__(type);
if (o == Py.NoConversion) {
throw new ServletException("The value from " + name + " must extend "
+ type.getSimpleName());
}
@SuppressWarnings("unchecked")
T asT = (T)o;
return asT;
} catch (PyException e) {
throw new ServletException(e);
}
}
示例4: getChildren
import org.python.core.Py; //导入方法依赖的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;
}