Package org.python.core

Examples of org.python.core.PyObject


        readTestExecutor();
        debugger = new PythonDebugger(this);
    }

    private PyObject getFixture() {
        PyObject fixture = interpreter.get("fixture");
        if (fixture == null) {
            throw new ScriptException("no fixture found for test " + filename);
        }
        return fixture;
    }
View Full Code Here


    private void readRuntime() {
        runtime = (Marathon) interpreter.get("marathon", Marathon.class);
    }

    private void readTestExecutor() {
        PyObject marathon = interpreter.get("marathon");
        PyMethod testExecutor = (PyMethod) marathon.__getattr__("execTest");
        if (testExecutor == null) {
            throw new ScriptException("no python test executor, something is wrong with the marathon runtime!");
        }
    }
View Full Code Here

    private void clearModuleDefinitions() {
        interpreterExec("import sys");
        interpreterExec("from java.awt import Color");
        PySystemState system = (PySystemState) interpreter.get("sys");
        PyStringMap modules = (PyStringMap) system.__getattr__("modules");
        PyObject builtin = modules.get(new PyString("__builtin__"));
        modules.clear();
        modules.__setitem__("__builtin__", builtin);
    }
View Full Code Here

    }

    public void runFixtureSetup() {
        invokeAndWaitForWindow(new Runnable() {
            public void run() {
                PyObject fixture = getFixture();
                try {
                    fixture.invoke("setup");
                    runMain();
                } catch (Throwable t) {
                    t.printStackTrace();
                    synchronized (PythonScript.this) {
                        PythonScript.this.notifyAll();
                    }
                }
            }
        });
        PyObject fixture = getFixture();
        if (fixture.__findattr__("test_setup") != null) {
            try {
                fixture.invoke("test_setup");
            } catch (Throwable t) {
                if (t instanceof PyException)
                    raisePythonError((PyException) t);
                throw new ScriptException("Could not invoke test_setup: " + t.getMessage());
            }
View Full Code Here

        return null;
    }

    public void setDataVariables(Properties dataVariables) {
        Set<Entry<Object, Object>> set = dataVariables.entrySet();
        PyObject builtin = interpreterEval("__builtin__");
        for (Entry<Object, Object> entry : set) {
            try {
                String key = (String) entry.getKey();
                String value = entry.getValue().toString();
                PyObject pyValue;
                if ((value.startsWith("\"") && value.endsWith("\"")) || (value.startsWith("'") || value.endsWith("'"))) {
                    value = value.substring(1, value.length() - 1);
                    pyValue = new PyString(value);
                } else {
                    try {
View Full Code Here

        className = className.substring(index + 1);
        script.interpreterExec("import sys");
        script.interpreterExec("from " + pacakgeName + " import " + className);
        script.interpreterExec("sys.settrace(PythonDebugger.traceFunction)");
        setTraceFunction(script.interpreterEval("PythonDebugger.traceFunction"));
        PyObject builtin = script.interpreterEval("__builtin__");
        PyObject acceptChecklist = script.interpreterEval("PythonDebugger.pyAcceptChecklist");
        builtin.__setattr__("__accept_checklist", acceptChecklist);
        PyObject showChecklist = script.interpreterEval("PythonDebugger.pyShowChecklist");
        builtin.__setattr__("__show_checklist", showChecklist);
    }
View Full Code Here

        listener.playbackFinished(result, false);
    }

    public static PyObject traceFunction(PyObject frame, PyObject event, PyObject arg) {
        if (debugger != null && debugger.listener != null) {
            PyObject code = frame.__getattr__("f_code");
            String methodName = code.__getattr__("co_name").toString();
            String fileName = code.__getattr__("co_filename").toString();
            int lineNo = ((PyInteger) frame.__getattr__("f_lineno")).getValue();

            debugger.trace(event.toString(), fileName, methodName, lineNo);
        }
        return traceFunction;
View Full Code Here

            }
          }
        }
        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) {
          _this = ((PyFunction) getInstance).__call__();
        } else {
          PyObject[] args = new PyObject[arguments.length];
          for (int i = 0; i < arguments.length; i++) {
            args[i] = PyJavaType.wrapJavaObject(arguments[i]);
          }
          _this = ((PyFunction) getInstance).__call__(args);
        }
        return _this.__tojava__(scriptInterfaces[0]);
      } catch (Exception ex) {
        logger.error("Error while loading script.", ex);
        if (ex instanceof IOException) {
          // Raise to caller
          throw (IOException) ex;
View Full Code Here

                if (!key.startsWith("__") && !key.equals("schemaFunction")
                        && !key.equals("outputSchema")
                        && !key.equals("outputSchemaFunction")
                        && (value instanceof PyFunction)
                        && (((PyFunction)value).__findattr__("schemaFunction")== null)) {
                    PyObject obj = ((PyFunction)value).__findattr__("outputSchema");
                    if(obj != null) {
                        Utils.getSchemaFromString(obj.toString());
                    }
                    funcspec = new FuncSpec(JythonFunction.class.getCanonicalName() + "('"
                            + path + "','" + key +"')");
                    pigContext.registerFunction(namespace + key, funcspec);
                    LOG.info("Register scripting UDF: " + namespace + key);
View Full Code Here

  public static <W extends Writable> JythonColumnWriter<W>
  create(ImmutableClassesGiraphConfiguration conf,
      StrConfOption jythonClassOption, StrConfOption columnOption,
      HiveTableSchema schema) {
    String className = jythonClassOption.get(conf);
    PyObject pyClass = JythonUtils.getInterpreter().get(className);
    JythonHiveWriter jythonColumnWritable = (JythonHiveWriter)
        pyClass.__call__().__tojava__(JythonHiveWriter.class);
    int columnIndex = HiveUtils.columnIndexOrThrow(schema, conf, columnOption);
    return new JythonColumnWriter<W>(columnIndex, jythonColumnWritable);
  }
View Full Code Here

TOP

Related Classes of org.python.core.PyObject

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.