]> granicus.if.org Git - python/commitdiff
Issue 11291: poplib suppresses errors on QUIT.
authorGiampaolo Rodolà <g.rodola@gmail.com>
Fri, 25 Feb 2011 22:28:24 +0000 (22:28 +0000)
committerGiampaolo Rodolà <g.rodola@gmail.com>
Fri, 25 Feb 2011 22:28:24 +0000 (22:28 +0000)
Lib/poplib.py
Lib/test/test_poplib.py
Misc/NEWS

index 84ea88de46b7e67e926da77794c82263170813b9..d42d9dd32024ac97c841cd03a87852c7c2ba4a5e 100644 (file)
@@ -250,15 +250,18 @@ class POP3:
 
     def quit(self):
         """Signoff: commit changes on server, unlock mailbox, close connection."""
-        try:
-            resp = self._shortcmd('QUIT')
-        except error_proto as val:
-            resp = val
-        self.file.close()
-        self.sock.close()
-        del self.file, self.sock
+        resp = self._shortcmd('QUIT')
+        self.close()
         return resp
 
+    def close(self):
+        """Close the connection without assuming anything about it."""
+        if self.file is not None:
+            self.file.close()
+        if self.sock is not None:
+            self.sock.close()
+        self.file = self.sock = None
+
     #__del__ = quit
 
 
index 81af56989fe5af4314b52aa4abb181716d7b9cc4..0a3adccb65502a00dfe2b2405328ceb149615963 100644 (file)
@@ -108,6 +108,10 @@ class DummyPOP3Handler(asynchat.async_chat):
     def cmd_apop(self, arg):
         self.push('+OK done nothing.')
 
+    def cmd_quit(self, arg):
+        self.push('+OK closing.')
+        self.close_when_done()
+
 
 class DummyPOP3Server(asyncore.dispatcher, threading.Thread):
 
@@ -165,10 +169,10 @@ class TestPOP3Class(TestCase):
     def setUp(self):
         self.server = DummyPOP3Server((HOST, PORT))
         self.server.start()
-        self.client = poplib.POP3(self.server.host, self.server.port)
+        self.client = poplib.POP3(self.server.host, self.server.port, timeout=3)
 
     def tearDown(self):
-        self.client.quit()
+        self.client.close()
         self.server.stop()
 
     def test_getwelcome(self):
@@ -228,6 +232,12 @@ class TestPOP3Class(TestCase):
         self.client.uidl()
         self.client.uidl('foo')
 
+    def test_quit(self):
+        resp = self.client.quit()
+        self.assertTrue(resp)
+        self.assertIsNone(self.client.sock)
+        self.assertIsNone(self.client.file)
+
 
 SUPPORTS_SSL = False
 if hasattr(poplib, 'POP3_SSL'):
@@ -274,6 +284,7 @@ if hasattr(poplib, 'POP3_SSL'):
             else:
                 DummyPOP3Handler.handle_read(self)
 
+
     class TestPOP3_SSLClass(TestPOP3Class):
         # repeat previous tests by using poplib.POP3_SSL
 
index 8acaf43065356765d629a5ae25dca64d79887b8b..59e01cde2226e265986cebbcc7bead974fecc324 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -35,6 +35,8 @@ Core and Builtins
 Library
 -------
 
+- Issue 11291: poplib.POP no longer suppresses errors on quit().
+
 - Issue 11177: asyncore's create_socket() arguments can now be omitted.
 
 - Issue #6064: Add a ``daemon`` keyword argument to the threading.Thread