Package org.python.core

Examples of org.python.core.PyList


            boolean exclpkgs) {
        PyStringMap dict = jpkg.__dict__;
        PyStringMap cls = jpkg.clsSet;

        if (!instantiate) {
            PyList ret = cls.keys();
            PyList dictKeys = dict.keys();

            for (PyObject name : dictKeys.asIterable()) {
                if (!cls.has_key(name)) {
                    if (exclpkgs && dict.get(name) instanceof PyJavaPackage)
                        continue;
                    ret.append(name);
                }
View Full Code Here


                if (keyword.equals("desc") || keyword.equals("description"))
                    desc = args[i].toString();
                else if (keyword.equals("usage"))
                    usage = args[i].toString();
                else if (keyword.equals("aliases"))
                    aliases = new PyList(args[i]);
                else if (keyword.equals("onTabComplete"))
                    tabComplete = args[i];
            }
            final String name;
            if (kwdelta == 1)
View Full Code Here

            if (!isPluginLoaded(pluginName)) {
                throw new UnknownDependencyException(pluginName);
            }
        }

        PyList pythonpath = Py.getSystemState().path;
        PyString filepath = new PyString(file.getAbsolutePath());
        if (data.shouldAddPathEntry()) {
            if (pythonpath.__contains__(filepath)) {
                throw new InvalidPluginException(new Exception("path " + filepath
                        + " already on pythonpath!")); //can't imagine how this would happen, but better safe than sorry
            }
            pythonpath.append(filepath);
        }


        String mainfile = description.getMain();
        InputStream instream = null;
        try {
            instream = data.getStream(mainfile);

            if (instream == null) {
                mainfile = "plugin.py";
                instream = data.getStream(mainfile);
            }
            if (instream == null) {
                mainfile = "main.py";
                instream = data.getStream(mainfile);
            }
        } catch (IOException e) {
            throw new InvalidPluginException(e);
        }

        if (instream == null) {
            throw new InvalidPluginException(new FileNotFoundException("Data file does not contain "+mainfile));
        }
        try {
            PythonHooks hook = new PythonHooks(description);

            PythonInterpreter interp = new PythonInterpreter();

            interp.set("hook", hook);
            interp.set("info", description);
           
            // Decorator Enhancements
            interp.exec("import __builtin__");
            interp.exec("__builtin__.hook = hook");
            interp.exec("__builtin__.info = info");
           
            // Hardcoded for now, may be worth thinking about generalizing it as sort of "addons" for the PythonPluginLoader
            // Could be used to extend the capabilities of python plugins the same way the metaclass decorators do, without requiring any changes to the PythonPluginLoader itself
            String[] pre_plugin_scripts = {"imports.py", "meta_decorators.py"};
            String[] post_plugin_scripts = {"meta_loader.py"};
           
            // Run scripts designed to be run before plugin creation
            for (String script : pre_plugin_scripts) {
              InputStream metastream = this.getClass().getClassLoader().getResourceAsStream("scripts/"+script);
              interp.execfile(metastream);
              metastream.close();
            }

            interp.execfile(instream);

            instream.close();

            try {
                if (!hasyml) {
                    Object name = interp.get("__plugin_name__");
                    Object version = interp.get("__plugin_version__");
                    Object website = interp.get("__plugin_website__");
                    Object main = interp.get("__plugin_mainclass__");
                    hassolidmeta = name != null && version != null;
                    if (name != null)
                        ReflectionHelper.setPrivateValue(description, "name", name.toString());
                    if (version != null)
                        ReflectionHelper.setPrivateValue(description, "version", version.toString());
                    if (website != null)
                        ReflectionHelper.setPrivateValue(description, "website", website.toString());
                    if (main != null)
                        ReflectionHelper.setPrivateValue(description, "main", main.toString());
                }
            } catch (Throwable t) {
                Logger.getLogger("Minecraft").log(Level.SEVERE, "Error while setting python-set description values", t);
            }

            String mainclass = description.getMain();
            PyObject pyClass = interp.get(mainclass);
            if (pyClass == null)
                pyClass = interp.get("Plugin");
            if (pyClass == null)
                result = new PythonPlugin();
            else
                result = (PythonPlugin) pyClass.__call__().__tojava__(PythonPlugin.class);
           
            interp.set("pyplugin", result);
           
            result.hooks = hook;
            result.interp = interp;
           
            // Run scripts designed to be run after plugin creation
            for (String script : post_plugin_scripts) {
              InputStream metastream = this.getClass().getClassLoader().getResourceAsStream("scripts/"+script);
              interp.execfile(metastream);
              metastream.close();
            }
           
            result.initialize(this, server, description, dataFolder, file);
            result.setDataFile(data);
           
        } catch (Throwable t) {
            if (data.shouldAddPathEntry() && pythonpath.__contains__(filepath)) {
                pythonpath.remove(filepath);
            }
            throw new InvalidPluginException(t);
        }

        if (data.getNeedsSolidMeta() && !hassolidmeta) {
View Full Code Here

        } else if (plugin instanceof PythonPlugin) {
            PythonPlugin pyplugin = (PythonPlugin) plugin;
            File pluginpath = pyplugin.getFile();
            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;

            }
View Full Code Here

    if (convertInputTuples == ConvertInputTuples.NONE) {
      // We don't need to convert the tuples
      result = tupleEntry;
    } else if (convertInputTuples == ConvertInputTuples.PYTHON_LIST) {
      // The user wants a Python list
      result = new PyList(new ConvertIterable<Object>(tupleEntry.getTuple().iterator()));
    } else if (convertInputTuples == ConvertInputTuples.PYTHON_DICT) {
      // The user wants a Python dict
      PyObject[] dictElements = new PyObject[2 * tupleEntry.size()];
      // Here we convert Java objects to Jython objects
      // http://osdir.com/ml/lang.jython.devel/2006-05/msg00022.html
View Full Code Here

    @Override
    protected SimpleFeatureType buildFeatureType() throws IOException {
        SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder();
        tb.setName(((PyString)schema.__findattr__("name")).asString());
       
        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

        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

           
            if (ret instanceof PyString) {
                getResponse().setEntity(ret.toString(), mediaType);
            }
            else if (ret instanceof PyList) {
                final PyList list = (PyList) ret;
                getResponse().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());
                            outputStream.write('\n');
                        }
                    }
                });
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

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.