1 package org.python.core; 3 4 7 8 public class PyTraceback extends PyObject 9 { 10 public PyObject tb_next; 11 public PyFrame tb_frame; 12 public int tb_lineno; 13 14 public PyTraceback(PyFrame frame) { 15 tb_frame = frame; 16 if (tb_frame != null) 17 tb_lineno = tb_frame.getline(); 18 tb_next = Py.None; 19 } 20 21 public PyTraceback(PyTraceback next) { 22 tb_next = next; 23 if (next != null) { 24 tb_frame = next.tb_frame.f_back; 25 tb_lineno = tb_frame.getline(); 26 } 27 } 28 29 private String line() { 32 if (tb_frame == null || tb_frame.f_code == null) 33 return " (no code object) at line "+tb_lineno+"\n"; 34 return " File \""+tb_frame.f_code.co_filename+ 35 "\", line "+tb_lineno+ 36 ", in "+tb_frame.f_code.co_name+"\n"; 37 } 38 39 public void dumpStack(StringBuffer buf) { 40 buf.append(line()); 41 if (tb_next != Py.None && tb_next != this) 42 ((PyTraceback)tb_next).dumpStack(buf); 43 else if (tb_next == this) { 44 buf.append("circularity detected!"+this+tb_next); 45 } 46 } 47 48 public String dumpStack() { 49 StringBuffer buf = new StringBuffer (); 50 51 buf.append("Traceback (innermost last):\n"); 52 dumpStack(buf); 53 54 return buf.toString(); 55 } 56 57 public String toString() { 58 return "<traceback object at " + " "+Py.idstr(this) + ">"; 59 } 60 } 61 | Popular Tags |