From b72b0eb357e9237e9de95dadda18fda433f88aac Mon Sep 17 00:00:00 2001 From: "Andrew M. Kuchling" Date: Mon, 22 Feb 2010 18:42:07 +0000 Subject: #7627: MH.remove() would fail if the MH mailbox was locked; it would call _unlock_file() and pass it a closed file object. Noted by Rob Austein. --- Lib/mailbox.py | 12 ++---------- Lib/test/test_mailbox.py | 7 +++++++ 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/Lib/mailbox.py b/Lib/mailbox.py index 4da5569..2b7b14e 100755 --- a/Lib/mailbox.py +++ b/Lib/mailbox.py @@ -892,17 +892,9 @@ class MH(Mailbox): 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: + else: f.close() + os.remove(path) def __setitem__(self, key, message): """Replace the keyed message; raise KeyError if it doesn't exist.""" diff --git a/Lib/test/test_mailbox.py b/Lib/test/test_mailbox.py index c88af06..7575ca7 100644 --- a/Lib/test/test_mailbox.py +++ b/Lib/test/test_mailbox.py @@ -979,6 +979,13 @@ class TestMH(TestMailbox): key0 = self._box.add(msg0) refmsg0 = self._box.get_message(key0) + def test_issue7627(self): + msg0 = mailbox.MHMessage(self._template % 0) + key0 = self._box.add(msg0) + self._box.lock() + self._box.remove(key0) + self._box.unlock() + def test_pack(self): # Pack the contents of the mailbox msg0 = mailbox.MHMessage(self._template % 0) -- cgit v0.12