summaryrefslogtreecommitdiffstats
path: root/Python/ast.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2013-02-10 15:42:01 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2013-02-10 15:42:01 (GMT)
commit801d955f04d46994ac5bc7270fea86a7703c5192 (patch)
treec63cdc08b7a4b1fde457b74143855d2a24fa2da5 /Python/ast.c
parent6427358501ac5b5a33b1c0543b46f6d378cea7e3 (diff)
parent5e61f14c6dd29982da9364696bc864604b143a66 (diff)
downloadcpython-801d955f04d46994ac5bc7270fea86a7703c5192.zip
cpython-801d955f04d46994ac5bc7270fea86a7703c5192.tar.gz
cpython-801d955f04d46994ac5bc7270fea86a7703c5192.tar.bz2
Issue #12983: Bytes literals with invalid \x escape now raise a SyntaxError
and a full traceback including line number.
Diffstat (limited to 'Python/ast.c')
-rw-r--r--Python/ast.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/Python/ast.c b/Python/ast.c
index 730c576..1b5fa6c 100644
--- a/Python/ast.c
+++ b/Python/ast.c
@@ -1829,20 +1829,24 @@ ast_for_atom(struct compiling *c, const node *n)
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);