mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
bpo-28369: Enhance transport socket check in add_reader/writer (#4365)
This commit is contained in:
parent
f76231f89a
commit
ce12629c84
4 changed files with 90 additions and 1 deletions
|
@ -246,8 +246,16 @@ class BaseSelectorEventLoop(base_events.BaseEventLoop):
|
|||
self.call_exception_handler(context)
|
||||
|
||||
def _ensure_fd_no_transport(self, fd):
|
||||
fileno = fd
|
||||
if not isinstance(fileno, int):
|
||||
try:
|
||||
fileno = int(fileno.fileno())
|
||||
except (AttributeError, TypeError, ValueError):
|
||||
# This code matches selectors._fileobj_to_fd function.
|
||||
raise ValueError("Invalid file object: "
|
||||
"{!r}".format(fd)) from None
|
||||
try:
|
||||
transport = self._transports[fd]
|
||||
transport = self._transports[fileno]
|
||||
except KeyError:
|
||||
pass
|
||||
else:
|
||||
|
|
|
@ -361,6 +361,13 @@ class TestLoop(base_events.BaseEventLoop):
|
|||
handle._args, args)
|
||||
|
||||
def _ensure_fd_no_transport(self, fd):
|
||||
if not isinstance(fd, int):
|
||||
try:
|
||||
fd = int(fd.fileno())
|
||||
except (AttributeError, TypeError, ValueError):
|
||||
# This code matches selectors._fileobj_to_fd function.
|
||||
raise ValueError("Invalid file object: "
|
||||
"{!r}".format(fd)) from None
|
||||
try:
|
||||
transport = self._transports[fd]
|
||||
except KeyError:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue