comparison Python/pythonrun.c @ 6322:05d943c4597c legacy-trunk

PyErr_Print(): When printing a class exception, try to dig out the __module__ string and if found, print <module>.<class>, unless <module> == "exceptions".
author Barry Warsaw <barry@python.org>
date Tue, 16 Sep 1997 21:42:03 +0000
parents 4cf20fa883a9
children dfeaf965f48a
comparison
equal deleted inserted replaced
6321:913cd1f373be 6322:05d943c4597c
743 } 743 }
744 if (err) { 744 if (err) {
745 /* Don't do anything else */ 745 /* Don't do anything else */
746 } 746 }
747 else if (PyClass_Check(exception)) { 747 else if (PyClass_Check(exception)) {
748 PyObject* className = 748 PyClassObject* exc = (PyClassObject*)exception;
749 ((PyClassObject*)exception)->cl_name; 749 PyObject* className = exc->cl_name;
750 if (className == NULL) 750 PyObject* moduleName =
751 PyDict_GetItemString(exc->cl_dict, "__module__");
752
753 if (moduleName == NULL)
751 err = PyFile_WriteString("<unknown>", f); 754 err = PyFile_WriteString("<unknown>", f);
752 else 755 else {
753 err = PyFile_WriteObject(className, f, 756 char* modstr = PyString_AsString(moduleName);
754 Py_PRINT_RAW); 757 if (modstr && strcmp(modstr, "exceptions"))
758 {
759 err = PyFile_WriteString(modstr, f);
760 err += PyFile_WriteString(".", f);
761 }
762 }
763 if (err == 0) {
764 if (className == NULL)
765 err = PyFile_WriteString("<unknown>", f);
766 else
767 err = PyFile_WriteObject(className, f,
768 Py_PRINT_RAW);
769 }
755 } 770 }
756 else 771 else
757 err = PyFile_WriteObject(exception, f, Py_PRINT_RAW); 772 err = PyFile_WriteObject(exception, f, Py_PRINT_RAW);
758 if (err == 0) { 773 if (err == 0) {
759 if (v != NULL && v != Py_None) { 774 if (v != NULL && v != Py_None) {