Package org.python.core

Examples of org.python.core.PyTuple


            PyString pypath = new PyString(pluginpath.getAbsolutePath());
            PyObject[] elements = new PyObject[] {pypath};
            PyList paths = new PyList(elements);
            PyObject result = imp.find_module(subname, paths);
            if (result != null) {
                PyTuple info = (PyTuple) result;

            }
        }
        return Py.None;
    }
View Full Code Here


                    .append(metricName)
                    .append(".")
                    .append(valueName)
                    .toString();
            }
            PyTuple tuple = new PyTuple(new PyString(metricName),
                new PyTuple(new PyLong(timestamp), new PyString(value)));
            metrics.add(tuple);
            if(metrics.size() >= batchSize) {
                writeMetrics();
            }
        }
View Full Code Here

                    .append(metricName)
                    .append(".")
                    .append(valueName)
                    .toString();
            }
            PyTuple tuple = new PyTuple(new PyString(metricName),
                new PyTuple(new PyLong(timestamp), new PyString(value)));
            metrics.add(tuple);
            if(metrics.size() >= batchSize) {
                writeMetrics();
            }
        }
View Full Code Here

  @Override
  protected Object resolveObject(Object obj) throws IOException {
    // This method will reconstruct the PyFunction based on its name or its
    // source if it was a closure
    if (obj instanceof SerializedPythonFunction) {
      PyTuple serializedFunction = ((SerializedPythonFunction) obj).getSerializedFunction();
      String functionType = (String) serializedFunction.get(0);
      String functionName = (String) serializedFunction.get(3);
      PyObject function = null;
      if ("global".equals(functionType)) {
        function = interpreter.get(functionName);
      } else if ("closure".equals(functionType)) {
        interpreter.exec((String) serializedFunction.get(4));
        function = interpreter.get(functionName);
      }
      return function;
    } else
      return obj;
View Full Code Here

        }
       
        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

        environ.put("PATH_INFO", StringUtils.join(seg.toArray(), "/"));
        //environ.put("PATH_INFO", );
       
        environ.put("QUERY_STRING", request.getResourceRef().getQuery());

        environ.put("wsgi.version", new PyTuple(new PyInteger(0), new PyInteger(1)));
        environ.put("wsgi.url_scheme", ref.getScheme());
        environ.put("wsgi.input", new PyFile(request.getEntity().getStream()));
        environ.put("wsgi.errors", new PyFile(System.err));
        environ.put("wsgi.multithread", true);
        environ.put("wsgi.multitprocess", false);
View Full Code Here

        }
       
        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,
                    input.__getitem__(1),
                    defaultValue, metadata);
            map.put(arg, parameter);
        }
        return map;
    }
View Full Code Here

   
        PyDictionary outputs = (PyDictionary) process(engine).__getattr__("outputs");
        Map<String,Parameter<?>> map = new TreeMap<String, Parameter<?>>();

        for (String name : (List<String>)outputs.keys()) {
          PyTuple output = (PyTuple) outputs.get(name);

            Object type = output.__getitem__(0);
            Object desc = output.__getitem__(1);

            // map every key in the optional dictionary as parameter metadata entry
            Map<String, Object> metadata = null;
            if (output.size() == 3) {
                PyDictionary meta = (PyDictionary) output.get(2);
                if(meta != null && !meta.isEmpty()) {
                  metadata = new HashMap<String, Object>();
                  for (Object key : meta.keySet()) {
            metadata.put((String) key, meta.get(key));
          }
View Full Code Here

        }
       
        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.PyTuple

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.