Package org.python.core

Examples of org.python.core.PyDictionary


    public PyObject getKeywords() {
        if (keywords.length == 0) {
            return Py.None;
        }
        int argc = args.length - keywords.length;
        PyObject kwDict = new PyDictionary();
        for (int i = 0; i < keywords.length; i++) {
            kwDict.__setitem__(Py.newString(keywords[i]), args[argc + i]);
        }
        return kwDict;
    }
View Full Code Here


  public JythonScope(PyObject scope) {
    this.scope = scope;
  }
 
  public JythonScope() {
    scope = new PyDictionary();
  }
View Full Code Here

      i = 1;
      for (Object value : tupleEntry.getTuple()) {
        dictElements[i] = Py.java2py(value);
        i += 2;
      }
      PyDictionary dict = new PyDictionary(dictElements);
      result = dict;
    }
    return result;
  }
View Full Code Here

     * @param request
     * @return
     */
    PyObject createEnviron(Request request) {
       
        PyDictionary environ = new PyDictionary();
       
        environ.put("REQUEST_METHOD", request.getMethod().toString());
       
        Reference ref = request.getResourceRef();
        environ.put("SCRIPT_NAME", ref.getLastSegment());
       
        Reference pref = ref.getParentRef();
        environ.put("PATH_INFO", pref.toString().substring(
            request.getRootRef().toString().length(), pref.toString().length()-1 ));
       
        environ.put("QUERY_STRING", request.getResourceRef().getQuery());

        //TODO: fill in rest of parameters
        return environ;
    }
View Full Code Here

        PyFunction getargspec = (PyFunction) pi.get("getargspec");
        PyObject init =  type.__getattr__("__init__");
       
        PySequence argspec =
            (PySequence) getargspec.__call__(init.__getattr__("wrapped")).__getitem__(0);
        PyDictionary params = (PyDictionary) init.__getattr__("params");
       
        List<Param> list = new ArrayList();
        for (Object item : (Collection) argspec) {
            String pname = item.toString();
            if ("self".equals(pname)) continue;
           
            PySequence pinfo = (PySequence) params.get(pname);
           
            String pdesc = pinfo != null ? pinfo.__getitem__(0).toString() : pname;
            Object ptype = null;
            try {
                ptype = pinfo != null ? pinfo.__getitem__(1) : null;
View Full Code Here

     * @return
     * @throws IOException
     */
    PyObject createEnviron(Request request) throws IOException {
       
        PyDictionary environ = new PyDictionary();
       
        environ.put("REQUEST_METHOD", request.getMethod().toString());
       
        Reference ref = request.getResourceRef();
        environ.put("SCRIPT_NAME", ref.getLastSegment());

        //force to pystring so that frameworks don't try to encode as idna
        environ.put("SERVER_NAME", new PyString(ref.getHostDomain()));
        environ.put("SERVER_PORT", String.valueOf(ref.getHostPort()));

        List<String> seg = new ArrayList(ref.getSegments().subList(4, ref.getSegments().size()));
        seg.add(0, "");
       
        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);
        environ.put("wsgi.run_once", false);
        return environ;
    }
View Full Code Here

            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:
View Full Code Here

    @Override
    public Map<String, Parameter<?>> getOutputs(ScriptEngine engine)
            throws ScriptException {
   
        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));
          }
                }
            }

            map.put(name, parameter(name, type, 1, 1, desc, null, metadata));
View Full Code Here

        PyFunction getargspec = (PyFunction) pi.get("getargspec");
        PyObject init =  type.__getattr__("__init__");
       
        PySequence argspec =
            (PySequence) getargspec.__call__(init.__getattr__("wrapped")).__getitem__(0);
        PyDictionary params = (PyDictionary) init.__getattr__("params");
       
        List<Param> list = new ArrayList();
        for (Object item : (Collection) argspec) {
            String pname = item.toString();
            if ("self".equals(pname)) continue;
           
            PySequence pinfo = (PySequence) params.get(pname);
           
            String pdesc = pinfo != null ? pinfo.__getitem__(0).toString() : pname;
            Object ptype = null;
            try {
                ptype = pinfo != null ? pinfo.__getitem__(1) : null;
View Full Code Here

     * @param request
     * @return
     */
    PyObject createEnviron(Request request) {
       
        PyDictionary environ = new PyDictionary();
       
        environ.put("REQUEST_METHOD", request.getMethod().toString());
       
        Reference ref = request.getResourceRef();
        environ.put("SCRIPT_NAME", ref.getLastSegment());
       
        Reference pref = ref.getParentRef();
        environ.put("PATH_INFO", pref.toString().substring(
            request.getRootRef().toString().length(), pref.toString().length()-1 ));
       
        environ.put("QUERY_STRING", request.getResourceRef().getQuery());

        //TODO: fill in rest of parameters
        return environ;
    }
View Full Code Here

TOP

Related Classes of org.python.core.PyDictionary

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.