[Python-checkins] r54660 - python/branches/amk-mailbox/Lib/mailbox.py

andrew.kuchling python-checkins at python.org
Mon Apr 2 19:39:53 CEST 2007


Author: andrew.kuchling
Date: Mon Apr  2 19:39:52 2007
New Revision: 54660

Modified:
   python/branches/amk-mailbox/Lib/mailbox.py
Log:
Simplify MH.remove().  

Locking a file and then removing it seems to be dodgy practice, and I
don't see what good it does to lock a file you're about to remove
completely. 


Modified: python/branches/amk-mailbox/Lib/mailbox.py
==============================================================================
--- python/branches/amk-mailbox/Lib/mailbox.py	(original)
+++ python/branches/amk-mailbox/Lib/mailbox.py	Mon Apr  2 19:39:52 2007
@@ -871,24 +871,9 @@
     def remove(self, key):
         """Remove the keyed message; raise KeyError if it doesn't exist."""
         path = os.path.join(self._path, str(key))
-        try:
-            f = open(path, 'rb+')
-        except IOError, e:
-            if e.errno == errno.ENOENT:
-                raise KeyError('No message with key: %s' % key)
-            else:
-                raise
-        try:
-            if self._locked:
-                _lock_file(f)
-            try:
-                f.close()
-                os.remove(os.path.join(self._path, str(key)))
-            finally:
-                if self._locked:
-                    _unlock_file(f)
-        finally:
-            f.close()
+        if not os.path.exists(path):
+            raise KeyError('No message with key: %s' % key)
+        os.remove(path)
 
     def __setitem__(self, key, message):
         """Replace the keyed message; raise KeyError if it doesn't exist."""


More information about the Python-checkins mailing list