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>tag = self._io_sources.pop(handler, None)<EOL>if tag is not None:<EOL><INDENT>glib.source_remove(tag)<EOL><DEDENT><DEDENT>if not prepared:<EOL><INDENT>self._unprepared_handlers[handler] = fileno<EOL><DEDENT>if fileno is None:<EOL><INDENT>logger.debug("<STR_LIT>"<EOL>.format(handler))<EOL>return<EOL><DEDENT>events = <NUM_LIT:0><EOL>if handler.is_readable():<EOL><INDENT>logger.debug("<STR_LIT>".format(handler))<EOL>events |= glib.IO_IN | glib.IO_ERR<EOL><DEDENT>if handler.is_writable():<EOL><INDENT>logger.debug("<STR_LIT>".format(handler))<EOL>events |= glib.IO_OUT | glib.IO_HUP | glib.IO_ERR<EOL><DEDENT>if events:<EOL><INDENT>logger.debug("<STR_LIT>"<EOL>"<STR_LIT>".format(handler, fileno, events))<EOL>glib.io_add_watch(fileno, events, self._io_callback, handler)<EOL><DEDENT>
Register an io-handler with the glib main loop.