当前位置: 首页>>代码示例>>Java>>正文


Java PyObject类代码示例

本文整理汇总了Java中org.python.core.PyObject的典型用法代码示例。如果您正苦于以下问题:Java PyObject类的具体用法?Java PyObject怎么用?Java PyObject使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


PyObject类属于org.python.core包,在下文中一共展示了PyObject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getJavaObject

import org.python.core.PyObject; //导入依赖的package包/类
@Override
public Object getJavaObject(Object pyObject) {
	if (!(pyObject instanceof PyList)) 
		throw new IllegalArgumentException("pyObject is not instance of PyList");
	PyList pyList = (PyList) pyObject;
	int count = (pyList.__len__());
	ArrayList list = new ArrayList(count);
	PyObject obj = null;
	PyObjectWrapper wrapper = null;
	for (int i = 0; i < count; ++i){
		obj = pyList.__getitem__(i);
		wrapper = PyObjectWrappersManager.getWrapper(obj.getClass());
		list.add(wrapper.getJavaObject(obj));
	}
	return list;
}
 
开发者ID:kefik,项目名称:Pogamut3,代码行数:17,代码来源:PyListWrapper.java

示例2: getNewValue

import org.python.core.PyObject; //导入依赖的package包/类
/**
 * Accepts Collection<PyObject> as parameter of newValue.
 * Returns PyList
 */
@Override
public PyObject getNewValue(Object newValue) {
	if (!(newValue instanceof Collection)){
		throw new IllegalArgumentException();
	} 
	Collection collection = (Collection)newValue;
	PyList list = new PyList();
	Iterator iter = collection.iterator();
	while (iter.hasNext()){
		Object next = iter.next();
		if (!(next instanceof PyObject))
			throw new IllegalArgumentException("value of the collection is not instance of PyObject");
		 list.__add__((PyObject) next);
	}		
	return list;
}
 
开发者ID:kefik,项目名称:Pogamut3,代码行数:21,代码来源:PyListWrapper.java

示例3: getJavaObject

import org.python.core.PyObject; //导入依赖的package包/类
@Override
public Object getJavaObject(Object pyObject) {
	if (!(pyObject instanceof PyTuple)) 
		throw new IllegalArgumentException("pyObject is not instance of PyTuple");
	PyTuple pyTuple = (PyTuple) pyObject;
	int count = (pyTuple.__len__());
	ArrayList list = new ArrayList(count);
	PyObject obj = null;
	PyObjectWrapper wrapper = null;
	for (int i = 0; i < count; ++i){
		obj = pyTuple.__getitem__(i);
		wrapper = PyObjectWrappersManager.getWrapper(obj.getClass());
		list.add(wrapper.getJavaObject(obj));
	}
	return list;
}
 
开发者ID:kefik,项目名称:Pogamut3,代码行数:17,代码来源:PyTupleWrapper.java

示例4: getJavaObject

import org.python.core.PyObject; //导入依赖的package包/类
@Override
public Object getJavaObject(Object pyObject) {
	if (!(pyObject instanceof PyDictionary)) 
		throw new IllegalArgumentException("pyObject is not instance of PyDictionary");
	final PyDictionary pyDict = (PyDictionary)pyObject;
	Map map = new HashMap();
	PyList keys = pyDict.keys();
	int count = keys.__len__();		
	PyObject pyKey, pyValue;
	Object javaKey, javaValue;
	for (int i = 0; i < count; ++i){
		pyKey = keys.__getitem__(i);
		javaKey = PyObjectWrappersManager.getWrapper(pyKey.getClass()).getJavaObject(pyKey);
		pyValue = pyDict.__getitem__(pyKey);
		javaValue = PyObjectWrappersManager.getWrapper(pyValue.getClass()).getJavaObject(pyValue);
		map.put(javaKey, javaValue);
	}
	return map;
}
 
开发者ID:kefik,项目名称:Pogamut3,代码行数:20,代码来源:PyDictionaryWrapper.java

示例5: getNewValue

import org.python.core.PyObject; //导入依赖的package包/类
/**
 * Accepts Map<String, PyObject> as newValue.
 */
@Override
public PyObject getNewValue(Object newValue) {
	if (!(newValue instanceof Map)){
		throw new IllegalArgumentException("newValue not of type Map");			
	}
	Map map = (Map)newValue;
	Set set = map.keySet();
	Iterator iter = set.iterator();
	PyDictionary dict = new PyDictionary();
	while (iter.hasNext()) {
		Object next = iter.next();
		if (!(next instanceof String)) 
			throw new IllegalArgumentException("Key of the map is not string.");
		String key = (String)next;
		if (!(map.get(key) instanceof PyObject))
			throw new IllegalArgumentException("Value of the item of the map is not PyObject.");
		dict.__setitem__(new PyString(key), (PyObject) map.get(key));
	}
	
	return dict;
}
 
开发者ID:kefik,项目名称:Pogamut3,代码行数:25,代码来源:PyDictionaryWrapper.java

示例6: makePyRoi

import org.python.core.PyObject; //导入依赖的package包/类
protected static PyObject makePyRoi(Object region) {
	IROI roi = null;
	if (region instanceof ScanRegion<?>) {
		region = ((ScanRegion<?>) region).getRoi();
	}
	if (region instanceof IROI) {
		roi = (IROI) region;
	} else {
		logger.error("Unknown region type: " + region.getClass());
		return null;
	}
	if (roiDispatchMap.containsKey(roi.getClass())) {
		return roiDispatchMap.get(roi.getClass()).apply(roi);
	} else {
		logger.error("Unsupported region type: " + roi.getClass());
		return null;
	}
}
 
开发者ID:eclipse,项目名称:scanning,代码行数:19,代码来源:AbstractScanPointIterator.java

示例7: fdopen

import org.python.core.PyObject; //导入依赖的package包/类
public static PyObject fdopen(PyObject fd, String mode, int bufsize) {
    if (mode.length() == 0 || !"rwa".contains("" + mode.charAt(0))) {
        throw Py.ValueError(String.format("invalid file mode '%s'", mode));
    }
    RawIOBase rawIO = FileDescriptors.get(fd);
    if (rawIO.closed()) {
        throw badFD();
    }

    try {
        return new PyFile(rawIO, "<fdopen>", mode, bufsize);
    } catch (PyException pye) {
        if (!pye.match(Py.IOError)) {
            throw pye;
        }
        throw Py.OSError((Constant)Errno.EINVAL);
    }
}
 
开发者ID:RunasSudo,项目名称:PyAndroid,代码行数:19,代码来源:PosixModule.java

示例8: fsync

import org.python.core.PyObject; //导入依赖的package包/类
/**
 * Internal fsync implementation.
 */
private static void fsync(PyObject fd, boolean metadata) {
    RawIOBase rawIO = FileDescriptors.get(fd);
    rawIO.checkClosed();
    Channel channel = rawIO.getChannel();
    if (!(channel instanceof FileChannel)) {
        throw Py.OSError(Errno.EINVAL);
    }

    try {
        ((FileChannel)channel).force(metadata);
    } catch (ClosedChannelException cce) {
        // In the rare case it's closed but the rawIO wasn't
        throw Py.ValueError("I/O operation on closed file");
    } catch (IOException ioe) {
        throw Py.OSError(ioe);
    }
}
 
开发者ID:RunasSudo,项目名称:PyAndroid,代码行数:21,代码来源:PosixModule.java

示例9: utime

import org.python.core.PyObject; //导入依赖的package包/类
public static void utime(PyObject path, PyObject times) {
    long[] atimeval;
    long[] mtimeval;

    if (times == Py.None) {
        atimeval = mtimeval = null;
    } else if (times instanceof PyTuple && times.__len__() == 2) {
        atimeval = extractTimeval(times.__getitem__(0));
        mtimeval = extractTimeval(times.__getitem__(1));
    } else {
        throw Py.TypeError("utime() arg 2 must be a tuple (atime, mtime)");
    }
    if (posix.utimes(absolutePath(path), atimeval, mtimeval) < 0) {
        throw errorFromErrno(path);
    }
}
 
开发者ID:RunasSudo,项目名称:PyAndroid,代码行数:17,代码来源:PosixModule.java

示例10: callFunc

import org.python.core.PyObject; //导入依赖的package包/类
public static Object callFunc(Class<?> c, String funcName, Object... binds) {
	try {
		PyObject obj = ScriptManager.python.get(funcName);
		if (obj != null && obj instanceof PyFunction) {
			PyFunction func = (PyFunction) obj;
			PyObject[] objects = new PyObject[binds.length];
			for (int i = 0; i < binds.length; i++) {
				Object bind = binds[i];
				objects[i] = Py.java2py(bind);
			}
			return func.__call__(objects).__tojava__(c);
		} else
			return null;
	} catch (PyException ex) {
		ex.printStackTrace();
		return null;
	}
}
 
开发者ID:Jarinus,项目名称:osrs-private-server,代码行数:19,代码来源:ScriptManager.java

示例11: gradeValueToPyObject

import org.python.core.PyObject; //导入依赖的package包/类
/**
 * Converts a grade value of the exmatrikulator system in a python representation
 * depending of the gradeType and value of the grade. The following mappings
 * take place:
 *  * GradeType.Boolean will be represented as PyBoolean
 *    for passed(true)
 *    / not passed(false)
 *    / none if the error doesnt represent a boolean.
 *  * GradeType.Numeric and GradeType.Percent will be represented as python
 *    Decimals with the numeric or percent values.
 *  * GradeType.Point will be represented as tuple of the reached and max
 *    points.
 *  * If the grade has no value (no grade has been given): The grade will be None.
 * @param grade The grade object representing the grade object.
 * @return The Python object representation of the grade value.
 */
private PyObject gradeValueToPyObject(Grade grade) {
    log.debug("gradeValueToPyObject called with: " + grade);
    if (grade == null || grade.getValue() == null) {
        return pyInterpreter.get(PY_NONE);
    }
    if (GradeType.Boolean.getId().equals(grade.getGradeType())) {
        return booleanGradeToPyBoolean(grade);
    } else if (GradeType.Numeric.getId().equals(grade.getGradeType())
            || GradeType.Percent.getId().equals(grade.getGradeType())) {
        return pyDecimalFromBigDecimal(grade.getValue());
    } else if (GradeType.Point.getId().equals(grade.getGradeType())) {
        return pyTupleFromPointGrade(grade);
    } else {
        throw new IllegalStateException(
                "Grade was not a Boolean, Numeric nor PointGrade");
    }
}
 
开发者ID:stefanoberdoerfer,项目名称:exmatrikulator,代码行数:34,代码来源:GradeScriptController.java

示例12: parse

import org.python.core.PyObject; //导入依赖的package包/类
public void parse(PyObject[] args, String[] kws) {
    int nargs = args.length - kws.length;
    
    if (nargs < fixedArgs.length) {
        // TODO I need to verify these exceptions bubble up correctly
        throw Py.TypeError(String.format("Not enough arguments to %s(): %d provided, %d needed",
                funcname, nargs, fixedArgs.length));
    }

    // fixed arguments
    for (int i=0; i < fixedArgs.length; i++) {
        this.args.put(fixedArgs[i], args[i]);
    }

    // keyword arguments
    for (int i=0; i < kws.length; i++) {
        if (!this.keywordArgs.contains(kws[i])) {
            throw Py.TypeError(String.format("Unexpected keyword argument to %s(): %s",
                    funcname, kws[i]));
        }
        this.args.put(kws[i], args[nargs + i]);
    }
}
 
开发者ID:r1chardj0n3s,项目名称:pycode-minecraft,代码行数:24,代码来源:ArgParser.java

示例13: 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);
}
 
开发者ID:dream-lab,项目名称:echo,代码行数:8,代码来源:NifiClientFactory.java

示例14: getChildren

import org.python.core.PyObject; //导入依赖的package包/类
@Override
public ArrayList<PyObjectAdapter> getChildren(Object object) {
	if (!(object instanceof PyList))
		throw new IllegalArgumentException("object is not instance of PyList");
	final PyList pyList = (PyList) object;
	int count = (pyList.__len__());
	ArrayList<PyObjectAdapter> list = new ArrayList<PyObjectAdapter>(count);
	PyObject obj;
	for (int i = 0; i < count; ++i){
		final int place = i;
		obj = pyList.__finditem__(place);
		list.add(
			new PyObjectAdapter(
					String.valueOf(place),
					new PyObjectPlace(){
						private int myPlace = place;
						@Override
						public void set(PyObject newValue) {
							pyList.__setitem__(myPlace, newValue);
						}
						@Override
						public PyObject get(){
							try{
								return pyList.__finditem__(myPlace);
							} catch (Exception e){
								return null;
							}
						}
					}
			)
		);
	}
	return list;		
}
 
开发者ID:kefik,项目名称:Pogamut3,代码行数:35,代码来源:PyListWrapper.java

示例15: getChildren

import org.python.core.PyObject; //导入依赖的package包/类
@Override
public ArrayList<PyObjectAdapter> getChildren(Object object) {
	if (!(object instanceof PyTuple))
		throw new IllegalArgumentException("object is not instance of PyTuple");
	final PyTuple pyTuple = (PyTuple) object;
	int count = (pyTuple.__len__());
	ArrayList<PyObjectAdapter> list = new ArrayList<PyObjectAdapter>(count);
	for (int i = 0; i < count; ++i){
		final int place = i;
		list.add(
			new PyObjectAdapter(
					String.valueOf(i),
					new PyObjectPlace(){
						private int myPlace = place;
						@Override
						public void set(PyObject newValue) {								
						}
						@Override
						public PyObject get(){
							try{
								return pyTuple.__finditem__(myPlace);
							} catch (Exception e){
								return null;
							}
						}
					}
			)
		);
	}
	return list;		
}
 
开发者ID:kefik,项目名称:Pogamut3,代码行数:32,代码来源:PyTupleWrapper.java


注:本文中的org.python.core.PyObject类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。