'Register a file object for a set of events to monitor.'

def register(self, fileobj, events, data=None):

    if ((not events) or (events & (~ (EVENT_READ | EVENT_WRITE)))):
        raise ValueError('Invalid    events:    {0!r}'.format(events))
    key = SelectorKey(fileobj, self._fileobj_lookup(fileobj), events, data)
    if (key.fd in self._fd_to_key):
        raise KeyError('{0!r}    (FD    {1})    is    already    registered'.format(fileobj, key.fd))
    self._fd_to_key[key.fd] = key
    return key
