bpo-40262: SSLSocket.recv_into() shouldn't require __len__

This commit is contained in:
Zackery Spytz 2020-05-21 23:33:12 -06:00
parent b831129123
commit 51fdd774da
3 changed files with 19 additions and 1 deletions

View File

@ -1230,7 +1230,7 @@ class SSLSocket(socket):
def recv_into(self, buffer, nbytes=None, flags=0):
self._checkClosed()
if buffer and (nbytes is None):
nbytes = len(buffer)
nbytes = memoryview(buffer).nbytes
elif nbytes is None:
nbytes = 1024
if self._sslobj is not None:

View File

@ -3607,6 +3607,22 @@ class ThreadedTests(unittest.TestCase):
self.assertEqual(s.recv(0), b"")
self.assertEqual(s.recv_into(bytearray()), 0)
def test_recv_into_buffer_protocol_len(self):
server = ThreadedEchoServer(CERTFILE)
server.__enter__()
self.addCleanup(server.__exit__, None, None)
s = socket.create_connection((HOST, server.port))
self.addCleanup(s.close)
s = test_wrap_socket(s, suppress_ragged_eofs=False)
self.addCleanup(s.close)
class B(bytearray):
def __len__(self):
return 1
s.send(b"data")
self.assertEqual(s.recv_into(B(4)), 4)
def test_nonblocking_send(self):
server = ThreadedEchoServer(CERTFILE,
certreqs=ssl.CERT_NONE,

View File

@ -0,0 +1,2 @@
The :meth:`ssl.SSLSocket.recv_into` method no longer requires the *buffer*
argument to implement ``__len__``.