summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_poplib.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2010-04-24 21:26:44 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2010-04-24 21:26:44 (GMT)
commitd3f8ab8bd37d942d64773e9043697003b8502049 (patch)
treeea8850776e86b56cd2f820ed693f00bdde51be6c /Lib/test/test_poplib.py
parentfb88636199c12f63d6c8c89f311cdafc91f30d2f (diff)
downloadcpython-d3f8ab8bd37d942d64773e9043697003b8502049.zip
cpython-d3f8ab8bd37d942d64773e9043697003b8502049.tar.gz
cpython-d3f8ab8bd37d942d64773e9043697003b8502049.tar.bz2
Merged revisions 80451-80452 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r80451 | antoine.pitrou | 2010-04-24 21:57:01 +0200 (sam., 24 avril 2010) | 4 lines The do_handshake() method of SSL objects now adjusts the blocking mode of the SSL structure if necessary (as other methods already do). ........ r80452 | antoine.pitrou | 2010-04-24 22:04:58 +0200 (sam., 24 avril 2010) | 4 lines Issue #5103: SSL handshake would ignore the socket timeout and block indefinitely if the other end didn't respond. ........
Diffstat (limited to 'Lib/test/test_poplib.py')
-rw-r--r--Lib/test/test_poplib.py29
1 files changed, 28 insertions, 1 deletions
diff --git a/Lib/test/test_poplib.py b/Lib/test/test_poplib.py
index 27e3a9f..aa703c5 100644
--- a/Lib/test/test_poplib.py
+++ b/Lib/test/test_poplib.py
@@ -10,6 +10,7 @@ import asynchat
import socket
import os
import time
+import errno
from unittest import TestCase
from test import support as test_support
@@ -241,13 +242,39 @@ if hasattr(poplib, 'POP3_SSL'):
def __init__(self, conn):
asynchat.async_chat.__init__(self, conn)
ssl_socket = ssl.wrap_socket(self.socket, certfile=CERTFILE,
- server_side=True)
+ server_side=True,
+ do_handshake_on_connect=False)
self.del_channel()
self.set_socket(ssl_socket)
+ # Must try handshake before calling push()
+ self._ssl_accepting = True
+ self._do_ssl_handshake()
self.set_terminator(b"\r\n")
self.in_buffer = []
self.push('+OK dummy pop3 server ready. <timestamp>')
+ def _do_ssl_handshake(self):
+ try:
+ self.socket.do_handshake()
+ except ssl.SSLError as err:
+ if err.args[0] in (ssl.SSL_ERROR_WANT_READ,
+ ssl.SSL_ERROR_WANT_WRITE):
+ return
+ elif err.args[0] == ssl.SSL_ERROR_EOF:
+ return self.handle_close()
+ raise
+ except socket.error as err:
+ if err.args[0] == errno.ECONNABORTED:
+ return self.handle_close()
+ else:
+ self._ssl_accepting = False
+
+ def handle_read(self):
+ if self._ssl_accepting:
+ self._do_ssl_handshake()
+ else:
+ DummyPOP3Handler.handle_read(self)
+
class TestPOP3_SSLClass(TestPOP3Class):
# repeat previous tests by using poplib.POP3_SSL