]> granicus.if.org Git - python/commitdiff
Issue 1776581. Minor corrections to smtplib, and two small tests.
authorFacundo Batista <facundobatista@gmail.com>
Sat, 23 Feb 2008 12:27:17 +0000 (12:27 +0000)
committerFacundo Batista <facundobatista@gmail.com>
Sat, 23 Feb 2008 12:27:17 +0000 (12:27 +0000)
Thanks Alan McIntyre.

Lib/smtplib.py
Lib/test/test_smtplib.py

index bb9c239a2764cf1ead04a6acfeaf4912d7831789..75093ae0fa65cc369baf0a83aaa78294965448ad 100755 (executable)
@@ -298,7 +298,7 @@ class SMTP:
     def send(self, str):
         """Send `str' to the server."""
         if self.debuglevel > 0: print>>stderr, 'send:', repr(str)
-        if self.sock:
+        if hasattr(self, 'sock') and self.sock:
             try:
                 self.sock.sendall(str)
             except socket.error:
@@ -486,7 +486,7 @@ class SMTP:
     vrfy=verify
 
     def expn(self, address):
-        """SMTP 'verify' command -- checks for address validity."""
+        """SMTP 'expn' command -- expands a mailing list."""
         self.putcmd("expn", quoteaddr(address))
         return self.getreply()
 
index e2b9b060f440e2a07d8293516062d4a0200a0de7..933523b93045b6069fcc2c7a14a09f551252ded6 100644 (file)
@@ -82,8 +82,9 @@ class GeneralTests(TestCase):
         # to reference the nonexistent 'sock' attribute of the SMTP object
         # causes an AttributeError)
         smtp = smtplib.SMTP()
-        self.assertRaises(AttributeError, smtp.ehlo)
-        self.assertRaises(AttributeError, smtp.send, 'test msg')
+        self.assertRaises(smtplib.SMTPServerDisconnected, smtp.ehlo)
+        self.assertRaises(smtplib.SMTPServerDisconnected,
+                          smtp.send, 'test msg')
 
     def testLocalHostName(self):
         # check that supplied local_hostname is used