<s> import sys <EOL> import traceback <EOL> from tracestack . handler import ExceptionHandler , _get_ipython_handler <EOL> def pm ( * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if hasattr ( sys , "<STR_LIT>" ) : <EOL> einfo = ( sys . last_type , sys . last_value , sys . last_traceback ) <EOL> handler = ExceptionHandler ( * args , ** kwargs ) <EOL> try : <EOL> ipython_shell = get_ipython ( ) <EOL> ipython_shell . showtraceback ( ) <EOL> handler . handle_error ( * einfo ) <EOL> except NameError : <EOL> handler ( * einfo ) <EOL> else : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> def on ( * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> ipython_shell = get_ipython ( ) <EOL> handler = ExceptionHandler ( * args , ** kwargs ) <EOL> def _get_ipython_handler ( * args , ** kwargs ) : <EOL> def handle_ipython ( shell , etype , value , tb , tb_offset = None ) : <EOL> shell . showtraceback ( ( etype , value , tb ) , tb_offset = tb_offset ) <EOL> handler . handle_error ( etype , value , tb ) <EOL> return traceback . format_tb ( tb ) <EOL> return handle_ipython <EOL> ipython_shell . set_custom_exc ( ( Exception , ) , <EOL> _get_ipython_handler ( * args , ** kwargs ) ) <EOL> except NameError : <EOL> sys . excepthook = ExceptionHandler ( * args , ** kwargs ) <EOL> def off ( ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> ipython_shell = get_ipython ( ) <EOL> ipython_shell . set_custom_exc ( ( ) , None ) <EOL> except NameError : <EOL> sys . excepthook = sys . __excepthook__ </s>
