'''Debugging utilities.'''
import sys
import traceback
import inspect
def excepthook(type, value, tb):
"""
Automatically start the debugger on an exception.
See also:
- http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65287
"""
if hasattr(sys, 'ps1') \
or not (sys.stdin.isatty() and sys.stdout.isatty() and sys.stderr.isatty()) \
or type == SyntaxError or type == KeyboardInterrupt:
oldexcepthook(type, value, tb)
else:
import traceback, pdb
traceback.print_exception(type, value, tb)
print
pdb.pm()
oldexcepthook, sys.excepthook = sys.excepthook, excepthook
def dump(var):
sys.stderr.write(repr(var) + '\n')