Package org.python.core

Examples of org.python.core.PyList


    }
   
    public Map<String,Parameter<?>> getOutputParameters(String name) {
        try {
            PySequenceList args = (PySequenceList) process(name).__getattr__("result");
            PyList list = new PyList();
            list.add(args);
            return parameters(list);
        }
        catch(Exception e) {
            throw new RuntimeException("Error occurred looking up result for process " + name, e);
        }
View Full Code Here


    }

    private void execFile(String filePath, String... arguments) {
        interp.cleanup();
        interp.set("__file__", filePath);
        sys.argv = new PyList(new PyString[]{new PyString(filePath)});
        sys.argv.extend(new PyArray(PyString.class, arguments));
        interp.execfile(filePath);
    }
View Full Code Here

               
                if (ret instanceof PyString) {
                    response.setEntity(ret.toString(), mediaType);
                }
                else if (ret instanceof PyList) {
                    final PyList list = (PyList) ret;
                    response.setEntity(new OutputRepresentation(mediaType) {
                       
                        @Override
                        public void write(OutputStream outputStream) throws IOException {
                            for (Iterator i = list.iterator(); i.hasNext();) {
                                outputStream.write(i.next().toString().getBytes());
                                if (i.hasNext()) {
                                    outputStream.write('\n');
                                }
                            }
View Full Code Here

        else {
            r.code = status.toString();
        }
       
        if (objs.length > 1) {
            PyList headers = (PyList) objs[1];
            for (Iterator i = headers.iterator(); i.hasNext();) {
                PyTuple tup = (PyTuple) i.next();
                r.headers.put(tup.get(0).toString(), tup.get(1).toString());
            }
        }
        return null;
View Full Code Here

    @Override
    public Map<String, Parameter<?>> getInputs(ScriptEngine engine)
            throws ScriptException {
        engine.eval("import inspect");
        PyList args = (PyList) engine.eval("inspect.getargspec(run.func_closure[0].cell_contents)[0]");
        PyTuple defaults = (PyTuple) engine
                .eval("inspect.getargspec(run.func_closure[0].cell_contents)[3]");
        PyDictionary inputs = (PyDictionary) process(engine).__getattr__("inputs");

        if (args.size() != inputs.size()) {
            throw new RuntimeException(String.format("process function specified %d arguments but"+
                " describes %d inputs", args.size(), inputs.size()));
        }

        Map<String, Parameter<?>> map = new LinkedHashMap<String, Parameter<?>>();
        for (int i = 0; i < args.size(); i++) {
            String arg = args.get(i).toString();
            PyTuple input = (PyTuple) inputs.get(arg);
            if (input == null) {
                throw new RuntimeException(String.format("process function specified argument %s" +
                    " but does not specify it as an input", arg));
            }
            int min = 1;
            int max = 1;
            Object defaultValue = null;
            Map metadata = null;
            if (input.size() == 3) {
                PyDictionary meta = (PyDictionary) input.get(2);
                min = getParameter(meta, "min", Integer.class, 1);
                max = getParameter(meta, "max", Integer.class, 1);
                List<String> options = getParameter(meta, "domain", List.class, null);
                if (options != null) {
                    metadata = new HashMap();
                    metadata.put(Parameter.OPTIONS, options);
                }
                // map every other key as parameter metadata entry
                HashSet<String> otherKeys = new HashSet<String>(meta.keySet());
                otherKeys.remove("min");
                otherKeys.remove("max");
                otherKeys.remove("domain");
                if(!otherKeys.isEmpty()) {
                    if (metadata == null) {
                        metadata = new HashMap();
                    }
                    for (String key : otherKeys) {
            metadata.put(key, meta.get(key));
          }
                }
            }
            if (defaults != null) {
                // from the python guide:
                // defaults is a tuple of default argument values or None if there are no
                // default arguments; if this tuple has n elements,
                // they correspond to the last n elements listed in args.
                int defaultIdx = defaults.size() - (args.size() - i);
                if (defaultIdx >= 0) {
                    defaultValue = defaults.get(defaultIdx);
                }
            }
            Parameter parameter = parameter(arg, input.__getitem__(0), min, max,
View Full Code Here

            if (crs != null) {
                tb.setCRS(crs);
            }
        }
      
        PyList fields = (PyList) schema.__findattr__("fields");
        for (Object o : fields.toArray()) {
            PyObject field = (PyObject) o;
           
            String name = ((PyString)field.__findattr__("name")).asString();
           
            PyType type = (PyType)field.__findattr__("typ");
View Full Code Here

       
        PyMethod layers = (PyMethod) workspace.__findattr__("layers");
        if (layers == null) {
            layers = (PyMethod) workspace.__findattr__("keys");
        }
        PyList result = (PyList) layers.__call__();
       
        List<Name> typeNames = new ArrayList<Name>();
        for (Object o : result.toArray()) {
            typeNames.add(new NameImpl(o.toString()));
        }
        return typeNames;
    }
View Full Code Here

        return process(name).__getattr__("version").toString();
    }
   
    public Map<String,Parameter<?>> getInputParameters(String name) {
        try {
            PyList args = (PyList) process(name).__getattr__("args");
            return parameters(args);
        }
        catch(Exception e) {
            throw new RuntimeException("Error occurred looking up inputs for process " + name, e);
        }
View Full Code Here

    }
   
    public Map<String,Parameter<?>> getOutputParameters(String name) {
        try {
            PySequenceList args = (PySequenceList) process(name).__getattr__("result");
            PyList list = new PyList();
            list.add(args);
            return parameters(list);
        }
        catch(Exception e) {
            throw new RuntimeException("Error occurred looking up result for process " + name, e);
        }
View Full Code Here

        else {
            r.statusCode = status.toString();
        }
       
        if (objs.length > 1) {
            PyList headers = (PyList) objs[1];
            for (Iterator i = headers.iterator(); i.hasNext();) {
                PyTuple tup = (PyTuple) i.next();
                r.headers.put(tup.get(0).toString(), tup.get(1).toString());
            }
        }
        return null;
View Full Code Here

TOP

Related Classes of org.python.core.PyList

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.