#NEWLINE# def _handle_events( self , fd , events ) : #NEWLINE# #INDENT# if self . closed ( ) : #NEWLINE# #INDENT# gen_log . warning ( 'Got events for closed stream %d' , fd ) #NEWLINE# return #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# if ( events & self . io_loop . READ ) : #NEWLINE# #INDENT# self . _handle_read ( ) #NEWLINE# #UNINDENT# if self . closed ( ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# if ( events & self . io_loop . WRITE ) : #NEWLINE# #INDENT# if self . _connecting : #NEWLINE# #INDENT# self . _handle_connect ( ) #NEWLINE# #UNINDENT# self . _handle_write ( ) #NEWLINE# #UNINDENT# if self . closed ( ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# if ( events & self . io_loop . ERROR ) : #NEWLINE# #INDENT# self . error = self . get_fd_error ( ) #NEWLINE# self . io_loop . add_callback ( self . close ) #NEWLINE# return #NEWLINE# #UNINDENT# state = self . io_loop . ERROR #NEWLINE# if self . reading ( ) : #NEWLINE# #INDENT# state |= self . io_loop . READ #NEWLINE# #UNINDENT# if self . writing ( ) : #NEWLINE# #INDENT# state |= self . io_loop . WRITE #NEWLINE# #UNINDENT# if ( events == self . io_loop . ERROR ) : #NEWLINE# #INDENT# state |= self . io_loop . READ #NEWLINE# #UNINDENT# if ( state != self . _state ) : #NEWLINE# #INDENT# assert ( self . _state is not None ) , "shouldn't happen: _handle_events without self._state" #NEWLINE# self . _state = state #NEWLINE# self . io_loop . update_handler ( self . fileno ( ) , self . _state ) #NEWLINE# #UNINDENT# #UNINDENT# except Exception : #NEWLINE# #INDENT# gen_log . error ( 'Uncaught exception, closing connection.' , exc_info = True ) #NEWLINE# self . close ( exc_info = True ) #NEWLINE# raise