diff options
| author | Amaury Forgeot d'Arc <amauryfa@gmail.com> | 2008-07-11 21:45:06 (GMT) | 
|---|---|---|
| committer | Amaury Forgeot d'Arc <amauryfa@gmail.com> | 2008-07-11 21:45:06 (GMT) | 
| commit | 2252d11c08643279ffe58e99f6c8d04014079a7f (patch) | |
| tree | 1561d7ccea92517daac9b7d5877426b17f15b107 | |
| parent | ae6d2b917520f441eb8538466c0b848047dd58f2 (diff) | |
| download | cpython-2252d11c08643279ffe58e99f6c8d04014079a7f.zip cpython-2252d11c08643279ffe58e99f6c8d04014079a7f.tar.gz cpython-2252d11c08643279ffe58e99f6c8d04014079a7f.tar.bz2  | |
#3342: In tracebacks, printed source lines were not indented since r62555.
#3343: Py_DisplaySourceLine should be a private function. Rename it to _Py_DisplaySourceLine.
| -rw-r--r-- | Include/traceback.h | 2 | ||||
| -rw-r--r-- | Lib/test/test_traceback.py | 2 | ||||
| -rw-r--r-- | Python/_warnings.c | 4 | ||||
| -rw-r--r-- | Python/traceback.c | 25 | 
4 files changed, 24 insertions, 9 deletions
diff --git a/Include/traceback.h b/Include/traceback.h index b77cc92..e7943da 100644 --- a/Include/traceback.h +++ b/Include/traceback.h @@ -19,7 +19,7 @@ typedef struct _traceback {  PyAPI_FUNC(int) PyTraceBack_Here(struct _frame *);  PyAPI_FUNC(int) PyTraceBack_Print(PyObject *, PyObject *); -PyAPI_FUNC(int) Py_DisplaySourceLine(PyObject *, const char *, int); +PyAPI_FUNC(int) _Py_DisplaySourceLine(PyObject *, const char *, int, int);  /* Reveal traceback type so we can typecheck traceback objects */  PyAPI_DATA(PyTypeObject) PyTraceBack_Type; diff --git a/Lib/test/test_traceback.py b/Lib/test/test_traceback.py index 96b8938..8034839 100644 --- a/Lib/test/test_traceback.py +++ b/Lib/test/test_traceback.py @@ -177,7 +177,7 @@ class TracebackFormatTests(unittest.TestCase):          banner, location, source_line = tb_lines          self.assert_(banner.startswith('Traceback'))          self.assert_(location.startswith('  File')) -        self.assert_(source_line.startswith('raise')) +        self.assert_(source_line.startswith('    raise'))  def test_main(): diff --git a/Python/_warnings.c b/Python/_warnings.c index 07b98ef..5ed8b55 100644 --- a/Python/_warnings.c +++ b/Python/_warnings.c @@ -256,7 +256,6 @@ show_warning(PyObject *filename, int lineno, PyObject *text, PyObject      Py_XDECREF(name);      /* Print "  source_line\n" */ -    PyFile_WriteString("  ", f_stderr);      if (sourceline) {          char *source_line_str = PyString_AS_STRING(sourceline);          while (*source_line_str == ' ' || *source_line_str == '\t' || @@ -267,7 +266,8 @@ show_warning(PyObject *filename, int lineno, PyObject *text, PyObject          PyFile_WriteString("\n", f_stderr);      }      else -        Py_DisplaySourceLine(f_stderr, PyString_AS_STRING(filename), lineno); +        _Py_DisplaySourceLine(f_stderr, PyString_AS_STRING(filename),  +                              lineno, 2);      PyErr_Clear();  } diff --git a/Python/traceback.c b/Python/traceback.c index a481963..5df7694 100644 --- a/Python/traceback.c +++ b/Python/traceback.c @@ -123,7 +123,7 @@ PyTraceBack_Here(PyFrameObject *frame)  }  int -Py_DisplaySourceLine(PyObject *f, const char *filename, int lineno) +_Py_DisplaySourceLine(PyObject *f, const char *filename, int lineno, int indent)  {  	int err = 0;  	FILE *xfp = NULL; @@ -197,12 +197,27 @@ Py_DisplaySourceLine(PyObject *f, const char *filename, int lineno)  		} while (*pLastChar != '\0' && *pLastChar != '\n');  	}  	if (i == lineno) { +		char buf[11];  		char *p = linebuf;  		while (*p == ' ' || *p == '\t' || *p == '\014')  			p++; -                    err = PyFile_WriteString(p, f); -                    if (err == 0 && strchr(p, '\n') == NULL) -                            err = PyFile_WriteString("\n", f); + +		/* Write some spaces before the line */ +		strcpy(buf, "          "); +		assert (strlen(buf) == 10); +		while (indent > 0) { +			if(indent < 10) +				buf[indent] = '\0'; +			err = PyFile_WriteString(buf, f); +			if (err != 0) +				break; +			indent -= 10; +		} + +		if (err == 0) +			err = PyFile_WriteString(p, f); +		if (err == 0 && strchr(p, '\n') == NULL) +			err = PyFile_WriteString("\n", f);  	}  	fclose(xfp);  	return err; @@ -222,7 +237,7 @@ tb_displayline(PyObject *f, const char *filename, int lineno, const char *name)  	err = PyFile_WriteString(linebuf, f);  	if (err != 0)  		return err; -        return Py_DisplaySourceLine(f, filename, lineno); +        return _Py_DisplaySourceLine(f, filename, lineno, 4);  }  static int  | 
