public object executescript(CodeContext context, [ParamDictionary] IDictionary <object, object> kwargs, params object[] args) { object c = cursor(context, null); object executescript = context.LanguageContext.Operations.GetMember(c, "executescript"); return(PythonCalls.CallWithKeywordArgs(context, executescript, args, kwargs)); }
public void stepCallback(Sqlite3.sqlite3_context ctx, int argc, sqlite3_value[] param) { if (instance == null) { try { instance = PythonCalls.Call(context, aggregate_class); } catch (Exception) { Sqlite3.sqlite3_result_error(ctx, "user-defined aggregate's '__init__' method raised error", -1); return; } } try { object step = context.LanguageContext.Operations.GetMember(instance, "step"); object[] args = buildPyParams(context, ctx, argc, param); PythonCalls.CallWithKeywordArgs(context, step, args, new Dictionary <object, object>()); } catch (Exception e) { if (e is MissingMemberException) { throw; } Sqlite3.sqlite3_result_error(ctx, "user-defined aggregate's 'step' method raised error", -1); } }
PyObject_Call(IntPtr objPtr, IntPtr argsPtr, IntPtr kwargsPtr) { try { object obj = this.Retrieve(objPtr); PythonDictionary builtins = this.GetModule("__builtin__").Get__dict__(); if (obj == TypeCache.PythonFile || obj == builtins["open"]) { obj = this.cFileClass; } object[] argsArray = null; if (argsPtr == IntPtr.Zero) { argsArray = new object[0]; } else { ICollection args = (ICollection)this.Retrieve(argsPtr); argsArray = new object[args.Count]; args.CopyTo(argsArray, 0); } if (obj == builtins["__import__"]) { // I really, really wish that Pyrex used the C API for importing things, // instead of PyObject_Call __import__. However, it doesn't, so I have to // do this. // This is only tested in functionalitytest -- if h5's pyd submodules each // have their own copy of _sync, this bit is broken. if (kwargsPtr != IntPtr.Zero) { throw new NotImplementedException("Someone tried to PyObject_Call __import__ with non-null kwargs."); } return(this.DoFoulImportHack(argsArray)); } object result = null; if (kwargsPtr == IntPtr.Zero) { result = PythonCalls.Call(obj, argsArray); } else { PythonDictionary kwargs = (PythonDictionary)this.Retrieve(kwargsPtr); result = PythonCalls.CallWithKeywordArgs(this.scratchContext, obj, argsArray, kwargs); } return(this.Store(result)); } catch (Exception e) { this.LastException = e; return(IntPtr.Zero); } }
protected override int Run() { if (Options.ModuleToRun != null) { // PEP 338 support - http://www.python.org/dev/peps/pep-0338 // This requires the presence of the Python standard library or // an equivalent runpy.py which defines a run_module method. // import the runpy module object runpy, runMod; try { runpy = Importer.Import( PythonContext.SharedContext, "runpy", PythonTuple.EMPTY, 0 ); } catch (Exception) { Console.WriteLine("Could not import runpy module", Style.Error); return(-1); } // get the run_module method try { runMod = PythonOps.GetBoundAttr(PythonContext.SharedContext, runpy, "run_module"); } catch (Exception) { Console.WriteLine("Could not access runpy.run_module", Style.Error); return(-1); } // call it with the name of the module to run try { PythonCalls.CallWithKeywordArgs( PythonContext.SharedContext, runMod, new object[] { Options.ModuleToRun, "__main__", ScriptingRuntimeHelpers.True }, new string[] { "run_name", "alter_sys" } ); } catch (SystemExitException e) { return(GetEffectiveExitCode(e)); } return(0); } int result = base.Run(); // Check if IRONPYTHONINSPECT was set during execution string inspectLine = Environment.GetEnvironmentVariable("IRONPYTHONINSPECT"); if (inspectLine != null && !Options.Introspection) { result = RunInteractiveLoop(); } return(result); }
public object Call(CodeContext context, [ParamDictionary] IDictionary <object, object> dict, params object[] args) { object targetMethod; if (!DynamicHelpers.GetPythonType(target.Target).TryGetBoundMember(context, target.Target, name, out targetMethod)) { throw PythonOps.AttributeError("type {0} has no attribute {1}", DynamicHelpers.GetPythonType(target.Target), name); } return(PythonCalls.CallWithKeywordArgs(context, targetMethod, args, dict)); }
public object Call(CodeContext /*!*/ context, object param) { object method = PythonOps.GetBoundAttr(context, param, _name); if (_dict == null) { return(PythonOps.CallWithContext(context, method, _args)); } else { return(PythonCalls.CallWithKeywordArgs(context, method, _args, _dict)); } }
public object Call(CodeContext context, [ParamDictionary] IDictionary <object, object> dict, params object[] args) { ValidateArgs(args); if (_inst != null) { return(PythonCalls.CallWithKeywordArgs(context, _func, ArrayUtils.Insert(_inst, args), dict)); } else { return(PythonCalls.CallWithKeywordArgs(context, _func, args, dict)); } }
public object Call(CodeContext context, [ParamDictionary] IDictionary <object, object> dict\u00F8, [NotNull] params object[] args\u00F8) { OldInstance inst = new OldInstance(context, this); object meth; if (PythonOps.TryGetBoundAttr(inst, "__init__", out meth)) { PythonCalls.CallWithKeywordArgs(context, meth, args\u00F8, dict\u00F8); } else if (dict\u00F8.Count > 0 || args\u00F8.Length > 0) { MakeCallError(); } return(inst); }
private static void callUserFunction(Sqlite3.sqlite3_context ctx, int argc, sqlite3_value[] argv) { object[] data = (object[])Sqlite3.sqlite3_user_data(ctx); CodeContext context = (CodeContext)data[0]; object func = data[1]; object[] args = buildPyParams(context, ctx, argc, argv); try { object result = PythonCalls.CallWithKeywordArgs(context, func, args, emptyKwargs); setResult(ctx, result); } catch (Exception) { Sqlite3.sqlite3_result_error(ctx, "user-defined function raised exception", -1); } }
public object __call__(CodeContext /*!*/ context, [ParamDictionary] IDictionary <object, object> dict, params object[] args) { return(PythonCalls.CallWithKeywordArgs(context, this, args, dict)); }
internal override object CreateInstance(CodeContext context, object[] args, string[] names) { return(PythonCalls.CallWithKeywordArgs(context, Type.Ctor, args, names)); }