def _configure_io_handler(self, handler):
if self.check_events():<EOL><INDENT>return<EOL><DEDENT>if handler in self._unprepared_handlers:<EOL><INDENT>old_fileno = self._unprepared_handlers[handler]<EOL>prepared = self._prepare_io_handler(handler)<EOL><DEDENT>else:<EOL><INDENT>old_fileno = None<EOL>prepared = True<EOL><DEDENT>fileno = handler.fileno()<EOL>if old_fileno is not None and fileno != old_fileno:<EOL><INDENT>del self._handlers[old_fileno]<EOL>self.io_loop.remove_handler(old_fileno)<EOL><DEDENT>if not prepared:<EOL><INDENT>self._unprepared_handlers[handler] = fileno<EOL><DEDENT>if not fileno:<EOL><INDENT>return<EOL><DEDENT>update = fileno in self._handlers<EOL>events = ioloop.IOLoop.NONE<EOL>if handler.is_readable():<EOL><INDENT>logger.debug("<STR_LIT>".format(handler))<EOL>events |= ioloop.IOLoop.READ<EOL><DEDENT>if handler.is_writable():<EOL><INDENT>logger.debug("<STR_LIT>".format(handler))<EOL>events |= ioloop.IOLoop.WRITE<EOL><DEDENT>if self._handlers.get(fileno, None) == events:<EOL><INDENT>return<EOL><DEDENT>self._handlers[fileno] = events<EOL>if events:<EOL><INDENT>logger.debug("<STR_LIT>"<EOL>"<STR_LIT>".format(handler, fileno, events))<EOL>if update:<EOL><INDENT>self.io_loop.update_handler(fileno, events)<EOL><DEDENT>else:<EOL><INDENT>self.io_loop.add_handler(<EOL>fileno, partial(self._handle_event, handler), events<EOL>)<EOL><DEDENT><DEDENT>
Register an io-handler at the polling object.