summaryrefslogtreecommitdiffstats
path: root/Lib/ssl.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2011-02-26 23:25:34 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2011-02-26 23:25:34 (GMT)
commit86cbfec50aa025a16b83c9ea1de7be438f4e7997 (patch)
treea9554bb6829927fd3ba8b5e7bc2ee4d0dcc1903b /Lib/ssl.py
parent849272bf021dd34bfe4a847e320f8e0eb21d2350 (diff)
downloadcpython-86cbfec50aa025a16b83c9ea1de7be438f4e7997.zip
cpython-86cbfec50aa025a16b83c9ea1de7be438f4e7997.tar.gz
cpython-86cbfec50aa025a16b83c9ea1de7be438f4e7997.tar.bz2
Merged revisions 88664 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ r88664 | antoine.pitrou | 2011-02-27 00:24:06 +0100 (dim., 27 févr. 2011) | 4 lines Issue #11326: Add the missing connect_ex() implementation for SSL sockets, and make it work for non-blocking connects. ........
Diffstat (limited to 'Lib/ssl.py')
-rw-r--r--Lib/ssl.py30
1 files changed, 22 insertions, 8 deletions
diff --git a/Lib/ssl.py b/Lib/ssl.py
index f1a0e45..84aa6dc 100644
--- a/Lib/ssl.py
+++ b/Lib/ssl.py
@@ -237,6 +237,7 @@ class SSLSocket(socket):
self._closed = False
self._sslobj = None
+ self._connected = connected
if connected:
# create the SSL object
try:
@@ -430,23 +431,36 @@ class SSLSocket(socket):
finally:
self.settimeout(timeout)
- def connect(self, addr):
- """Connects to remote ADDR, and then wraps the connection in
- an SSL channel."""
+ def _real_connect(self, addr, return_errno):
if self.server_side:
raise ValueError("can't connect in server-side mode")
# Here we assume that the socket is client-side, and not
# connected at the time of the call. We connect it, then wrap it.
- if self._sslobj:
+ if self._connected:
raise ValueError("attempt to connect already-connected SSLSocket!")
- socket.connect(self, addr)
self._sslobj = self.context._wrap_socket(self, False, self.server_hostname)
try:
+ socket.connect(self, addr)
if self.do_handshake_on_connect:
self.do_handshake()
- except:
- self._sslobj = None
- raise
+ except socket_error as e:
+ if return_errno:
+ return e.errno
+ else:
+ self._sslobj = None
+ raise e
+ self._connected = True
+ return 0
+
+ def connect(self, addr):
+ """Connects to remote ADDR, and then wraps the connection in
+ an SSL channel."""
+ self._real_connect(addr, False)
+
+ def connect_ex(self, addr):
+ """Connects to remote ADDR, and then wraps the connection in
+ an SSL channel."""
+ return self._real_connect(addr, True)
def accept(self):
"""Accepts a new connection from a remote client, and returns