Package org.python.core

Examples of org.python.core.PyObject$ConversionException


    public PyDictionary getGlobals(String text)
    {
        PyModule module = new PyModule( "main",
                                        new PyDictionary( ) );

        PyObject locals = module.__dict__;      

        Py.exec( Py.compile_flags( text,
                                   "<string>",
                                   "exec",
                                   null ),
View Full Code Here


    /**
     * Creates and returns an instance of the robot.JarRunner (implemented in
     * Python), which can be used to execute tests.
     */
    public RobotRunner createRunner() {
        PyObject runnerObject = runnerClass.__call__();
        return (RobotRunner) runnerObject.__tojava__(RobotRunner.class);
    }
View Full Code Here

        try {
            f = JythonScriptEngine.getFunction(filename, functionName);
            this.function = f;
            num_parameters = ((PyBaseCode) f.func_code).co_argcount;
            PyObject outputSchemaDef = f.__findattr__("outputSchema".intern());
            if (outputSchemaDef != null) {
                this.schema = Utils.getSchemaFromString(outputSchemaDef.toString());
                found = true;
            }
            PyObject outputSchemaFunctionDef = f.__findattr__("outputSchemaFunction".intern());
            if (outputSchemaFunctionDef != null) {
                if(found) {
                    throw new ExecException(
                            "multiple decorators for " + functionName);
                }
                scriptFilePath = filename;
                outputSchemaFunc = outputSchemaFunctionDef.toString();
                this.schema = null;
                found = true;
            }
            PyObject schemaFunctionDef = f.__findattr__("schemaFunction".intern());
            if (schemaFunctionDef != null) {
                if(found) {
                    throw new ExecException(
                            "multiple decorators for " + functionName);
                }
View Full Code Here

    @Override
    public Object exec(Tuple tuple) throws IOException {
        try {
            if (tuple == null || num_parameters == 0) {
                // ignore input tuple
                PyObject out = function.__call__();
                return JythonUtils.pythonToPig(out);
            }
            else {
                // this way we get the elements of the tuple as parameters instead
                // of one tuple object
View Full Code Here

            if(outputSchemaFunc != null) {
                PyFunction pf;
                try {
                    pf = JythonScriptEngine.getFunction(scriptFilePath, outputSchemaFunc);
                    // this should be a schema function
                    PyObject schemaFunctionDef = pf.__findattr__("schemaFunction".intern());
                    if(schemaFunctionDef == null) {
                        throw new IllegalStateException("Function: "
                                + outputSchemaFunc + " is not a schema function");
                    }
                    return (Schema)((pf.__call__(Py.java2py(input))).__tojava__(Object.class));
View Full Code Here

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

    _interpreter = new PythonInterpreter();
    _interpreter.exec("import sys;");
    _interpreter.exec("sys.path.append('" + new File("lib").getAbsolutePath() + "')");
    _interpreter.exec("sys.path.append('" + new File("lib", "external").getAbsolutePath() + "')");
        _interpreter.exec("from " + pythonPackage + " import " + pythonClass);
        PyObject serviceClass = _interpreter.get(pythonClass);
        PyObject implObj = serviceClass.__call__();
        _impl = (JavaServiceI)implObj.__tojava__(JavaServiceI.class);
       
        _impl.init(config);
       
        _interpreter.exec("print sys.path");
  }
View Full Code Here

            python.execfile(scriptResource.getInputStream());
        } catch (IOException e) {
            throw new IllegalArgumentException("Couldn't run python script, " + script, e);
        }

        PyObject allowed = python.get("allow");

        if (allowed == null) {
            throw new IllegalStateException("Python script did not set the permit flag");
        }
View Full Code Here

      boolean result = evalPredicate(interp, predicate);
      return result;
    }
   
    protected boolean evalPredicate(PythonInterpreter interp, String predicate) {
      PyObject pyResult = interp.eval(predicate);
      Boolean resultObj = (Boolean) pyResult.__tojava__(Boolean.class);
      boolean result = resultObj.booleanValue();
      return result;
    }
View Full Code Here

            }
            if (message == null) {
                if (pe.type instanceof PyClass) {
                    String errorName = null, errorValue;
                    try {
                        PyObject doc = pe.value.__getattr__(new PyString("__doc__"));
                        if (doc != Py.None) {
                            errorName = doc.toString();
                            if (errorName.endsWith(".")) {
                                errorName = errorName.substring(0, errorName.length() - 1);
                            }
                        }
                    } catch (PyException pye) {
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.