Examples of PyFunction


Examples of org.python.core.PyFunction

    private int num_parameters;
    private String scriptFilePath;
    private String outputSchemaFunc;
   
    public JythonFunction(String filename, String functionName) throws IOException{
        PyFunction f;
        boolean found = false;

        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

Examples of org.python.core.PyFunction

    public Schema outputSchema(Schema input) {
        if(schema != null) {
            return schema;
        } else {
            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));
                } catch (IOException ioe) {
                    throw new IllegalStateException("Could not find function: "
                        + outputSchemaFunc + "()");
                }
            } else {
View Full Code Here

Examples of org.python.core.PyFunction

    private int num_parameters;
    private String scriptFilePath;
    private String outputSchemaFunc;
   
    public JythonFunction(String filename, String functionName) throws IOException{
        PyFunction f;
        boolean found = false;

        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());
                logOnce("Schema '"+outputSchemaDef.toString()+"' defined for func "+functionName);
                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();
                logOnce("Schema Function '"+outputSchemaFunc+"' defined for func "+functionName);
                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

Examples of org.python.core.PyFunction

    public Schema outputSchema(Schema input) {
        if(schema != null) {
            return schema;
        } else {
            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");
                    }
                    Object newSchema = ((pf.__call__(Py.java2py(input))).__tojava__(Object.class));
                    if (newSchema instanceof ResourceSchema) {
                        return(Schema.getPigSchema((ResourceSchema) newSchema));
                    }
                    else if (newSchema instanceof Schema) {
                        return (Schema) newSchema;
View Full Code Here

Examples of org.python.core.PyFunction

        return moduleList.getRoot();
    }

    public String[][] getArgumentsFor(DefaultMutableTreeNode node) {
        String fName = (String) node.getUserObject();
        PyFunction function = (PyFunction) interpreterEval(fName);
        int argcount = ((PyTableCode) function.func_code).co_argcount;
        String[] arguments = new String[argcount];
        String[] varNames = ((PyTableCode) function.func_code).co_varnames;
        for (int i = 0; i < argcount; i++) {
            arguments[i] = varNames[i];
View Full Code Here

Examples of org.python.core.PyFunction

    private int num_parameters;
    private String scriptFilePath;
    private String outputSchemaFunc;
   
    public JythonFunction(String filename, String functionName) throws IOException{
        PyFunction f;
        boolean found = false;

        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

Examples of org.python.core.PyFunction

    public Schema outputSchema(Schema input) {
        if(schema != null) {
            return schema;
        } else {
            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));
                } catch (IOException ioe) {
                    throw new IllegalStateException("Could not find function: "
                        + outputSchemaFunc + "()", ioe);
                }
            } else {
View Full Code Here

Examples of org.python.core.PyFunction

        }
        return null;
    }
   
    PyFunction createStartResponse() {
        return new PyFunction(new PyStringMap(), new PyObject[]{}, Py.newJavaCode(getClass(), "start_response"));
    }
View Full Code Here

Examples of org.python.core.PyFunction

        }
        if (!(app instanceof PyFunction)) {
            throw new RestletException("'app' must be a function", Status.SERVER_ERROR_INTERNAL);
        }
       
        PyFunction appf = (PyFunction) app;
        PyFunction start_response = createStartResponse();
       
        WSGIResponse wr = new WSGIResponse();
        response.set(wr);
       
        PyObject ret = appf.__call__(new PyObject[]{createEnviron(getRequest()), start_response });
View Full Code Here

Examples of org.python.core.PyFunction

        PyType type = type();
       
        PythonInterpreter pi = py.interpreter();
        pi.exec("from inspect import getargspec");
       
        PyFunction getargspec = (PyFunction) pi.get("getargspec");
        PyObject init =  type.__getattr__("__init__");
       
        PySequence argspec =
            (PySequence) getargspec.__call__(init.__getattr__("wrapped")).__getitem__(0);
        PyDictionary params = (PyDictionary) init.__getattr__("params");
       
        List<Param> list = new ArrayList();
        for (Object item : (Collection) argspec) {
            String pname = item.toString();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.