* Lib/linecache.py: don't crash on empty filename
* Lib/macpath.py: don't return trailing colon for dirname()
(XXX won't do for volume names -- but otherwise glob(':*:*.py')
loops forever)
* Lib/traceback.py: print SyntaxError correctly
* Lib/stat.py: moved to posixstat.py; added macstat.py which has
the constants for the Mac; and created new stat.py which includes
the right one
* Lib/urllib.py: fix caching bug (by disabling the cache)
diff --git a/Lib/traceback.py b/Lib/traceback.py
index c78d9ad..1eec209 100644
--- a/Lib/traceback.py
+++ b/Lib/traceback.py
@@ -42,11 +42,33 @@
return list
def print_exception(type, value, tb, limit = None):
- print 'Traceback (innermost last):'
- print_tb(tb, limit)
- print type,
- if value is not None: print ':', value,
- print
+ if tb:
+ print 'Traceback (innermost last):'
+ print_tb(tb, limit)
+ if value is None:
+ print type
+ else:
+ if type is SyntaxError:
+ try:
+ msg, (filename, lineno, offset, line) = value
+ except:
+ pass
+ else:
+ if not filename: filename = "<string>"
+ print ' File "%s", line %d' % (filename, lineno)
+ i = 0
+ while i < len(line) and line[i] in string.whitespace:
+ i = i+1
+ s = ' '
+ print s + string.strip(line)
+ for c in line[i:offset-1]:
+ if c in string.whitespace:
+ s = s + c
+ else:
+ s = s + ' '
+ print s + '^'
+ value = msg
+ print '%s: %s' % (type, value)
def print_exc(limit = None):
print_exception(sys.exc_type, sys.exc_value, sys.exc_traceback,