Esempio n. 1
0
        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";
            }
        }
Esempio n. 2
0
 /// <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);
     }
 }
Esempio n. 3
0
 //TODO excValue may be null.
 public PyException(PyObject excType, PyObject excValue, PyObject excTraceback)
     : this(excType, excValue, excTraceback, null)
 {
 }
Esempio n. 4
0
        /// <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);
            }
        }