cpython: c37cb11b546f (original) (raw)

Mercurial > cpython

changeset 77832:c37cb11b546f 2.7

#9559: Append data to single-file mailbox files if messages are only added If messages were only added, a new file is no longer created and renamed over the old file when flush() is called on an mbox, MMDF or Babyl mailbox. [#9559]

Petri Lehtinen petri@digip.org
date Thu, 28 Jun 2012 13:48:17 +0300
parents 73710ae9fedc
children 49dee01d72f9
files Lib/mailbox.py Lib/test/test_mailbox.py Misc/NEWS
diffstat 3 files changed, 46 insertions(+), 5 deletions(-)[+] [-] Lib/mailbox.py 18 Lib/test/test_mailbox.py 29 Misc/NEWS 4

line wrap: on

line diff

--- a/Lib/mailbox.py +++ b/Lib/mailbox.py @@ -561,16 +561,19 @@ class _singlefileMailbox(Mailbox): self._file = f self._toc = None self._next_key = 0

def add(self, message): """Add message and return assigned key.""" self._lookup() self._toc[self._next_key] = self._append_message(message) self._next_key += 1

def remove(self, key): @@ -616,6 +619,11 @@ class _singlefileMailbox(Mailbox): def flush(self): """Write any pending changes to disk.""" if not self._pending:

# In order to be writing anything out at all, self._toc must @@ -669,6 +677,7 @@ class _singlefileMailbox(Mailbox): self._file = open(self._path, 'rb+') self._toc = new_toc self._pending = False

@@ -705,6 +714,9 @@ class _singlefileMailbox(Mailbox): """Append message to mailbox and return (start, stop) offsets.""" self._file.seek(0, 2) before = self._file.tell()

--- a/Lib/test/test_mailbox.py +++ b/Lib/test/test_mailbox.py @@ -824,7 +824,32 @@ class TestMaildir(TestMailbox, unittest. self._box._refresh() self.assertTrue(refreshed()) -class _TestMboxMMDF(TestMailbox): + +class _TestSingleFile(TestMailbox):

+

+

+

+

+

+ + +class _TestMboxMMDF(_TestSingleFile): def tearDown(self): self._box.close() @@ -1085,7 +1110,7 @@ class TestMH(TestMailbox, unittest.TestC return os.path.join(self._path, '.mh_sequences.lock') -class TestBabyl(TestMailbox, unittest.TestCase): +class TestBabyl(_TestSingleFile, unittest.TestCase): _factory = lambda self, path, factory=None: mailbox.Babyl(path, factory)

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -75,6 +75,10 @@ Core and Builtins Library ------- +- Issue #9559: If messages were only added, a new file is no longer