bpo-28369: Enhance transport socket check in add_reader/writer (#4365)

This commit is contained in:
Yury Selivanov 2017-11-13 13:38:22 -05:00 committed by GitHub
parent f76231f89a
commit ce12629c84
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 90 additions and 1 deletions

View file

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

View file

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