diff --git a/Lib/idlelib/PyShell.py b/Lib/idlelib/PyShell.py index cbfd2036db8..98e091821bc 100644 --- a/Lib/idlelib/PyShell.py +++ b/Lib/idlelib/PyShell.py @@ -353,6 +353,7 @@ class ModifiedInterpreter(InteractiveInterpreter): self.rpcclt.register("stdout", self.tkconsole.stdout) self.rpcclt.register("stderr", self.tkconsole.stderr) self.rpcclt.register("flist", self.tkconsole.flist) + self.rpcclt.register("linecache", linecache) self.transfer_path() self.poll_subprocess() @@ -404,23 +405,6 @@ class ModifiedInterpreter(InteractiveInterpreter): if what is not None: print >>console, `what` elif how == "EXCEPTION": - mod, name, args, tb = what - print >>console, 'Traceback (most recent call last):' - exclude = ("run.py", "rpc.py", "RemoteDebugger.py", "bdb.py") - self.cleanup_traceback(tb, exclude, console) - traceback.print_list(tb, file=console) - # try to reinstantiate the exception, stuff in the args: - try: - etype = eval(mod + '.' + name) - val = etype() - val.args = args - except TypeError: # string exception! - etype = name - val = args - lines = traceback.format_exception_only(etype, val) - for line in lines[:-1]: - traceback._print(console, line, '') - traceback._print(console, lines[-1], '') if self.tkconsole.getvar("<>"): self.remote_stack_viewer() elif how == "ERROR": @@ -430,36 +414,6 @@ class ModifiedInterpreter(InteractiveInterpreter): # we received a response to the currently active seq number: self.tkconsole.endexecuting() - def cleanup_traceback(self, tb, exclude, console): - "Remove excluded traces from beginning/end of tb; get cached lines" - orig_tb = tb[:] - while tb: - for rpcfile in exclude: - if tb[0][0].count(rpcfile): - break # found an exclude, break for: and delete tb[0] - else: - break # no excludes, have left RPC code, break while: - del tb[0] - while tb: - for rpcfile in exclude: - if tb[-1][0].count(rpcfile): - break - else: - break - del tb[-1] - if len(tb) == 0: - # error was in IDLE internals, don't prune! - tb[:] = orig_tb[:] - print>>sys.__stderr__, "** IDLE Internal Error: ", tb - print>>console, "** IDLE Internal Error **" - for i in range(len(tb)): - fn, ln, nm, line = tb[i] - if nm == '?': - nm = "-toplevel-" - if not line and fn.startswith(">efile, 'Traceback (most recent call last):' + exclude = ("run.py", "rpc.py", "RemoteDebugger.py", "bdb.py") + self.cleanup_traceback(tbe, exclude) + traceback.print_list(tbe, file=efile) + lines = traceback.format_exception_only(typ, val) + for line in lines: + print>>efile, line, + return ("EXCEPTION", None) + + def cleanup_traceback(self, tb, exclude): + "Remove excluded traces from beginning/end of tb; get cached lines" + orig_tb = tb[:] + while tb: + for rpcfile in exclude: + if tb[0][0].count(rpcfile): + break # found an exclude, break for: and delete tb[0] else: - # User string exception - mod = None - name = typ - if val is None: val = '' - args = str(val) - tb = traceback.extract_tb(tb) - self.debug("localcall:EXCEPTION: ", mod, name, args, tb) - return ("EXCEPTION", (mod, name, args, tb)) + break # no excludes, have left RPC code, break while: + del tb[0] + while tb: + for rpcfile in exclude: + if tb[-1][0].count(rpcfile): + break + else: + break + del tb[-1] + if len(tb) == 0: + # error was in RPC internals, don't prune! + tb[:] = orig_tb[:] + print>>sys.stderr, "** RPC Internal Error: ", tb + for i in range(len(tb)): + fn, ln, nm, line = tb[i] + if nm == '?': + nm = "-toplevel-" + if not line and fn.startswith("