Fix Issue #4066: smtplib.SMTP_SSL._get_socket now correctly returns
the socket. Patch by Farhan Ahmad, test by Marcin Bachry.
diff --git a/Lib/smtplib.py b/Lib/smtplib.py
index 69d7f71..9300474 100755
--- a/Lib/smtplib.py
+++ b/Lib/smtplib.py
@@ -754,9 +754,10 @@
def _get_socket(self, host, port, timeout):
if self.debuglevel > 0: print>>stderr, 'connect:', (host, port)
- self.sock = socket.create_connection((host, port), timeout)
- self.sock = ssl.wrap_socket(self.sock, self.keyfile, self.certfile)
- self.file = SSLFakeFile(self.sock)
+ new_socket = socket.create_connection((host, port), timeout)
+ new_socket = ssl.wrap_socket(new_socket, self.keyfile, self.certfile)
+ self.file = SSLFakeFile(new_socket)
+ return new_socket
__all__.append("SMTP_SSL")
diff --git a/Lib/test/test_smtpnet.py b/Lib/test/test_smtpnet.py
new file mode 100644
index 0000000..c38eeee
--- /dev/null
+++ b/Lib/test/test_smtpnet.py
@@ -0,0 +1,26 @@
+#!/usr/bin/env python
+
+import unittest
+from test import test_support
+import smtplib
+
+test_support.requires(
+ "network",
+ "use of network resource is not enabled and "
+ "test requires Internet access for communication with smtp.gmail.com:465",
+ )
+
+class SmtpSSLTest(unittest.TestCase):
+ testServer = 'smtp.gmail.com'
+ remotePort = 465
+
+ def test_connect(self):
+ server = smtplib.SMTP_SSL(self.testServer, self.remotePort)
+ server.ehlo()
+ server.quit()
+
+def test_main():
+ test_support.run_unittest(SmtpSSLTest)
+
+if __name__ == "__main__":
+ test_main()