Package org.python.util

Examples of org.python.util.PythonInterpreter.exec()


        "def outside_add_squared(foo, x):\n" +
        "    foo.do_add_squared(x)\n" +
        "\n";

    PythonInterpreter interpreter = new PythonInterpreter();
    interpreter.exec(jython);

    PyObject fooClass = interpreter.get("Foo");
    assertTrue(fooClass instanceof PyClass);
    PyObject foo = fooClass.__call__();
View Full Code Here


            "             raise Checked()\n" +
            "         else:\n" +
            "             raise Throwable()\n" +
            "r = Raiser()";
        PythonInterpreter interp = new PythonInterpreter();
        interp.exec(raiser);
        t = Py.tojava(interp.get("r"), Thrower.class);
    }

    public void testRaisingCheckedException() {
        try {
View Full Code Here

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

            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"};
View Full Code Here

            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"};
View Full Code Here

        String expr = "x+5";

        // Evaluate some arbitrary strings
        System.out.println(expr+" = "+interp.eval(expr));    
        interp.exec("y = 'foo'");

        // Get a string back from the namespace
        Object y = Py.tojava(interp.get("y"), Object.class);

        System.out.println("y = "+y);
View Full Code Here

      for (final Entry<String, Object> binding : bindings.entrySet())
      {
        interpreter.set(binding.getKey(), binding.getValue());
      }

      interpreter.exec(script);
      returnValue = interpreter.get("result");
    }
    catch (final Exception e)
    {
      exception = e;
View Full Code Here

    }
   
    try {
      ArrayList<String> source = script.getSource();
      for (String pycode : source) {
        pi.exec(pycode);
     
      script.setStatus(ScriptStatus.PASS);
    } catch (Exception ex) {
      script.setStatus(ScriptStatus.FAIL);
      String rootCauseMsg = StringEscapeUtils.escapeXml(ExceptionUtils.getRootCauseStackTrace(ex)[0]);
View Full Code Here

                }
                PythonInterpreter pi = (PythonInterpreter) model.getObject();
                ByteArrayOutputStream out = new ByteArrayOutputStream();
                pi.setOut(out);
                try {
                    pi.exec(line);
               }
                catch( PyException pe ) {
                    pe.printStackTrace(new PrintWriter(out, true));
                }
                output += "\n";
View Full Code Here

    public static void setUpData() throws Exception {
        DeleteDbFiles.execute("target", "foobar", true);
       
        GeoServerResourceLoader loader = new GeoServerResourceLoader(new File("target"));
        PythonInterpreter pi = new Python(loader).interpreter();
        pi.exec("from geoscript.workspace import H2");
        pi.exec("from geoscript.geom import Point");
        pi.exec("h2 = H2('foobar', 'target')");
        pi.exec("l = h2.create('bar', [('geom', Point, 'epsg:4326'), ('baz', str)])");
        pi.exec("l.add([Point(10,10), 'ten'])");
        pi.exec("l.add([Point(20,20), 'twenty'])");
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.