當前位置: 首頁>>代碼示例>>Java>>正文


Java Py.NoConversion方法代碼示例

本文整理匯總了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;
}
 
開發者ID:kefik,項目名稱:Pogamut3,代碼行數:38,代碼來源:PyDictionaryWrapper.java

示例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();
}
 
開發者ID:RunasSudo,項目名稱:PyAndroid,代碼行數:32,代碼來源:PosixModule.java

示例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);
    }
}
 
開發者ID:quickbundle,項目名稱:qb-archetype,代碼行數:30,代碼來源:RmPyServlet.java

示例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;
}
 
開發者ID:kefik,項目名稱:Pogamut3,代碼行數:45,代碼來源:PyInstanceWrapper.java


注:本文中的org.python.core.Py.NoConversion方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。