Commit c8850d07 authored by Benjamin Peterson's avatar Benjamin Peterson

Merged revisions 85817,85904 via svnmerge from

svn+ssh://pythondev@svn.python.org/python/branches/py3k

........
  r85817 | benjamin.peterson | 2010-10-23 22:41:46 -0500 (Sat, 23 Oct 2010) | 1 line

  tighten loop
........
  r85904 | benjamin.peterson | 2010-10-28 22:28:14 -0500 (Thu, 28 Oct 2010) | 1 line

  decrement offset when it points to a newline (#10186 followup)
........
parent 98e2b452
...@@ -302,6 +302,10 @@ class BaseExceptionReportingTests: ...@@ -302,6 +302,10 @@ class BaseExceptionReportingTests:
raise SyntaxError('', ('', 0, 5, 'hello')) raise SyntaxError('', ('', 0, 5, 'hello'))
msg = self.get_report(e).splitlines() msg = self.get_report(e).splitlines()
self.assertEqual(msg[-2], " ^") self.assertEqual(msg[-2], " ^")
def e():
exec("x = 5 | 4 |")
msg = self.get_report(e).splitlines()
self.assertEqual(msg[-2], ' ^')
class PyExcReportingTests(BaseExceptionReportingTests, unittest.TestCase): class PyExcReportingTests(BaseExceptionReportingTests, unittest.TestCase):
......
...@@ -1299,6 +1299,8 @@ print_error_text(PyObject *f, int offset, const char *text) ...@@ -1299,6 +1299,8 @@ print_error_text(PyObject *f, int offset, const char *text)
{ {
char *nl; char *nl;
if (offset >= 0) { if (offset >= 0) {
if (offset > 0 && offset == strlen(text) && text[offset - 1] == '\n')
offset--;
for (;;) { for (;;) {
nl = strchr(text, '\n'); nl = strchr(text, '\n');
if (nl == NULL || nl-text >= offset) if (nl == NULL || nl-text >= offset)
...@@ -1318,11 +1320,8 @@ print_error_text(PyObject *f, int offset, const char *text) ...@@ -1318,11 +1320,8 @@ print_error_text(PyObject *f, int offset, const char *text)
if (offset == -1) if (offset == -1)
return; return;
PyFile_WriteString(" ", f); PyFile_WriteString(" ", f);
offset--; while (--offset > 0)
while (offset > 0) {
PyFile_WriteString(" ", f); PyFile_WriteString(" ", f);
offset--;
}
PyFile_WriteString("^\n", f); PyFile_WriteString("^\n", f);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment