Mercurial > cpython-lru_cache-weakref
diff Python/ast.c @ 82137:d5b731446a91 3.3
Issue #12983: Bytes literals with invalid \x escape now raise a SyntaxError
and a full traceback including line number.
| author | Serhiy Storchaka <storchaka@gmail.com> |
|---|---|
| date | Sun, 10 Feb 2013 17:42:01 +0200 |
| parents | c08bcf5302ec 305210a08fc9 |
| children | 0ac424c86a94 fe410292cba6 |
line wrap: on
line diff
--- a/Python/ast.c Sun Feb 10 14:16:56 2013 +0000 +++ b/Python/ast.c Sun Feb 10 17:42:01 2013 +0200 @@ -1829,20 +1829,24 @@ case STRING: { PyObject *str = parsestrplus(c, n, &bytesmode); if (!str) { - if (PyErr_ExceptionMatches(PyExc_UnicodeError)) { + const char *errtype = NULL; + if (PyErr_ExceptionMatches(PyExc_UnicodeError)) + errtype = "unicode error"; + else if (PyErr_ExceptionMatches(PyExc_ValueError)) + errtype = "value error"; + if (errtype) { + char buf[128]; PyObject *type, *value, *tback, *errstr; PyErr_Fetch(&type, &value, &tback); errstr = PyObject_Str(value); if (errstr) { - char *s = ""; - char buf[128]; - s = _PyUnicode_AsString(errstr); - PyOS_snprintf(buf, sizeof(buf), "(unicode error) %s", s); - ast_error(c, n, buf); + char *s = _PyUnicode_AsString(errstr); + PyOS_snprintf(buf, sizeof(buf), "(%s) %s", errtype, s); Py_DECREF(errstr); } else { - ast_error(c, n, "(unicode error) unknown error"); + PyOS_snprintf(buf, sizeof(buf), "(%s) unknown error", errtype); } + ast_error(c, n, buf); Py_DECREF(type); Py_DECREF(value); Py_XDECREF(tback);
