bpo-40262: SSLSocket.recv_into() shouldn't require __len__
This commit is contained in:
parent
b831129123
commit
51fdd774da
|
@ -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:
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
The :meth:`ssl.SSLSocket.recv_into` method no longer requires the *buffer*
|
||||
argument to implement ``__len__``.
|
Loading…
Reference in New Issue