def _callback_for(self, fd, flag, *default): try: if flag & READ: return self.readers[fileno(fd)] if flag & WRITE: return self.writers[fileno(fd)] except KeyError: if default: return default[0] raise
def add(self, fd, callback, flags, args=(), consolidate=False): try: self.poller.register(fd, flags) except ValueError: self._discard(fd) else: dest = self.readers if flags & READ else self.writers if consolidate: self.consolidate.add(fd) dest[fileno(fd)] = None else: dest[fileno(fd)] = callback, args
def add(self, fd, callback, flags, args=(), consolidate=False): fd = fileno(fd) try: self.poller.register(fd, flags) except ValueError: self._remove_from_loop(fd) raise else: dest = self.readers if flags & READ else self.writers if consolidate: self.consolidate.add(fd) dest[fd] = None else: dest[fd] = callback, args
def add(self, fd, callback, flags, args=(), consolidate=False): print 'Adding %s to hub' % fd fd = fileno(fd) try: self.poller.register(fd, flags) except ValueError: self._discard(fd) raise else: dest = self.readers if flags & READ else self.writers if consolidate: self.consolidate.add(fd) dest[fd] = None else: dest[fd] = callback, args
def _discard(self, fd): fd = fileno(fd) self.readers.pop(fd, None) self.writers.pop(fd, None) self.consolidate.discard(fd)
def remove(self, fd): fd = fileno(fd) self._unregister(fd) self._discard(fd)
def remove(self, fd): fd = fileno(fd) self._remove_from_loop(fd)
def _add(self, fd, cb, flags, consolidate=False): self.poller.register(fd, flags) (self.readers if flags & READ else self.writers)[fileno(fd)] = cb if consolidate: self.consolidate.add(fd)