#NEWLINE# def enable_tty_echo( tty = None ) : #NEWLINE# #INDENT# '\n    Re-enables proper console behavior, primarily for when a reload is\n    triggered at a PDB prompt.\n\n    TODO: context manager for ignoring signals\n    ' #NEWLINE# if ( tty is None ) : #NEWLINE# #INDENT# tty = sys . stdin #NEWLINE# #UNINDENT# if ( not tty . isatty ( ) ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# import termios #NEWLINE# #UNINDENT# except ImportError : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# attr_list = termios . tcgetattr ( tty ) #NEWLINE# attr_list [ 3 ] |= termios . ECHO #NEWLINE# try : #NEWLINE# #INDENT# orig_handler = signal . getsignal ( signal . SIGTTOU ) #NEWLINE# #UNINDENT# except AttributeError : #NEWLINE# #INDENT# termios . tcsetattr ( tty , termios . TCSANOW , attr_list ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# signal . signal ( signal . SIGTTOU , signal . SIG_IGN ) #NEWLINE# termios . tcsetattr ( tty , termios . TCSANOW , attr_list ) #NEWLINE# #UNINDENT# finally : #NEWLINE# #INDENT# signal . signal ( signal . SIGTTOU , orig_handler ) #NEWLINE# #UNINDENT# #UNINDENT# return