@@ -122,6 +122,7 @@ def __init__(self, address, af=socket.AF_INET):
122122 self .active = False
123123 self .active_lock = threading .Lock ()
124124 self .host , self .port = self .socket .getsockname ()[:2 ]
125+ self .handler_instance = None
125126
126127 def start (self ):
127128 assert not self .active
@@ -145,8 +146,7 @@ def stop(self):
145146
146147 def handle_accept (self ):
147148 conn , addr = self .accept ()
148- self .handler = self .handler (conn )
149- self .close ()
149+ self .handler_instance = self .handler (conn )
150150
151151 def handle_connect (self ):
152152 self .close ()
@@ -287,6 +287,23 @@ def setUp(self):
287287 def test__all__ (self ):
288288 self .assertIn ('POP3_SSL' , poplib .__all__ )
289289
290+ def test_context (self ):
291+ ctx = ssl .SSLContext (ssl .PROTOCOL_TLSv1 )
292+ self .assertRaises (ValueError , poplib .POP3_SSL , self .server .host ,
293+ self .server .port , keyfile = CERTFILE , context = ctx )
294+ self .assertRaises (ValueError , poplib .POP3_SSL , self .server .host ,
295+ self .server .port , certfile = CERTFILE , context = ctx )
296+ self .assertRaises (ValueError , poplib .POP3_SSL , self .server .host ,
297+ self .server .port , keyfile = CERTFILE ,
298+ certfile = CERTFILE , context = ctx )
299+
300+ self .client .quit ()
301+ self .client = poplib .POP3_SSL (self .server .host , self .server .port ,
302+ context = ctx )
303+ self .assertIsInstance (self .client .sock , ssl .SSLSocket )
304+ self .assertIs (self .client .sock .context , ctx )
305+ self .assertTrue (self .client .noop ().startswith (b'+OK' ))
306+
290307
291308class TestTimeouts (TestCase ):
292309
0 commit comments