diff Python/errors.c @ 22121:d4406fbfcb4e 2.2

Patch #50002: Display line information for bad \x escapes: - recognize "SyntaxError"s by the print_file_and_line attribute. - add the syntaxerror attributes to all exceptions in compile.c. Fixes #221791
author Martin v. Löwis <martin@v.loewis.de>
date Sun, 03 Mar 2002 21:32:01 +0000
parents abaf9ea2e560
children faeb708bacc4 f4487350c537
line wrap: on
line diff
--- a/Python/errors.c	Sun Mar 03 15:17:07 2002 +0000
+++ b/Python/errors.c	Sun Mar 03 21:32:01 2002 +0000
@@ -561,7 +561,9 @@
 }
 
 
-/* XXX There's a comment missing here */
+/* Set file and line information for the current exception.
+   If the exception is not a SyntaxError, also sets additional attributes
+   to make printing of exceptions believe it is a syntax error. */
 
 void
 PyErr_SyntaxLocation(char *filename, int lineno)
@@ -596,6 +598,26 @@
 			Py_DECREF(tmp);
 		}
 	}
+	if (PyObject_SetAttrString(v, "offset", Py_None)) {
+		PyErr_Clear();
+	}
+	if (exc != PyExc_SyntaxError) {
+		if (!PyObject_HasAttrString(v, "msg")) {
+			tmp = PyObject_Str(v);
+			if (tmp) {
+				if (PyObject_SetAttrString(v, "msg", tmp))
+					PyErr_Clear();
+				Py_DECREF(tmp);
+			} else {
+				PyErr_Clear();
+			}
+		}
+		if (!PyObject_HasAttrString(v, "print_file_and_line")) {
+			if (PyObject_SetAttrString(v, "print_file_and_line",
+						   Py_None))
+				PyErr_Clear();
+		}
+	}
 	PyErr_Restore(exc, v, tb);
 }