Forward UnicodeDecodeError into SyntaxError for source encoding errors.

Will backport to 2.4.
This commit is contained in:
Martin v. Löwis 2005-08-24 08:39:24 +00:00
parent 56066d2e55
commit d35edda682
2 changed files with 9 additions and 5 deletions

View File

@ -12,6 +12,8 @@ What's New in Python 2.5 alpha 1?
Core and builtins Core and builtins
----------------- -----------------
- Forward UnicodeDecodeError into SyntaxError for source encoding errors.
- SF bug #900092: When tracing (e.g. for hotshot), restore 'return' events for - SF bug #900092: When tracing (e.g. for hotshot), restore 'return' events for
exceptions that cause a function to exit. exceptions that cause a function to exit.

View File

@ -1474,18 +1474,20 @@ err_input(perrdetail *err)
errtype = PyExc_IndentationError; errtype = PyExc_IndentationError;
msg = "too many levels of indentation"; msg = "too many levels of indentation";
break; break;
case E_DECODE: { /* XXX */ case E_DECODE: {
PyThreadState* tstate = PyThreadState_GET(); PyObject *type, *value, *tb;
PyObject* value = tstate->curexc_value; PyErr_Fetch(&type, &value, &tb);
if (value != NULL) { if (value != NULL) {
u = PyObject_Repr(value); u = PyObject_Str(value);
if (u != NULL) { if (u != NULL) {
msg = PyString_AsString(u); msg = PyString_AsString(u);
break;
} }
} }
if (msg == NULL) if (msg == NULL)
msg = "unknown decode error"; msg = "unknown decode error";
Py_DECREF(type);
Py_DECREF(value);
Py_DECREF(tb);
break; break;
} }
case E_LINECONT: case E_LINECONT: