<s> import functools <EOL> import traceback <EOL> def get_exception_handler ( debugger_name ) : <EOL> debugger = _get_debugger ( debugger_name ) <EOL> return functools . partial ( _exception_handler , debugger ) <EOL> def _get_debugger ( debugger_name ) : <EOL> try : <EOL> debugger = __import__ ( debugger_name ) <EOL> except ImportError : <EOL> raise ValueError ( "<STR_LIT>" % <EOL> debugger_name ) <EOL> if '<STR_LIT>' in dir ( debugger ) : <EOL> return debugger <EOL> else : <EOL> raise ValueError ( "<STR_LIT>" % <EOL> debugger_name ) <EOL> def _exception_handler ( debugger , exc_info ) : <EOL> """<STR_LIT>""" <EOL> tb = exc_info [ <NUM_LIT:2> ] <EOL> ignored_traceback = get_ignored_traceback ( tb ) <EOL> if ignored_traceback : <EOL> tb = FilteredTraceback ( tb , ignored_traceback ) <EOL> traceback . print_exception ( exc_info [ <NUM_LIT:0> ] , exc_info [ <NUM_LIT:1> ] , tb ) <EOL> debugger . post_mortem ( tb ) <EOL> def get_ignored_traceback ( tb ) : <EOL> """<STR_LIT>""" <EOL> tb_list = [ ] <EOL> while tb : <EOL> tb_list . append ( tb ) <EOL> tb = tb . tb_next <EOL> ignored_tracebacks = [ ] <EOL> for tb in reversed ( tb_list ) : <EOL> if '<STR_LIT>' in tb . tb_frame . f_globals : <EOL> ignored_tracebacks . append ( tb ) <EOL> else : <EOL> break <EOL> if ignored_tracebacks : <EOL> return ignored_tracebacks [ - <NUM_LIT:1> ] <EOL> class FilteredTraceback ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , tb , filtered_traceback ) : <EOL> """<STR_LIT>""" <EOL> self . _tb = tb <EOL> self . tb_lasti = self . _tb . tb_lasti <EOL> self . tb_lineno = self . _tb . tb_lineno <EOL> self . tb_frame = self . _tb . tb_frame <EOL> self . _filtered_traceback = filtered_traceback <EOL> @ property <EOL> def tb_next ( self ) : <EOL> tb_next = self . _tb . tb_next <EOL> if tb_next and tb_next != self . _filtered_traceback : <EOL> return FilteredTraceback ( tb_next , self . _filtered_traceback ) </s>
