Mercurial > cpython-lru_cache-weakref
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 22119:0859e764509e | 22121:d4406fbfcb4e |
|---|---|
| 559 return 0; | 559 return 0; |
| 560 } | 560 } |
| 561 } | 561 } |
| 562 | 562 |
| 563 | 563 |
| 564 /* XXX There's a comment missing here */ | 564 /* Set file and line information for the current exception. |
| 565 If the exception is not a SyntaxError, also sets additional attributes | |
| 566 to make printing of exceptions believe it is a syntax error. */ | |
| 565 | 567 |
| 566 void | 568 void |
| 567 PyErr_SyntaxLocation(char *filename, int lineno) | 569 PyErr_SyntaxLocation(char *filename, int lineno) |
| 568 { | 570 { |
| 569 PyObject *exc, *v, *tb, *tmp; | 571 PyObject *exc, *v, *tb, *tmp; |
| 592 | 594 |
| 593 tmp = PyErr_ProgramText(filename, lineno); | 595 tmp = PyErr_ProgramText(filename, lineno); |
| 594 if (tmp) { | 596 if (tmp) { |
| 595 PyObject_SetAttrString(v, "text", tmp); | 597 PyObject_SetAttrString(v, "text", tmp); |
| 596 Py_DECREF(tmp); | 598 Py_DECREF(tmp); |
| 599 } | |
| 600 } | |
| 601 if (PyObject_SetAttrString(v, "offset", Py_None)) { | |
| 602 PyErr_Clear(); | |
| 603 } | |
| 604 if (exc != PyExc_SyntaxError) { | |
| 605 if (!PyObject_HasAttrString(v, "msg")) { | |
| 606 tmp = PyObject_Str(v); | |
| 607 if (tmp) { | |
| 608 if (PyObject_SetAttrString(v, "msg", tmp)) | |
| 609 PyErr_Clear(); | |
| 610 Py_DECREF(tmp); | |
| 611 } else { | |
| 612 PyErr_Clear(); | |
| 613 } | |
| 614 } | |
| 615 if (!PyObject_HasAttrString(v, "print_file_and_line")) { | |
| 616 if (PyObject_SetAttrString(v, "print_file_and_line", | |
| 617 Py_None)) | |
| 618 PyErr_Clear(); | |
| 597 } | 619 } |
| 598 } | 620 } |
| 599 PyErr_Restore(exc, v, tb); | 621 PyErr_Restore(exc, v, tb); |
| 600 } | 622 } |
| 601 | 623 |
