Package org.python.core

Examples of org.python.core.PyObject


                        }
                    }
                }
            } 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

      checkArgument(interfaceClass.isAssignableFrom(langType.getJavaClass()),
          langType.getJavaClass().getSimpleName() + " needs to implement " +
          interfaceClass.getSimpleName());
      break;
    case JYTHON:
      PyObject pyClass = interpreter.get(langType.getJythonClassName());
      PyObject pyObj = pyClass.__call__();
      Object converted = pyObj.__tojava__(interfaceClass);
      checkArgument(!Py.NoConversion.equals(converted),
         "Jython class " + langType.getJythonClassName() +
         " does not implement " + interfaceClass.getSimpleName() +
         " interface");
      break;
View Full Code Here

   * @param interpreter PythonInterpreter
   * @return language and type specification
   */
  private static LanguageAndType processJythonType(String jythonName,
      PythonInterpreter interpreter) {
    PyObject pyClass = interpreter.get(jythonName);
    checkNotNull(pyClass, "Jython class " + jythonName + " not found");
    return LanguageAndType.jython(jythonName);
  }
View Full Code Here

   */
  public static <T extends Writable> JythonColumnReader<T>
  create(ImmutableClassesGiraphConfiguration conf,
      StrConfOption jythonClassOption, StrConfOption columnOption,
      HiveTableSchema schema) {
    PyObject pyClass =
        JythonUtils.getInterpreter().get(jythonClassOption.get(conf));
    JythonHiveReader jythonHiveReader = (JythonHiveReader)
        pyClass.__call__().__tojava__(JythonHiveReader.class);
    int columnIndex = HiveUtils.columnIndexOrThrow(schema, conf, columnOption);
    return new JythonColumnReader<T>(columnIndex, jythonHiveReader);
  }
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] = new PyJavaInstance(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

     */
    public TemplateCollectionModel keys() throws TemplateModelException
    {
        try
        {
            PyObject method = object.__findattr__(KEYS);
            if(method == null)
            {
                method = object.__findattr__(KEYSET);
            }
            if(method != null)
            {
                return (TemplateCollectionModel)wrapper.wrap(method.__call__());
            }
        }
        catch(PyException e)
        {
            throw new TemplateModelException(e);
View Full Code Here

     */
    public TemplateCollectionModel values() throws TemplateModelException
    {
        try
        {
            PyObject method = object.__findattr__(VALUES);
            if(method != null)
            {
                return (TemplateCollectionModel)wrapper.wrap(method.__call__());
            }
        }
        catch(PyException e)
        {
            throw new TemplateModelException(e);
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.