diff options
| author | bwarsaw | 2007-05-28 20:21:41 +0000 |
|---|---|---|
| committer | bwarsaw | 2007-05-28 20:21:41 +0000 |
| commit | b18f632faa6de17badabb3c6c7ba61752ac84c37 (patch) | |
| tree | 8b444330b288c5dfc9b25be639d429abfaeb3d3d /Mailman/Pending.py | |
| parent | 5ff792b13599920527b48f92f8bad880668f8f26 (diff) | |
| download | mailman-b18f632faa6de17badabb3c6c7ba61752ac84c37.tar.gz mailman-b18f632faa6de17badabb3c6c7ba61752ac84c37.tar.zst mailman-b18f632faa6de17badabb3c6c7ba61752ac84c37.zip | |
Diffstat (limited to 'Mailman/Pending.py')
| -rw-r--r-- | Mailman/Pending.py | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/Mailman/Pending.py b/Mailman/Pending.py index f5794453d..1d133e018 100644 --- a/Mailman/Pending.py +++ b/Mailman/Pending.py @@ -17,6 +17,8 @@ """Track pending actions which require confirmation.""" +from __future__ import with_statement + import os import sha import time @@ -51,7 +53,7 @@ _default = object() class Pending: def InitTempVars(self): - self.__pendfile = os.path.join(self.fullpath(), 'pending.pck') + self._pendfile = os.path.join(self.full_path, 'pending.pck') def pend_new(self, op, *content, **kws): """Create a new entry in the pending database, returning cookie for it. @@ -87,14 +89,12 @@ class Pending: def __load(self): try: - fp = open(self.__pendfile) + with open(self._pendfile) as fp: + return cPickle.load(fp) except IOError, e: - if e.errno <> errno.ENOENT: raise + if e.errno <> errno.ENOENT: + raise return {'evictions': {}} - try: - return cPickle.load(fp) - finally: - fp.close() def __save(self, db): evictions = db['evictions'] @@ -112,15 +112,12 @@ class Pending: if not db.has_key(cookie): del evictions[cookie] db['version'] = config.PENDING_FILE_SCHEMA_VERSION - tmpfile = '%s.tmp.%d.%d' % (self.__pendfile, os.getpid(), now) - fp = open(tmpfile, 'w') - try: + tmpfile = '%s.tmp.%d.%d' % (self._pendfile, os.getpid(), now) + with open(tmpfile, 'w') as fp: cPickle.dump(db, fp) fp.flush() os.fsync(fp.fileno()) - finally: - fp.close() - os.rename(tmpfile, self.__pendfile) + os.rename(tmpfile, self._pendfile) def pend_confirm(self, cookie, expunge=True): """Return data for cookie, or None if not found. |
