Issue #9729: Fix the signature of SSLSocket.recvfrom() and
SSLSocket.sendto() to match the corresponding socket methods. Also,
fix various SSLSocket methods to raise socket.error rather than an
unhelpful TypeError when called on an unconnected socket. Original patch
by Andrew Bennetts.
NOTE: obviously, these methods are untested and unused in the real world...
diff --git a/Lib/test/test_ssl.py b/Lib/test/test_ssl.py
index d6f1fce..3726155 100644
--- a/Lib/test/test_ssl.py
+++ b/Lib/test/test_ssl.py
@@ -179,6 +179,19 @@
del ss
self.assertEqual(wr(), None)
+ def test_wrapped_unconnected(self):
+ # The _delegate_methods in socket.py are correctly delegated to by an
+ # unconnected SSLSocket, so they will raise a socket.error rather than
+ # something unexpected like TypeError.
+ s = socket.socket(socket.AF_INET)
+ ss = ssl.wrap_socket(s)
+ self.assertRaises(socket.error, ss.recv, 1)
+ self.assertRaises(socket.error, ss.recv_into, bytearray(b'x'))
+ self.assertRaises(socket.error, ss.recvfrom, 1)
+ self.assertRaises(socket.error, ss.recvfrom_into, bytearray(b'x'), 1)
+ self.assertRaises(socket.error, ss.send, b'x')
+ self.assertRaises(socket.error, ss.sendto, b'x', ('0.0.0.0', 0))
+
class NetworkedTests(unittest.TestCase):