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...
This commit is contained in:
Antoine Pitrou 2010-09-14 14:37:18 +00:00
parent 7a84877de1
commit f7f390a251
3 changed files with 29 additions and 8 deletions

View file

@ -179,6 +179,19 @@ class BasicSocketTests(unittest.TestCase):
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):