MCPcopy Index your code
hub / github.com/python/cpython / _fileobj_lookup

Method _fileobj_lookup

Lib/selectors.py:219–236  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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)):

Callers 6

registerMethod · 0.95
unregisterMethod · 0.95
modifyMethod · 0.95
getMethod · 0.80
__getitem__Method · 0.80
modifyMethod · 0.80

Calls 2

_fileobj_to_fdFunction · 0.85
valuesMethod · 0.45

Tested by

no test coverage detected