public PyException(PyObject excType, PyObject excValue, PyObject excTraceback, Exception inner) : base(excValue.ToString(), inner) { ExcType = excType; ExcValue = excValue; ExcTraceback = excTraceback; if (ExcTraceback != null) { //TODO unittest stacktrace creation? var tracebackModule = excTraceback.Api.PyImport_AddModule("traceback"); var formatExcFunc = new PyObject(excTraceback.Api, tracebackModule).GetAttr("format_exception"); var tbList = formatExcFunc.Call(excType, excValue, excTraceback); //TODO join tblist with \n _pyTraceback = "NotImplemented"; } }
/// <summary> /// Set attribute of PyObject instance. /// Equivalent to python setattr function. /// </summary> /// <param name="attr">attribute name.</param> /// <param name="value">the attribute value.</param> public void SetAttr(string attr, PyObject value) { IntPtr gil = BeginSafeMethod(); try { int result = Api.PyObject_SetAttrString(PyObjectPtr, attr, value.PyObjectPtr); _pyUtils.ThrowExcIf(() => result == -1); } finally { EndSafeMethod(gil); } }
//TODO excValue may be null. public PyException(PyObject excType, PyObject excValue, PyObject excTraceback) : this(excType, excValue, excTraceback, null) { }
/// <summary> /// Check if the instance is instance of the specified pyObject. /// Equivalent to the python "isinstance" function. /// </summary> /// <param name="pyObject">isinstance of this param.</param> /// <returns>isinstance result</returns> public bool IsInstance(PyObject pyObject) { if (pyObject.Api != Api) { throw new InCompatibleInterpretersException(); } IntPtr gil = BeginSafeMethod(); try { int result = Api.PyObject_IsInstance(PyObjectPtr, pyObject.PyObjectPtr); _pyUtils.ThrowExcIf(() => result == -1); return result != 0; } finally { EndSafeMethod(gil); } }