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, cb, flags): #if flags & WRITE: # ex = self.writers.get(fd) # if ex and ex.__name__ == '_write_job': # assert not ex.gi_frame or ex.gi_frame == -1 self.poller.register(fd, flags) (self.readers if flags & READ else self.writers)[fileno(fd)] = cb
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 _discard(self, fd): fd = fileno(fd) self.readers.pop(fd, None) self.writers.pop(fd, None)
def _add(self, fd, cb, flags): self.poller.register(fd, flags) (self.readers if flags & READ else self.writers)[fileno(fd)] = cb
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)
def remove_coro(self, fds): for fd in maybe_list(fds, None): self.coros.pop(fileno(fd), None)
def add_coro(self, fds, coro, flags): for fd in (fileno(f) for f in maybe_list(fds, None)): self._add(fd, self.trampoline, flags) self.coros[fd] = coro