Package org.python.util

Examples of org.python.util.PythonInterpreter


        if(testPattern != null)
        {
            systemState.argv.append(new PyString(testPattern));
        }

        PythonInterpreter interp = new PythonInterpreter(null, systemState);
        return interp;
    }
View Full Code Here


                            // solve import statements.
                            PySystemState.add_extdir(jarDir);
                        }
                    }

                    PythonInterpreter interpreter = new PythonInterpreter();
                    interpreter.exec(script);
                    return null;
                }
            });
        } catch (PrivilegedActionException e) {
            logger.error(e.getMessage(), e);
View Full Code Here

    public void registerFunctions(String path, String namespace, PigContext pigContext)
    throws IOException {
        Interpreter.setMain(false);
        Interpreter.init(path, pigContext);
        pigContext.scriptJars.add(getJarPath(PythonInterpreter.class));
        PythonInterpreter pi = Interpreter.interpreter;
        @SuppressWarnings("unchecked")
        List<PyTuple> locals = ((PyStringMap) pi.getLocals()).items();
        namespace = (namespace == null) ? "" : namespace + NAMESPACE_SEPARATOR;
        try {
            for (PyTuple item : locals) {
                String key = (String) item.get(0);
                Object value = item.get(1);
View Full Code Here

     * The main thread for this class invoked by Thread.run()
     *
     * @see java.lang.Thread#run()
     */
    public void run() {
        PythonInterpreter p = new PythonInterpreter();
        for (String name : this.locals.keySet()) {
            p.set(name, this.locals.get(name));
        }

        URL jarUrl = JythonServer.class.getProtectionDomain().getCodeSource().getLocation();
        String jarPath = jarUrl.getPath();
        if (jarUrl.getProtocol().equals("file")) {
            // If URL is of type file, assume that we are in dev env and set path to python dir.
            // else use the jar file as is
            jarPath = jarPath + "../../src/main/python/";
        }

        p.exec("import sys");
        p.exec("sys.path.append('" + jarPath + "')");
        p.exec("from debugserver import run_server");
        if (this.host == null) {
          p.exec("run_server(port=" + this.port + ", locals=locals())");
        } else {
          p.exec("run_server(port=" + this.port + ", host='" + this.host + "', locals=locals())");
        }
    }
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

    public JythonLineMapper(String pythonCode, String recordMapperSymbol) {
        this(pythonCode, recordMapperSymbol, new PrintWriter(System.err));
    }

    public JythonLineMapper(String pythonCode, String recordMapperSymbol, Writer stderrWriter) {
        interpreter = new PythonInterpreter();
        interpreter.setErr(stderrWriter);

        // TODO Should we (or can we) restrict what can be done here?
        interpreter.exec(pythonCode);
        mapperCallable = interpreter.get(recordMapperSymbol);
View Full Code Here

            }
         
          @Override
          public void init()
            {
            pi = new PythonInterpreter();
            pi.set("numPrimes", 0L);
            pi.set("num", num);
            py = readFileAsString("resource/test/primes.py");
            pycode = pi.compile(py);
            }
View Full Code Here

            }
         
          @Override
          public void init()
            {
            pi = new PythonInterpreter();
            pi.set("numPrimes", 0L);
            pi.set("num", num);
            py = readFileAsString("resource/test/primes.py");
            }
        });
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.