Package org.python.core

Examples of org.python.core.PyObject$ConversionException


        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

                        }
                    }
                }
            } catch (PyException e) {
                if (e.match(Py.SystemExit)) {
                    PyObject value = e.value;
                    if (PyException.isExceptionInstance(e.value)) {
                        value = value.__findattr__("code");
                    }
                    if (new  PyInteger(0).equals(value)) {
                        LOG.info("Script invoked sys.exit(0)");
                        return;
                    }
View Full Code Here

                    Object loader = null;
                    if (value instanceof PyJavaPackage ) {
                        fileEntry = ((PyJavaPackage) value).__file__;
                    } else if (value instanceof PyObject) {
                        // resolved through the filesystem (or built-in)
                        PyObject dict = ((PyObject) value).getDict();
                        if (dict != null) {
                            fileEntry = dict.__finditem__("__file__");
                            loader = dict.__finditem__("__loader__");
                        } // else built-in
                    }   // else some system module?

                    if (fileEntry != null) {
                        File file = resolvePyModulePath(fileEntry.toString(), loader);
View Full Code Here

      InputStream ... streams) {
    for (InputStream stream : streams) {
      readJythonStream(interpreter, stream);
    }

    PyObject pyPrepare = interpreter.get("prepare");

    JythonJob jythonJob = new JythonJob();
    pyPrepare._jcall(new Object[]{jythonJob});

    return jythonJob;
  }
View Full Code Here

      checkImplements(langType, writableClass, interpreter);
      return langType.getJavaClass();
    case JYTHON:
      GRAPH_TYPE_LANGUAGES.set(conf, graphType, Language.JYTHON);
      String jythonClassName = langType.getJythonClassName();
      PyObject jythonClass = interpreter.get(jythonClassName);
      if (jythonClass == null) {
        throw new IllegalArgumentException("Could not find Jython class " +
            jythonClassName + " for parameter " + graphType);
      }
      PyObject valuePyObj = jythonClass.__call__();

      // Check if the Jython type implements Writable. If so, just use it
      // directly. Otherwise, wrap it in a class that does using pickle.
      Object pyWritable = valuePyObj.__tojava__(writableClass);
      if (pyWritable.equals(Py.NoConversion)) {
        GiraphConstants.GRAPH_TYPES_NEEDS_WRAPPERS.set(conf, graphType, true);
        jythonFactory.useThisFactory(conf, jythonClassName);
        return JythonWritableWrapper.class;
      } else {
View Full Code Here

TOP

Related Classes of org.python.core.PyObject$ConversionException

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.