summaryrefslogtreecommitdiffstats
path: root/Lib/selectors.py
diff options
context:
space:
mode:
authorJ. Nick Koston <nick@koston.org>2023-07-14 18:46:30 (GMT)
committerGitHub <noreply@github.com>2023-07-14 18:46:30 (GMT)
commitaeef8591e41b68341af308e56a744396c66879cc (patch)
tree8523e90bac25c987c79c57aa46b4ba357406d8d5 /Lib/selectors.py
parent6a70edf24ca217c5ed4a556d0df5748fc775c762 (diff)
downloadcpython-aeef8591e41b68341af308e56a744396c66879cc.zip
cpython-aeef8591e41b68341af308e56a744396c66879cc.tar.gz
cpython-aeef8591e41b68341af308e56a744396c66879cc.tar.bz2
gh-106554: replace `_BaseSelectorImpl._key_from_fd` with `dict.get` (#106555)
Diffstat (limited to 'Lib/selectors.py')
-rw-r--r--Lib/selectors.py21
1 files changed, 4 insertions, 17 deletions
diff --git a/Lib/selectors.py b/Lib/selectors.py
index dfcc125..6d82935 100644
--- a/Lib/selectors.py
+++ b/Lib/selectors.py
@@ -276,19 +276,6 @@ class _BaseSelectorImpl(BaseSelector):
def get_map(self):
return self._map
- def _key_from_fd(self, fd):
- """Return the key associated to a given file descriptor.
-
- Parameters:
- fd -- file descriptor
-
- Returns:
- corresponding key, or None if not found
- """
- try:
- return self._fd_to_key[fd]
- except KeyError:
- return None
class SelectSelector(_BaseSelectorImpl):
@@ -336,7 +323,7 @@ class SelectSelector(_BaseSelectorImpl):
if fd in w:
events |= EVENT_WRITE
- key = self._key_from_fd(fd)
+ key = self._fd_to_key.get(fd)
if key:
ready.append((key, events & key.events))
return ready
@@ -426,7 +413,7 @@ class _PollLikeSelector(_BaseSelectorImpl):
if event & ~self._EVENT_WRITE:
events |= EVENT_READ
- key = self._key_from_fd(fd)
+ key = self._fd_to_key.get(fd)
if key:
ready.append((key, events & key.events))
return ready
@@ -479,7 +466,7 @@ if hasattr(select, 'epoll'):
if event & ~select.EPOLLOUT:
events |= EVENT_READ
- key = self._key_from_fd(fd)
+ key = self._fd_to_key.get(fd)
if key:
ready.append((key, events & key.events))
return ready
@@ -574,7 +561,7 @@ if hasattr(select, 'kqueue'):
if flag == select.KQ_FILTER_WRITE:
events |= EVENT_WRITE
- key = self._key_from_fd(fd)
+ key = self._fd_to_key.get(fd)
if key:
ready.append((key, events & key.events))
return ready