'Helper to dispatch callbacks for file descriptors that received
events.
Before doing so we re-calculate the event mask based on what is
currently set in case it has been changed under our feet by a
previous callback. We also take a store a refernce to the
fd_event_map so that we can detect removal of an
fileno during processing of another callback and not generate
spurious callbacks on it.
:param dict fd_event_map: Map of fds to events received on them.'

def _dispatch_fd_events(self, fd_event_map):

    self._processing_fd_event_map.clear()
    self._processing_fd_event_map = fd_event_map
    for fileno in dictkeys(fd_event_map):
        if (fileno not in fd_event_map):
            continue
        events = fd_event_map[fileno]
        for evt in [READ, WRITE, ERROR]:
            if (fileno not in self._fd_events[evt]):
                events &= (~ evt)
        if events:
            handler = self._fd_handlers[fileno]
            handler(fileno, events)
