Return a file descriptor from a file object. This wraps _fileobj_to_fd() to do an exhaustive search in case the object is invalid but we still have it in our map. This is used by unregister() so we can unregister an object that was previously registered even if it i
(self, fileobj)
| 217 | self._map = _SelectorMapping(self) |
| 218 | |
| 219 | def _fileobj_lookup(self, fileobj): |
| 220 | """Return a file descriptor from a file object. |
| 221 | |
| 222 | This wraps _fileobj_to_fd() to do an exhaustive search in case |
| 223 | the object is invalid but we still have it in our map. This |
| 224 | is used by unregister() so we can unregister an object that |
| 225 | was previously registered even if it is closed. It is also |
| 226 | used by _SelectorMapping. |
| 227 | """ |
| 228 | try: |
| 229 | return _fileobj_to_fd(fileobj) |
| 230 | except ValueError: |
| 231 | # Do an exhaustive search. |
| 232 | for key in self._fd_to_key.values(): |
| 233 | if key.fileobj is fileobj: |
| 234 | return key.fd |
| 235 | # Raise ValueError after all. |
| 236 | raise |
| 237 | |
| 238 | def register(self, fileobj, events, data=None): |
| 239 | if (not events) or (events & ~(EVENT_READ | EVENT_WRITE)): |
no test coverage detected