Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-37404: Raising value error if an SSLSocket is passed to asyncio functions #14457

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions Lib/asyncio/selector_events.py
Expand Up @@ -348,6 +348,8 @@ async def sock_recv(self, sock, n):
The maximum amount of data to be received at once is specified by
nbytes.
"""
if isinstance(sock, ssl.SSLSocket):
raise ValueError("the socket must not be an SSLSocket instance")
if self._debug and sock.gettimeout() != 0:
raise ValueError("the socket must be non-blocking")
try:
Expand Down Expand Up @@ -386,6 +388,8 @@ async def sock_recv_into(self, sock, buf):
The received data is written into *buf* (a writable buffer).
The return value is the number of bytes written.
"""
if isinstance(sock, ssl.SSLSocket):
raise ValueError("the socket must not be an SSLSocket instance")
if self._debug and sock.gettimeout() != 0:
raise ValueError("the socket must be non-blocking")
try:
Expand Down Expand Up @@ -425,6 +429,8 @@ async def sock_sendall(self, sock, data):
raised, and there is no way to determine how much data, if any, was
successfully processed by the receiving end of the connection.
"""
if isinstance(sock, ssl.SSLSocket):
raise ValueError("the socket must not be an SSLSocket instance")
if self._debug and sock.gettimeout() != 0:
raise ValueError("the socket must be non-blocking")
try:
Expand Down Expand Up @@ -472,6 +478,8 @@ async def sock_connect(self, sock, address):

This method is a coroutine.
"""
if isinstance(sock, ssl.SSLSocket):
raise ValueError("the socket must not be an SSLSocket instance")
if self._debug and sock.gettimeout() != 0:
raise ValueError("the socket must be non-blocking")

Expand Down Expand Up @@ -533,6 +541,8 @@ async def sock_accept(self, sock):
object usable to send and receive data on the connection, and address
is the address bound to the socket on the other end of the connection.
"""
if isinstance(sock, ssl.SSLSocket):
raise ValueError("the socket must not be an SSLSocket instance")
if self._debug and sock.gettimeout() != 0:
raise ValueError("the socket must be non-blocking")
fut = self.create_future()
Expand Down
@@ -0,0 +1,7 @@
Raising an error if the socket passed to the following functions is an ssl.SSLSocket instance. Since, as discussed in the issue, these functions do not support SSLSocket.

- sock_recv
- sock_recv_into
- sock_sendall
- sock_connect
- sock_accept