• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java PyTuple类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: loadAvailableLexers

import org.python.core.PyTuple; //导入依赖的package包/类
public List<LexerInfo> loadAvailableLexers(PyGateway gateway) {
    PythonInterpreter interpreter = gateway.getInterpreter();

    // Simple use Pygments as you would in Python
    interpreter.exec(""
            + "from pygments.lexers import get_all_lexers\n"
            + "result = get_all_lexers()");

    PyGenerator result = (PyGenerator) interpreter.get("result");
    ArrayList<LexerInfo> infos = Lists.newArrayList();
    for (Object o : result) {
        PyTuple tuple = (PyTuple) o;
        String name = (String) tuple.get(0);
        List<String> aliases = Lists.newArrayListWithCapacity(3);
        for (Object alias : (PyTuple) tuple.get(1)) {
            String str = (String) alias;
            aliases.add(str);
        }
        LexerInfo info = new LexerInfo(name, aliases);
        infos.add(info);
    }
    return infos;
}
 
开发者ID:Arnauld,项目名称:gutenberg,代码行数:24,代码来源:Lexers.java


示例2: getJavaObject

import org.python.core.PyTuple; //导入依赖的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


示例3: PyObjectWrappersManager

import org.python.core.PyTuple; //导入依赖的package包/类
protected PyObjectWrappersManager(){
	PyObjectWrappersManager.wrappers.put(PyInteger.class,    new PyIntegerWrapper());
	PyObjectWrappersManager.wrappers.put(Integer.class,      new PyIntegerWrapper());
	PyObjectWrappersManager.wrappers.put(PyFloat.class,      new PyFloatWrapper());
	PyObjectWrappersManager.wrappers.put(Float.class,        new PyFloatWrapper());
	PyObjectWrappersManager.wrappers.put(Double.class,       new PyFloatWrapper());
	PyObjectWrappersManager.wrappers.put(PyLong.class,       new PyLongWrapper());
	PyObjectWrappersManager.wrappers.put(Long.class,         new PyLongWrapper());
	PyObjectWrappersManager.wrappers.put(BigInteger.class,   new PyLongWrapper());
	PyObjectWrappersManager.wrappers.put(PyString.class,     new PyStringWrapper());
	PyObjectWrappersManager.wrappers.put(String.class,       new PyStringWrapper());
	PyObjectWrappersManager.wrappers.put(PyList.class,       new PyListWrapper());
	PyObjectWrappersManager.wrappers.put(PyDictionary.class, new PyDictionaryWrapper());
	PyObjectWrappersManager.wrappers.put(PyTuple.class,      new PyTupleWrapper());
	PyObjectWrappersManager.wrappers.put(PyInstance.class,   new PyInstanceWrapper());
}
 
开发者ID:kefik,项目名称:Pogamut3,代码行数:17,代码来源:PyObjectWrappersManager.java


示例4: utime

import org.python.core.PyTuple; //导入依赖的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


示例5: getMap

import org.python.core.PyTuple; //导入依赖的package包/类
public static Map<String, Object> getMap(ArgParser ap, int position)
/*     */   {
/* 196 */     PyObject arg = ap.getPyObject(position, Py.None);
/* 197 */     if (Py.isInstance(arg, PyNone.TYPE)) {
/* 198 */       return Collections.emptyMap();
/*     */     }
/*     */
/* 201 */     Map ret = Maps.newHashMap();
/*     */
/* 203 */     PyDictionary dict = (PyDictionary)arg;
/* 204 */     PyList items = dict.items();
/* 205 */     for (int x = 0; x < items.__len__(); x++)
/*     */     {
/* 207 */       PyTuple item = (PyTuple)items.__getitem__(x);
/*     */
/* 209 */       String key = (String)item.__getitem__(0).__str__().__tojava__(String.class);
/* 210 */       PyObject value = item.__getitem__(1);
/*     */
/* 213 */       Class javaClass = (Class)PYOBJECT_TO_JAVA_OBJECT_MAP.get(value.getClass());
/* 214 */       if (javaClass != null) {
/* 215 */         ret.put(key, value.__tojava__(javaClass));
/*     */       }
/*     */     }
/* 218 */     return ret;
/*     */   }
 
开发者ID:hoozheng,项目名称:AndroidRobot,代码行数:26,代码来源:JythonUtils.java


示例6: getParamsFromVariables

import org.python.core.PyTuple; //导入依赖的package包/类
@Override
protected Map<String, Object> getParamsFromVariables() throws IOException {
    PyFrame frame = Py.getFrame();
    @SuppressWarnings("unchecked")
    List<PyTuple> locals = ((PyStringMap) frame.getLocals()).items();
    Map<String, Object> vars = new HashMap<String, Object>();
    for (PyTuple item : locals) {
        String key = (String) item.get(0);
        Object obj = item.get(1);
        if (obj != null) {
            String value = item.get(1).toString();
            vars.put(key, value);
        }
    }
    return vars;
}
 
开发者ID:sigmoidanalytics,项目名称:spork-streaming,代码行数:17,代码来源:JythonScriptEngine.java


示例7: getChildren

import org.python.core.PyTuple; //导入依赖的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


示例8: getNewValue

import org.python.core.PyTuple; //导入依赖的package包/类
/**
 * Accepts List<PyObject> as parameter of newValue.
 * Returns PyList
 */
@Override
public PyObject getNewValue(Object newValue) {
	if (!(newValue instanceof List)){
		throw new IllegalArgumentException("newValue is not instance of List");
	} 
	List list = (List)newValue;
	PyObject[] elements = new PyObject[list.size()];
	for (int i = 0; i < list.size(); ++i){
		if (!(list.get(i) instanceof PyObject))
			throw new IllegalArgumentException("value of the list is not instance of PyObject");
		elements[i] = (PyObject)list.get(i);
	}
	return new PyTuple(elements);
}
 
开发者ID:kefik,项目名称:Pogamut3,代码行数:19,代码来源:PyTupleWrapper.java


示例9: rmdir

import org.python.core.PyTuple; //导入依赖的package包/类
public static void rmdir(PyObject path) {
    File file = new File(absolutePath(path));
    if (!file.exists()) {
        throw Py.OSError(Errno.ENOENT, path);
    } else if (!file.isDirectory()) {
        throw Py.OSError(Errno.ENOTDIR, path);
    } else if (!file.delete()) {
        PyObject args = new PyTuple(Py.Zero, new PyString("Couldn't delete directory"),
                                    path);
        throw new PyException(Py.OSError, args);
    }
}
 
开发者ID:RunasSudo,项目名称:PyAndroid,代码行数:13,代码来源:PosixModule.java


示例10: if

import org.python.core.PyTuple; //导入依赖的package包/类
@Hide(OS.NT)
public static PyObject wait$() {
    int[] status = new int[1];
    int pid = posix.wait(status);
    if (pid < 0) {
        throw errorFromErrno();
    }
    return new PyTuple(Py.newInteger(pid), Py.newInteger(status[0]));
}
 
开发者ID:RunasSudo,项目名称:PyAndroid,代码行数:10,代码来源:PosixModule.java


示例11: waitpid

import org.python.core.PyTuple; //导入依赖的package包/类
public static PyObject waitpid(int pid, int options) {
    int[] status = new int[1];
    pid = posix.waitpid(pid, status, options);
    if (pid < 0) {
        throw errorFromErrno();
    }
    return new PyTuple(Py.newInteger(pid), Py.newInteger(status[0]));
}
 
开发者ID:RunasSudo,项目名称:PyAndroid,代码行数:9,代码来源:PosixModule.java


示例12: _get_shell_commands

import org.python.core.PyTuple; //导入依赖的package包/类
/**
 * Helper function for the subprocess module, returns the potential shell commands for
 * this OS.
 *
 * @return a tuple of lists of command line arguments. E.g. (['/bin/sh', '-c'])
 */
public static PyObject _get_shell_commands() {
    String[][] commands = os.getShellCommands();
    PyObject[] commandsTup = new PyObject[commands.length];
    int i = 0;
    for (String[] command : commands) {
        PyList args = new PyList();
        for (String arg : command) {
            args.append(new PyString(arg));
        }
        commandsTup[i++] = args;
    }
    return new PyTuple(commandsTup);
}
 
开发者ID:RunasSudo,项目名称:PyAndroid,代码行数:20,代码来源:PosixModule.java


示例13: getBindings

import org.python.core.PyTuple; //导入依赖的package包/类
@Override
public Map<String, Object> getBindings()
{
  Map<String, Object> bindings = new HashMap<String, Object>();
  PyStringMap keyValueMap = (PyStringMap)interp.getLocals();
  PyIterator keyValueSet = (PyIterator)keyValueMap.iteritems();
  for (Object temp : keyValueSet) {
    PyTuple tempEntry = (PyTuple)temp;
    Iterator<PyObject> iter = tempEntry.iterator();
    bindings.put((String)iter.next().__tojava__(String.class), iter.next());
  }
  return bindings;
}
 
开发者ID:apache,项目名称:apex-malhar,代码行数:14,代码来源:PythonOperator.java


示例14: pigTupleToPyTuple

import org.python.core.PyTuple; //导入依赖的package包/类
public static PyTuple pigTupleToPyTuple(Tuple tuple) {
    PyObject[] pyTuple = new PyObject[tuple.size()];
    int i = 0;
    for (Object object : tuple.getAll()) {
        pyTuple[i++] = pigToPython(object);
    }
    return new PyTuple(pyTuple);
}
 
开发者ID:sigmoidanalytics,项目名称:spork-streaming,代码行数:9,代码来源:JythonUtils.java


示例15: registerFunctions

import org.python.core.PyTuple; //导入依赖的package包/类
@Override
public void registerFunctions(String path, String namespace, PigContext pigContext)
throws IOException {
    Interpreter.setMain(false);
    Interpreter.init(path, pigContext);
    pigContext.scriptJars.add(getJarPath(PythonInterpreter.class));
    PythonInterpreter pi = Interpreter.interpreter;
    @SuppressWarnings("unchecked")
    List<PyTuple> locals = ((PyStringMap) pi.getLocals()).items();
    namespace = (namespace == null) ? "" : namespace + NAMESPACE_SEPARATOR;
    try {
        for (PyTuple item : locals) {
            String key = (String) item.get(0);
            Object value = item.get(1);
            FuncSpec funcspec = null;
            if (!key.startsWith("__") && !key.equals("schemaFunction")
                    && !key.equals("outputSchema")
                    && !key.equals("outputSchemaFunction")
                    && (value instanceof PyFunction)
                    && (((PyFunction)value).__findattr__("schemaFunction")== null)) {
                PyObject obj = ((PyFunction)value).__findattr__("outputSchema");
                if(obj != null) {
                    Utils.getSchemaFromString(obj.toString());
                }
                funcspec = new FuncSpec(JythonFunction.class.getCanonicalName() + "('"
                        + path + "','" + key +"')");
                pigContext.registerFunction(namespace + key, funcspec);
                LOG.info("Register scripting UDF: " + namespace + key);
            }
        }
    } catch (ParserException pe) {
        throw new IOException(
                "Error parsing schema for script function from the decorator",
                pe);
    }
    pigContext.addScriptFile(path);
    Interpreter.setMain(true);
}
 
开发者ID:PonIC,项目名称:PonIC,代码行数:39,代码来源:JythonScriptEngine.java


示例16: rename

import org.python.core.PyTuple; //导入依赖的package包/类
public static void rename(PyObject oldpath, PyObject newpath) {
    if (!new File(absolutePath(oldpath)).renameTo(new File(absolutePath(newpath)))) {
        PyObject args = new PyTuple(Py.Zero, new PyString("Couldn't rename file"));
        throw new PyException(Py.OSError, args);
    }
}
 
开发者ID:RunasSudo,项目名称:PyAndroid,代码行数:7,代码来源:PosixModule.java


示例17: stat_result___reduce__

import org.python.core.PyTuple; //导入依赖的package包/类
@ExposedMethod
final PyObject stat_result___reduce__() {
    PyTuple newargs = __getnewargs__();
    return new PyTuple(getType(), newargs);
}
 
开发者ID:RunasSudo,项目名称:PyAndroid,代码行数:6,代码来源:PyStatResult.java


示例18: __getnewargs__

import org.python.core.PyTuple; //导入依赖的package包/类
@Override
public PyTuple __getnewargs__() {
    return new PyTuple(new PyList(getArray()));
}
 
开发者ID:RunasSudo,项目名称:PyAndroid,代码行数:5,代码来源:PyStatResult.java


示例19: longPress

import org.python.core.PyTuple; //导入依赖的package包/类
public void longPress(int x, int y) {
    PyTuple point = new PyTuple(new PyInteger(x), new PyInteger(y));
    _device.drag(new PyObject[] { point, point, new PyInteger(2), new PyInteger(2) }, null);
}
 
开发者ID:imsardine,项目名称:sikuli-monkey,代码行数:5,代码来源:AndroidRobot.java


示例20: getModuleState

import org.python.core.PyTuple; //导入依赖的package包/类
/**
 * get the state of modules currently loaded
 * @return a map of module name to module file (absolute path)
 */
private static Map<String, String> getModuleState() {
    // determine the current module state
    Map<String, String> files = new HashMap<String, String>();
    PyStringMap modules = (PyStringMap) Py.getSystemState().modules;
    for (PyObject kvp : modules.iteritems().asIterable()) {
        PyTuple tuple = (PyTuple) kvp;
        String name = tuple.get(0).toString();
        Object value = tuple.get(1);
        // inspect the module to determine file location and status
        try {
            Object fileEntry = null;
            Object loader = null;
            if (value instanceof PyJavaPackage ) {
                fileEntry = ((PyJavaPackage) value).__file__;
            } else if (value instanceof PyObject) {
                // resolved through the filesystem (or built-in)
                PyObject dict = ((PyObject) value).getDict();
                if (dict != null) {
                    fileEntry = dict.__finditem__("__file__");
                    loader = dict.__finditem__("__loader__");
                } // else built-in
            }   // else some system module?

            if (fileEntry != null) {
                File file = resolvePyModulePath(fileEntry.toString(), loader);
                if (file.exists()) {
                    String apath = file.getAbsolutePath();
                    if (apath.endsWith(".jar") || apath.endsWith(".zip")) {
                        // jar files are simple added to the pigContext
                        files.put(apath, apath);
                    } else {
                        // determine the relative path that the file should have in the jar
                        int pos = apath.lastIndexOf(File.separatorChar + name.replace('.', File.separatorChar));
                        if (pos > 0) {
                            files.put(apath.substring(pos), apath);
                        } else {
                            files.put(apath, apath);
                        }
                    }
                } else {
                    LOG.warn("module file does not exist: " + name + ", " + file);
                }
            } // else built-in
        } catch (Exception e) {
            LOG.warn("exception while retrieving module state: " + value, e);
        }
    }
    return files;
}
 
开发者ID:sigmoidanalytics,项目名称:spork-streaming,代码行数:54,代码来源:JythonScriptEngine.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java AutocompletePredictionBuffer类代码示例发布时间:2022-05-21
下一篇:
Java OFFlowDeleteStrict类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap