diff -r 06239fe781fe Lib/ssl.py --- a/Lib/ssl.py Sun Nov 03 20:09:51 2013 -0800 +++ b/Lib/ssl.py Mon Nov 04 16:32:13 2013 +0800 @@ -144,7 +144,7 @@ from _ssl import enum_cert_store, X509_ASN_ENCODING, PKCS_7_ASN_ENCODING from socket import getnameinfo as _getnameinfo -from socket import socket, AF_INET, SOCK_STREAM, create_connection +from socket import socket, AF_INET, SOCK_STREAM, create_connection, SocketType import base64 # for DER-to-PEM translation import traceback import errno @@ -333,6 +333,9 @@ "operations") if keyfile and not certfile: raise ValueError("certfile must be specified") + if sock.type == SocketType.SOCK_DGRAM: + raise ValueError("Python SSL library does not support " + "Datagram Transport Layer Security") if certfile and not keyfile: keyfile = certfile self._context = SSLContext(ssl_version) diff -r 06239fe781fe Lib/test/test_ssl.py --- a/Lib/test/test_ssl.py Sun Nov 03 20:09:51 2013 -0800 +++ b/Lib/test/test_ssl.py Mon Nov 04 16:32:13 2013 +0800 @@ -539,6 +539,16 @@ self.assertIsInstance(ca[0][0], bytes) self.assertIsInstance(ca[0][1], int) + def test_raises_exception_on_wrap_socket_with_sock_dgram(self): + with self.assertRaises(ValueError) as cx: + s = ssl.wrap_socket(socket.socket(socket.AF_INET, + socket.SOCK_DGRAM), + cert_reqs=ssl.CERT_NONE) + self.assertEqual(str(cx.exception), + "Python SSL library does not support Datagram Transport Layer " + "Security") + + class ContextTests(unittest.TestCase): @skip_if_broken_ubuntu_ssl @@ -1147,7 +1157,6 @@ s.close() self.assertEqual(len(ctx.get_ca_certs()), 1) - try: import threading except ImportError: