By default the smtplib.SMTP objects did not have a sock attribute, it
was only created during connect()
method called 'sendmail' that will do an entire mail transaction.
"""
debuglevel = 0
+
+ sock = None
file = None
helo_resp = None
ehlo_msg = "ehlo"
"""Send `s' to the server."""
if self.debuglevel > 0:
self._print_debug('send:', repr(s))
- if hasattr(self, 'sock') and self.sock:
+ if self.sock:
if isinstance(s, str):
# send is used by the 'data' command, where command_encoding
# should not be used, but 'data' needs to convert the string to
self.assertRaises(OSError, smtplib.SMTP,
"localhost:bogus")
+ def testSockAttributeExists(self):
+ # check that sock attribute is present outside of a connect() call
+ # (regression test, the previous behavior raised an
+ # AttributeError: 'SMTP' object has no attribute 'sock')
+ with smtplib.SMTP() as smtp:
+ self.assertIsNone(smtp.sock)
+
class DefaultArgumentsTests(unittest.TestCase):
--- /dev/null
+:class:`smtplib.SMTP` objects now always have a `sock` attribute present