public PyException(IntPtr type, IntPtr value, IntPtr traceback) { TypeObject = new PyObject(type); ValueObject = new PyObject(value); TracebackObject = new PyObject(traceback); TypeObject.IncRef(); ValueObject.IncRef(); TracebackObject.IncRef(); Type = TypeObject.GetString("__name__"); if (ValueObject.IsString) { Value = PyString.GetValueInternal(ValueObject.Pointer); } else if (ValueObject.HasAttr("message")) { Value = ValueObject.GetString("message"); } else // use Py_Repr to atleast get some information { Value = ValueObject.ToString(); } CallStack = new List <PyTraceback>(5); var cur = TracebackObject; while (cur != null && cur.IsValid && !cur.IsNone) { CallStack.Add(new PyTraceback(cur)); cur = cur.Get("tb_next"); } }
protected void Initialize() { if (!Initialized) { Module = new PyObject(Python.InitModule(Name, Methods.ToArray()), ReferenceType.Borrowed); Module.IncRef(); Initialized = true; } }
public PyCode(PyObject code) { _code = code; code.IncRef(); RawBytecode = code.GetRaw("co_code"); Name = code.GetString("co_name"); File = code.GetString("co_filename"); Bytecode = new PyBytecode(this); }
internal PyTraceback(PyObject trace) { _trace = trace; trace.IncRef(); }
internal PyStackFrame(PyObject frame) { _frame = frame; frame.IncRef(); }