mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
Backport Python 3.2 fix for issue #12065, and add another test for SSLSocket.connect_ex().
This commit is contained in:
parent
c4051aa8eb
commit
40f12ab0c5
3 changed files with 42 additions and 9 deletions
20
Lib/ssl.py
20
Lib/ssl.py
|
@ -313,17 +313,19 @@ class SSLSocket(socket):
|
||||||
self.cert_reqs, self.ssl_version,
|
self.cert_reqs, self.ssl_version,
|
||||||
self.ca_certs, self.ciphers)
|
self.ca_certs, self.ciphers)
|
||||||
try:
|
try:
|
||||||
socket.connect(self, addr)
|
|
||||||
if self.do_handshake_on_connect:
|
|
||||||
self.do_handshake()
|
|
||||||
except socket_error as e:
|
|
||||||
if return_errno:
|
if return_errno:
|
||||||
return e.errno
|
rc = socket.connect_ex(self, addr)
|
||||||
else:
|
else:
|
||||||
self._sslobj = None
|
rc = None
|
||||||
raise e
|
socket.connect(self, addr)
|
||||||
self._connected = True
|
if not rc:
|
||||||
return 0
|
if self.do_handshake_on_connect:
|
||||||
|
self.do_handshake()
|
||||||
|
self._connected = True
|
||||||
|
return rc
|
||||||
|
except socket_error:
|
||||||
|
self._sslobj = None
|
||||||
|
raise
|
||||||
|
|
||||||
def connect(self, addr):
|
def connect(self, addr):
|
||||||
"""Connects to remote ADDR, and then wraps the connection in
|
"""Connects to remote ADDR, and then wraps the connection in
|
||||||
|
|
|
@ -280,6 +280,34 @@ class NetworkedTests(unittest.TestCase):
|
||||||
finally:
|
finally:
|
||||||
s.close()
|
s.close()
|
||||||
|
|
||||||
|
def test_timeout_connect_ex(self):
|
||||||
|
# Issue #12065: on a timeout, connect_ex() should return the original
|
||||||
|
# errno (mimicking the behaviour of non-SSL sockets).
|
||||||
|
with test_support.transient_internet("svn.python.org"):
|
||||||
|
s = ssl.wrap_socket(socket.socket(socket.AF_INET),
|
||||||
|
cert_reqs=ssl.CERT_REQUIRED,
|
||||||
|
ca_certs=SVN_PYTHON_ORG_ROOT_CERT,
|
||||||
|
do_handshake_on_connect=False)
|
||||||
|
try:
|
||||||
|
s.settimeout(0.0000001)
|
||||||
|
rc = s.connect_ex(('svn.python.org', 443))
|
||||||
|
if rc == 0:
|
||||||
|
self.skipTest("svn.python.org responded too quickly")
|
||||||
|
self.assertIn(rc, (errno.EAGAIN, errno.EWOULDBLOCK))
|
||||||
|
finally:
|
||||||
|
s.close()
|
||||||
|
|
||||||
|
def test_connect_ex_error(self):
|
||||||
|
with test_support.transient_internet("svn.python.org"):
|
||||||
|
s = ssl.wrap_socket(socket.socket(socket.AF_INET),
|
||||||
|
cert_reqs=ssl.CERT_REQUIRED,
|
||||||
|
ca_certs=SVN_PYTHON_ORG_ROOT_CERT)
|
||||||
|
try:
|
||||||
|
self.assertEqual(errno.ECONNREFUSED,
|
||||||
|
s.connect_ex(("svn.python.org", 444)))
|
||||||
|
finally:
|
||||||
|
s.close()
|
||||||
|
|
||||||
@unittest.skipIf(os.name == "nt", "Can't use a socket as a file under Windows")
|
@unittest.skipIf(os.name == "nt", "Can't use a socket as a file under Windows")
|
||||||
def test_makefile_close(self):
|
def test_makefile_close(self):
|
||||||
# Issue #5238: creating a file-like object with makefile() shouldn't
|
# Issue #5238: creating a file-like object with makefile() shouldn't
|
||||||
|
|
|
@ -175,6 +175,9 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #12065: connect_ex() on an SSL socket now returns the original errno
|
||||||
|
when the socket's timeout expires (it used to return None).
|
||||||
|
|
||||||
- Issue #16504: IDLE now catches SyntaxErrors raised by tokenizer. Patch by
|
- Issue #16504: IDLE now catches SyntaxErrors raised by tokenizer. Patch by
|
||||||
Roger Serwy.
|
Roger Serwy.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue