+
+static PyObject *get_StringIO_instance(void)
+{
+ PyObject *module_StringIO = NULL;
+ PyObject *class_StringIO = NULL;
+ PyObject *inst_StringIO = NULL;
+
+ module_StringIO = PyImport_ImportModule("cStringIO");
+ if(!module_StringIO) {
+ debug_print("Error getting traceback: Could not import module cStringIO\n");
+ goto done;
+ }
+
+ class_StringIO = PyObject_GetAttrString(module_StringIO, "StringIO");
+ if(!class_StringIO) {
+ debug_print("Error getting traceback: Could not get StringIO class\n");
+ goto done;
+ }
+
+ inst_StringIO = PyObject_CallObject(class_StringIO, NULL);
+ if(!inst_StringIO) {
+ debug_print("Error getting traceback: Could not create an instance of the StringIO class\n");
+ goto done;
+ }
+
+done:
+ Py_XDECREF(module_StringIO);
+ Py_XDECREF(class_StringIO);
+
+ return inst_StringIO;
+}
+
+static char* get_exception_information(PyObject *inst_StringIO)
+{
+ char *retval = NULL;
+ PyObject *meth_getvalue = NULL;
+ PyObject *result_getvalue = NULL;
+
+ if(!inst_StringIO)
+ goto done;
+
+ if(PySys_SetObject("stderr", inst_StringIO) != 0) {
+ debug_print("Error getting traceback: Could not set sys.stderr to a StringIO instance\n");
+ goto done;
+ }
+
+ meth_getvalue = PyObject_GetAttrString(inst_StringIO, "getvalue");
+ if(!meth_getvalue) {
+ debug_print("Error getting traceback: Could not get the getvalue method of the StringIO instance\n");
+ goto done;
+ }
+
+ PyErr_Print();
+
+ result_getvalue = PyObject_CallObject(meth_getvalue, NULL);
+ if(!result_getvalue) {
+ debug_print("Error getting traceback: Could not call the getvalue method of the StringIO instance\n");
+ goto done;
+ }
+
+ retval = g_strdup(PyString_AsString(result_getvalue));
+
+done:
+
+ Py_XDECREF(meth_getvalue);
+ Py_XDECREF(result_getvalue);
+
+ return retval ? retval : g_strdup("Unspecified error occured");
+}
+
+