From: Finn B. <bc...@us...> - 2001-11-26 11:00:27
|
Update of /cvsroot/jython/jython/org/python/core In directory usw-pr-cvs1:/tmp/cvs-serv7106 Modified Files: PySystemState.java Py.java Log Message: Support for sys.excepthook. Index: PySystemState.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/core/PySystemState.java,v retrieving revision 2.64 retrieving revision 2.65 diff -C2 -d -r2.64 -r2.65 *** PySystemState.java 2001/11/03 19:26:02 2.64 --- PySystemState.java 2001/11/26 11:00:22 2.65 *************** *** 132,135 **** --- 132,137 ---- public PyObject __stdout__, __stderr__, __stdin__; + public PyObject __displayhook__, __excepthook__; + public PyObject last_value = Py.None; public PyObject last_type = Py.None; *************** *** 208,211 **** --- 210,215 ---- __stderr__ = stderr = new PyFile(System.err, "<stderr>"); __stdin__ = stdin = new PyFile(getSystemIn(), "<stdin>"); + __displayhook__ = new PySystemStateFunctions("displayhook", 10, 1, 1); + __excepthook__ = new PySystemStateFunctions("excepthook", 30, 3, 3); // This isn't quite right... *************** *** 217,222 **** __dict__ = new PyStringMap(); __dict__.invoke("update", __class__.__getattr__("__dict__")); ! __dict__.__setitem__("displayhook", ! new PySystemStateFunctions("displayhook", 10, 1, 1)); } } --- 221,226 ---- __dict__ = new PyStringMap(); __dict__.invoke("update", __class__.__getattr__("__dict__")); ! __dict__.__setitem__("displayhook", __displayhook__); ! __dict__.__setitem__("excepthook", __excepthook__); } } *************** *** 630,633 **** --- 634,641 ---- } + static void excepthook(PyObject type, PyObject val, PyObject tb) { + Py.displayException(type, val, tb); + } + public void callExitFunc() throws PyIgnoreMethodTag { PyObject exitfunc = __findattr__("exitfunc"); *************** *** 690,693 **** --- 698,711 ---- default: throw argCountError(1); + } + } + public PyObject __call__(PyObject arg1, PyObject arg2, PyObject arg3) { + PySystemState sys = Py.getThreadState().systemState; + switch (index) { + case 30: + sys.excepthook(arg1, arg2, arg3); + return Py.None; + default: + throw argCountError(3); } } Index: Py.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/core/Py.java,v retrieving revision 2.55 retrieving revision 2.56 diff -C2 -d -r2.55 -r2.56 *** Py.java 2001/11/21 11:43:32 2.55 --- Py.java 2001/11/26 11:00:24 2.56 *************** *** 895,912 **** ts.systemState.last_traceback = exc.traceback; ! ts.exception = null; ! /*_type = null; ! ts.exc_value = null; ! ts.exc_traceback = null;*/ ! stderr.print(exc.traceback.dumpStack()); ! if (exc instanceof PySyntaxError) { ! PySyntaxError se = (PySyntaxError)exc; ! stderr.println(" File \""+se.filename+"\", line "+se.lineno); ! if (se.text != null && se.text.length() != 0) { ! stderr.println("\t"+se.text); String space = "\t"; ! for(int j=1; j<se.column; j++) space = space+" "; stderr.println(space+"^"); --- 895,932 ---- ts.systemState.last_traceback = exc.traceback; ! PyObject exceptHook = ts.systemState.__findattr__("excepthook"); ! if (exceptHook != null) { ! try { ! exceptHook.__call__(exc.type, exc.value, exc.traceback); ! } catch (PyException exc2) { ! stderr.println("Error in sys.excepthook:"); ! displayException(exc2.type, exc2.value, exc2.traceback); ! stderr.println(); ! stderr.println("Original exception was:"); ! displayException(exc.type, exc.value, exc.traceback); ! } ! } else { ! stderr.println("sys.excepthook is missing"); ! displayException(exc.type, exc.value, exc.traceback); ! } ! ! ts.exception = null; ! } ! public static void displayException(PyObject type, PyObject value, ! PyObject tb) ! { ! if (tb instanceof PyTraceback) ! stderr.print(((PyTraceback) tb).dumpStack()); ! if (__builtin__.isinstance(value, (PyClass) Py.SyntaxError)) { ! stderr.println(" File \""+value.__findattr__("filename")+ ! "\", line "+value.__findattr__("lineno")); ! PyObject text = value.__findattr__("text"); ! if (text != Py.None && text.__len__() != 0) { ! stderr.println("\t"+text); String space = "\t"; ! int col = value.__findattr__("offset").__int__().getValue(); ! for(int j=1; j<col; j++) space = space+" "; stderr.println(space+"^"); *************** *** 914,919 **** } ! if (exc.value instanceof PyJavaInstance) { ! Object javaError = exc.value.__tojava__(Throwable.class); if (javaError != null && javaError != Py.NoConversion) { --- 934,939 ---- } ! if (value instanceof PyJavaInstance) { ! Object javaError = value.__tojava__(Throwable.class); if (javaError != null && javaError != Py.NoConversion) { *************** *** 923,938 **** PyObject typeName; ! if (exc.type instanceof PyClass) { ! typeName = new PyString(((PyClass)exc.type).__name__); } else { ! typeName = exc.type; } ! if (exc.value != Py.None) { stderr.print(typeName); stderr.print(": "); ! if (exc instanceof PySyntaxError) { ! stderr.println(exc.value.__getitem__(0)); } else { ! stderr.println(exc.value); } } else { --- 943,958 ---- PyObject typeName; ! if (type instanceof PyClass) { ! typeName = new PyString(((PyClass)type).__name__); } else { ! typeName = type; } ! if (value != Py.None) { stderr.print(typeName); stderr.print(": "); ! if (__builtin__.isinstance(value, (PyClass) Py.SyntaxError)) { ! stderr.println(value.__getitem__(0)); } else { ! stderr.println(value); } } else { |