01: // Copyright (c) Corporation for National Research Initiatives
02: package org.python.core;
03:
04: /**
05: * A python traceback object.
06: */
07:
08: public class PyTraceback extends PyObject {
09: public PyObject tb_next;
10: public PyFrame tb_frame;
11: public int tb_lineno;
12:
13: public PyTraceback(PyFrame frame) {
14: tb_frame = frame;
15: if (tb_frame != null)
16: tb_lineno = tb_frame.getline();
17: tb_next = Py.None;
18: }
19:
20: public PyTraceback(PyTraceback next) {
21: tb_next = next;
22: if (next != null) {
23: tb_frame = next.tb_frame.f_back;
24: tb_lineno = tb_frame.getline();
25: }
26: }
27:
28: // filename, lineno, function_name
29: // " File \"%.900s\", line %d, in %s\n"
30: private String line() {
31: if (tb_frame == null || tb_frame.f_code == null)
32: return " (no code object) at line " + tb_lineno + "\n";
33: return " File \"" + tb_frame.f_code.co_filename + "\", line "
34: + tb_lineno + ", in " + tb_frame.f_code.co_name + "\n";
35: }
36:
37: public void dumpStack(StringBuffer buf) {
38: buf.append(line());
39: if (tb_next != Py.None && tb_next != this )
40: ((PyTraceback) tb_next).dumpStack(buf);
41: else if (tb_next == this ) {
42: buf.append("circularity detected!" + this + tb_next);
43: }
44: }
45:
46: public String dumpStack() {
47: StringBuffer buf = new StringBuffer();
48:
49: buf.append("Traceback (innermost last):\n");
50: dumpStack(buf);
51:
52: return buf.toString();
53: }
54:
55: public String toString() {
56: return "<traceback object at " + " " + Py.idstr(this ) + ">";
57: }
58: }
|