Package org.python.util

Examples of org.python.util.PythonInterpreter


*/
public class JPythonInterpreter implements org.apache.flex.forks.batik.script.Interpreter {
    private PythonInterpreter interpreter = null;

    public JPythonInterpreter() {
        interpreter = new PythonInterpreter();
    }
View Full Code Here


                return;
            }
        }

        File classesDir = new File(basedir, "target/classes");
        PythonInterpreter interp = new PythonInterpreter();

        interp.exec(
        "import sys\n"+
        "sys.path.insert(0,\""+classesDir.getCanonicalPath()+"\")\n"+
        "sys.path.insert(0,\""+testDir.getCanonicalPath()+"\")\n"
        );

        try
        {
            interp.execfile(new File(testDir, "proton-test").getCanonicalPath());
        }
        catch (PyException e)
        {
            if( e.type.toString().equals("<type 'exceptions.SystemExit'>") && e.value.toString().equals("0") )
            {
View Full Code Here

            properties.setProperty("python.home", workDir.toString());
            properties.setProperty("python.packages.fakepath",
                    (String)avalonContext.get(Constants.CONTEXT_CLASSPATH));
            PythonInterpreter.initialize(System.getProperties(), properties, new String[]{});

            python = new PythonInterpreter();
            python.set("page", this);
            python.set("logger", getLogger());
            python.set("xspAttr", new AttributesImpl());
       
            if (getLogger().isDebugEnabled()) {
View Full Code Here

*/
public class JPythonInterpreter implements org.apache.batik.script.Interpreter {
    private PythonInterpreter interpreter = null;

    public JPythonInterpreter() {
        interpreter = new PythonInterpreter();
    }
View Full Code Here

        if (f.exists())
        {
            try
            {
                // We try to open the Py Interpreter
                PythonInterpreter interp = new PythonInterpreter();

                // Make sure the Py Interpreter use the right classloader
                // This is necessary for servlet engines generally has
                // their own classloader implementations and servlets aren't
                // loaded in the system classloader.  The python script will
                // load java package
                // org.apache.turbine.services.assemblerbroker.util.python;
                // the new classes to it as well.
                Py.getSystemState().setClassLoader(
                        this.getClass().getClassLoader());

                // We import the Python SYS module. Now we don't need to do this
                // explicitely in the script.  We always use the sys module to
                // do stuff like loading java package
                // org.apache.turbine.services.assemblerbroker.util.python;
                interp.exec("import sys");

                // Now we try to load the script file
                interp.execfile(confName);
                interp.execfile(fName.toString());

                try
                {
                    // We create an instance of the screen class from the
                    // python script
                    interp.exec("scr = " + name + "()");
                }
                catch (Throwable e)
                {
                    throw new Exception(
                        "\nCannot create an instance of the python class.\n"
                        + "You probably gave your class the wrong name.\n"
                        + "Your class should have the same name as your "
                        + "filename.\nFilenames should be all lowercase and "
                        + "classnames should start with a capital.\n"
                        + "Expected class name: " + name + "\n");
                }

                // Here we convert the python sceen instance to a java instance.
                assembler = (Assembler) interp.get("scr", Assembler.class);
            }
            catch (Exception e)
            {
                // We log the error here because this code is not widely tested
                // yet. After we tested the code on a range of platforms this
View Full Code Here

            })) {
              state.path.insert(1, Py.newString(basePath + "lib" + File.separator + filename));
            }
          }
        }
        PythonInterpreter interp = new PythonInterpreter(null, state);
        interp.exec(strScript);
        PyObject getInstance = interp.get("getInstance");
        if (!(getInstance instanceof PyFunction)) {
          throw new ScriptCompilationException("\"getInstance\" is not a function.");
        }
        PyObject _this;
        if (arguments == null) {
View Full Code Here

* Used internally, public for technical reasons only.
*/
public class UnlinkedJythonOperationsImpl implements UnlinkedJythonOperations {
   
    public void execute(String script, Map vars) throws BuildException {
        PythonInterpreter pi = createInterpreter(vars);
        pi.exec(script);
    }
View Full Code Here

        PythonInterpreter pi = createInterpreter(vars);
        pi.exec(script);
    }

    public void execute(File file, Map vars) throws BuildException {
        PythonInterpreter pi = createInterpreter(vars);
        try {
            pi.execfile(file.getCanonicalPath());
        } catch (IOException e) {
            throw new BuildException(e);
        }
    }
View Full Code Here

            throw new BuildException(e);
        }
    }
   
    private PythonInterpreter createInterpreter(Map vars) {
        PythonInterpreter pi = new PythonInterpreter();
        Iterator it = vars.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry ent = (Map.Entry) it.next();
            pi.set((String) ent.getKey(), ent.getValue());
        }
        return pi;
    }
View Full Code Here

            properties.setProperty("python.home", workDir.toString());
            properties.setProperty("python.packages.fakepath",
                    (String)avalonContext.get(Constants.CONTEXT_CLASSPATH));
            PythonInterpreter.initialize(System.getProperties(), properties, new String[]{});

            python = new PythonInterpreter();
            python.set("page", this);
            python.set("logger", getLogger());
            python.set("xspAttr", new AttributesImpl());
       
            if (getLogger().isDebugEnabled()) {
View Full Code Here

TOP

Related Classes of org.python.util.PythonInterpreter

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.