[Python-checkins] r74433 - in python/branches/tk_and_idle_maintenance/Lib/idlelib: PyShell.py ScriptBinding.py run.py
guilherme.polo
python-checkins at python.org
Thu Aug 13 21:46:47 CEST 2009
Author: guilherme.polo
Date: Thu Aug 13 21:46:46 2009
New Revision: 74433
Log:
Mask the name of temporary files in a possible traceback.
Modified:
python/branches/tk_and_idle_maintenance/Lib/idlelib/PyShell.py
python/branches/tk_and_idle_maintenance/Lib/idlelib/ScriptBinding.py
python/branches/tk_and_idle_maintenance/Lib/idlelib/run.py
Modified: python/branches/tk_and_idle_maintenance/Lib/idlelib/PyShell.py
==============================================================================
--- python/branches/tk_and_idle_maintenance/Lib/idlelib/PyShell.py (original)
+++ python/branches/tk_and_idle_maintenance/Lib/idlelib/PyShell.py Thu Aug 13 21:46:46 2009
@@ -685,8 +685,9 @@
else:
return None
- def showtraceback(self):
- "Extend base class method to reset output properly"
+ def showtraceback(self, temp_filename=None):
+ """Extend base class method to reset output properly and print an
+ customized traceback."""
self.tkconsole.resetoutput()
self.checklinecache()
@@ -697,7 +698,13 @@
tblist = traceback.extract_tb(tb)
del tblist[:1]
sys.stderr.write('\nTraceback (most recent call last):\n')
- traceback
+ if temp_filename is not None:
+ # Replace the name of the temporary file by 'Untitled'
+ new_tb = []
+ for t in tblist:
+ fname = 'Untitled' if t[0] == temp_filename else t[0]
+ new_tb.append((fname, ) + t[1:])
+ tblist = new_tb
# Highlight only topmost exception
first, rest = [tblist[0]], tblist[1:]
traceback.print_list(first, file=sys.stderr)
@@ -727,7 +734,7 @@
exec code in self.locals
return 1
- def runcode(self, code):
+ def runcode(self, code, tempname=None):
"Override base class method"
if self.tkconsole.executing:
self.interp.restart_subprocess()
@@ -740,7 +747,7 @@
self.tkconsole.beginexecuting()
if not debugger and self.rpcclt is not None:
self.active_seq = self.rpcclt.asyncqueue("exec", "runcode",
- (code,), {})
+ (code, tempname), {})
elif debugger:
debugger.run(code, self.locals)
else:
@@ -768,7 +775,7 @@
self.tkconsole.canceled = False
print >>self.tkconsole.stderr, "KeyboardInterrupt"
else:
- self.showtraceback()
+ self.showtraceback(tempname)
finally:
if not use_subprocess:
try:
Modified: python/branches/tk_and_idle_maintenance/Lib/idlelib/ScriptBinding.py
==============================================================================
--- python/branches/tk_and_idle_maintenance/Lib/idlelib/ScriptBinding.py (original)
+++ python/branches/tk_and_idle_maintenance/Lib/idlelib/ScriptBinding.py Thu Aug 13 21:46:46 2009
@@ -178,9 +178,11 @@
# XXX KBK 03Jul04 When run w/o subprocess, runtime warnings still
# go to __stderr__. With subprocess, they go to the shell.
# Need to change streams in PyShell.ModifiedInterpreter.
- interp.runcode(code)
if is_temp:
+ interp.runcode(code, filename)
interp.tkconsole.append_cleanup_func(self._cleanup_temp, filename)
+ else:
+ interp.runcode(code)
return 'break'
def getfilename(self):
Modified: python/branches/tk_and_idle_maintenance/Lib/idlelib/run.py
==============================================================================
--- python/branches/tk_and_idle_maintenance/Lib/idlelib/run.py (original)
+++ python/branches/tk_and_idle_maintenance/Lib/idlelib/run.py Thu Aug 13 21:46:46 2009
@@ -146,7 +146,7 @@
tkMessageBox.showerror("IDLE Subprocess Error", "Socket Error: %s" % err[1])
root.destroy()
-def print_exception():
+def print_exception(temp_filename=None):
import linecache
linecache.checkcache()
flush_stdout()
@@ -158,6 +158,13 @@
exclude = ("run.py", "rpc.py", "threading.py", "Queue.py",
"RemoteDebugger.py", "bdb.py")
cleanup_traceback(tbe, exclude)
+ if temp_filename is not None:
+ # Replace the name of the temporary file by 'Untitled'
+ new_tbe = []
+ for t in tbe:
+ fname = 'Untitled' if t[0] == temp_filename else t[0]
+ new_tbe.append((fname, ) + t[1:])
+ tbe = new_tbe
# Highlight only topmost exception
first, rest = [tbe[0]], tbe[1:]
traceback.print_list(first, file=efile)
@@ -291,7 +298,7 @@
self.calltip = CallTips.CallTips()
self.autocomplete = AutoComplete.AutoComplete()
- def runcode(self, code):
+ def runcode(self, code, temp_filename=None):
global interruptable
try:
self.usr_exc_info = None
@@ -305,7 +312,7 @@
if quitting:
exit()
# even print a user code SystemExit exception, continue
- print_exception()
+ print_exception(temp_filename)
jit = self.rpchandler.console.getvar("<<toggle-jit-stack-viewer>>")
if jit:
self.rpchandler.interp.open_remote_stack_viewer()
More information about the Python-checkins
mailing list