public Object invoke(Object... args) throws Exception { PyObject[] pyArgs = new PyObject[args.length]; for (int i = 0; i < args.length; i++) pyArgs[i] = Py.java2py(args[i]); PyObject pyResult = fn.__call__(pyArgs); if (pyResult == null) return null; // todo: number conversions should be handled higher up in the code, and not at the Jython level. if (pyResult instanceof PyLong || pyResult instanceof PyInteger) return pyResult.__tojava__(Long.class); Object result = pyResult.__tojava__(Object.class); if (result == Py.NoConversion) throw new RuntimeException("Cannot convert Python object " + pyResult + " to java."); return result; }
PyFunction handler = new PyFunction(new PyStringMap(), null, codeobj);
pf = JythonScriptEngine.getFunction(scriptFilePath, outputSchemaFunc); 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));
PyFunction findDecoratedFunction(ScriptEngine engine, String name) { Bindings bindings = engine.getBindings(ScriptContext.ENGINE_SCOPE); for (Object o : bindings.values()) { if (o instanceof PyFunction) { PyFunction f = (PyFunction) o; PyObject d = f.__findattr__("__decorator__"); if (d instanceof PyFunction && name.equals(((PyFunction) d).__name__)) { return f; } } } return null; }
@Deprecated @ExposedDelete(name = "func_closure") public void delFuncClosure() { delClosure(); }
@Deprecated @ExposedDelete(name = "func_defaults") public void delFuncDefaults( ) { delDefaults(); }
/** * Checks rule event condition by evaluating the defined knowledge base rule method. * * @param rule rule. * @param event event. * @return {@code true} if this condition is met. */ @Override public boolean condition(Rule rule, Event event) { PyObject pyObject = function._jcall(new Object[] { rule, event }); if (!(pyObject instanceof PyBoolean)) { throw new IllegalArgumentException("Condition method must return boolean value"); } return ((PyBoolean) pyObject).getBooleanValue(); } }
&& !key.equals("outputSchemaFunction") && (value instanceof PyFunction) && (((PyFunction)value).__findattr__("schemaFunction")== null)) { PyObject obj = ((PyFunction)value).__findattr__("outputSchema"); if(obj != null) { Utils.getSchemaFromString(obj.toString());
@Override public PyObject __call__(ThreadState state, PyObject[] args) { return __call__(state, args, Py.NoKeywords); }
/** Creates the start_response object. */ PyFunction createStartResponse() { return new PyFunction( new PyStringMap(), new PyObject[] {}, Py.newJavaCode(getClass(), "start_response")); }
this.function = f; num_parameters = ((PyBaseCode) f.__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) { found = true; PyObject schemaFunctionDef = f.__findattr__("schemaFunction".intern()); if (schemaFunctionDef != null) { if(found) {
@Override public PyObject __call__(PyObject arg0, PyObject arg1, PyObject arg2, PyObject arg3) { return __call__(Py.getThreadState(), arg0, arg1, arg2, arg3); }
public static PyObject makeManager(PyObject object) { if (object instanceof PyFunction) { PyFunction function = (PyFunction) object; PyCode code = function.__code__; if (code instanceof PyBaseCode) { PyBaseCode pyCode = (PyBaseCode) code; if (pyCode.co_flags.isFlagSet(CodeFlag.CO_GENERATOR)) { return new PyFunction(function.__globals__, function.__defaults__, new ContextCode(pyCode), function.__doc__, (function.__closure__ == null) ? null : ((PyTuple)function.__closure__).getArray()); } } } throw Py.TypeError("Argument must be a generator function."); }
@Override public PyObject __call__(PyObject arg1, PyObject arg2) { return __call__(Py.getThreadState(), arg1, arg2); }
PyFunction function = new PyFunction(globals, defaults == Py.None ? null : ((PyTuple)defaults).getArray(),
@Override public PyObject __call__(PyObject arg1, PyObject[] args, String[] keywords) { return __call__(Py.getThreadState(), arg1, args, keywords); }
doc = ((PyBytecode) code).co_consts[0]; PyFunction func = new PyFunction(f.f_globals, defaults, code, doc); stack.push(func); break; doc = ((PyBytecode) code).co_consts[0]; PyFunction func = new PyFunction(f.f_globals, defaults, code, doc, closure_cells); stack.push(func); break;
@Override public PyObject __call__(PyObject[] args) { return __call__(Py.getThreadState(), args); }
Object call(PyFunction f, Object... args) { PyObject[] pyargs = new PyObject[args.length]; for (int i = 0; i < args.length; i++) { pyargs[i] = Py.java2py(args[i]); } return f.__call__(pyargs); } }
@Override public PyObject __call__() { return __call__(Py.getThreadState()); }