[Python-checkins] r74441 - in python/branches/tk_and_idle_maintenance/Lib/idlelib: PyShell.py run.py utils.py

guilherme.polo python-checkins at python.org
Fri Aug 14 05:35:14 CEST 2009


Author: guilherme.polo
Date: Fri Aug 14 05:35:14 2009
New Revision: 74441

Log:
Highlight all the traceback entries that occur in the main file.

Modified:
   python/branches/tk_and_idle_maintenance/Lib/idlelib/PyShell.py
   python/branches/tk_and_idle_maintenance/Lib/idlelib/run.py
   python/branches/tk_and_idle_maintenance/Lib/idlelib/utils.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	Fri Aug 14 05:35:14 2009
@@ -701,16 +701,15 @@
         sys.stderr.write('\nTraceback (most recent call last):\n')
         if temp_filename is not None:
             # Replace the name of the temporary file by 'Untitled'
+            main_fname = 'Untitled'
             new_tb = []
             for t in tblist:
-                fname = 'Untitled' if t[0] == temp_filename else t[0]
+                fname = main_fname 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:]
-        tb_print_list(first, file=sys.stderr)
-        if rest:
-            tb_print_list(rest, file=sys.stdout)
+        else:
+            main_fname = tblist[0][0]
+        tb_print_list(tblist, main_fname, sys.stdout, sys.stderr)
         lines = traceback.format_exception_only(typ, value)
         map(sys.stderr.write, lines)
 

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	Fri Aug 14 05:35:14 2009
@@ -161,16 +161,15 @@
     cleanup_traceback(tbe, exclude)
     if temp_filename is not None:
         # Replace the name of the temporary file by 'Untitled'
+        main_fname = 'Untitled'
         new_tbe = []
         for t in tbe:
-            fname = 'Untitled' if t[0] == temp_filename else t[0]
+            fname = main_fname 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:]
-    tb_print_list(first, file=efile)
-    if rest:
-        tb_print_list(rest, file=sys.stdout)
+    else:
+        main_fname = tbe[0][0]
+    tb_print_list(tbe, main_fname, sys.stdout, efile)
     lines = traceback.format_exception_only(typ, val)
     for line in lines:
         print>>efile, line,

Modified: python/branches/tk_and_idle_maintenance/Lib/idlelib/utils.py
==============================================================================
--- python/branches/tk_and_idle_maintenance/Lib/idlelib/utils.py	(original)
+++ python/branches/tk_and_idle_maintenance/Lib/idlelib/utils.py	Fri Aug 14 05:35:14 2009
@@ -1,12 +1,15 @@
 import sys
 
-def tb_print_list(extracted_list, file=sys.stderr):
-    """An extended version of traceback.print_list which doesn't include
-    "in <module>" when printing traceback."""
+def tb_print_list(extracted_list, filename, normal=sys.stdout,
+        highlight=sys.stderr):
+    """An extended version of traceback.print_list which exclude
+    "in <module>" when printing traceback and highlight the entries
+    that occur on the given filename."""
     for fname, lineno, name, line in extracted_list:
+        f = highlight if fname == filename else normal
         if name == '<module>':
-            file.write('  File "%s", line %d\n' % (fname, lineno))
+            f.write('  File "%s", line %d\n' % (fname, lineno))
         else:
-            file.write('  File "%s", line %d, in %s\n' % (fname, lineno, name))
+            f.write('  File "%s", line %d, in %s\n' % (fname, lineno, name))
         if line:
-            file.write('    %s\n' % line.strip())
+            f.write('    %s\n' % line.strip())


More information about the Python-checkins mailing list