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>try:<EOL><INDENT>self.poll.unregister(old_fileno)<EOL><DEDENT>except KeyError:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>if not prepared:<EOL><INDENT>self._unprepared_handlers[handler] = fileno<EOL><DEDENT>if not fileno:<EOL><INDENT>return<EOL><DEDENT>self._handlers[fileno] = handler<EOL>events = <NUM_LIT:0><EOL>if handler.is_readable():<EOL><INDENT>logger.debug("<STR_LIT>".format(handler))<EOL>events |= select.POLLIN<EOL><DEDENT>if handler.is_writable():<EOL><INDENT>logger.debug("<STR_LIT>".format(handler))<EOL>events |= select.POLLOUT<EOL><DEDENT>if events:<EOL><INDENT>logger.debug("<STR_LIT>"<EOL>"<STR_LIT>".format(handler, fileno, events))<EOL>self.poll.register(fileno, events)<EOL><DEDENT>
Register an io-handler at the polling object.