diff options
author | Martin v. Löwis <martin@v.loewis.de> | 2006-05-04 14:27:52 (GMT) |
---|---|---|
committer | Martin v. Löwis <martin@v.loewis.de> | 2006-05-04 14:27:52 (GMT) |
commit | 08041d582b539aec159ec51d2759c0f8876cd151 (patch) | |
tree | 67d60b85069b1faeca4bc342048b724b94ff3b89 | |
parent | 4fc2bda8d9a9e8a43192e9e714d442e85cb52cbc (diff) | |
download | cpython-08041d582b539aec159ec51d2759c0f8876cd151.zip cpython-08041d582b539aec159ec51d2759c0f8876cd151.tar.gz cpython-08041d582b539aec159ec51d2759c0f8876cd151.tar.bz2 |
Update checks to consider Windows error numbers.
-rwxr-xr-x | Lib/mailbox.py | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/Lib/mailbox.py b/Lib/mailbox.py index 14de30b..2d3553a 100755 --- a/Lib/mailbox.py +++ b/Lib/mailbox.py @@ -2,6 +2,7 @@ """Read/write support for Maildir, mbox, MH, Babyl, and MMDF mailboxes.""" +import sys import os import time import calendar @@ -23,6 +24,11 @@ __all__ = [ 'Mailbox', 'Maildir', 'mbox', 'MH', 'Babyl', 'MMDF', 'BabylMessage', 'MMDFMessage', 'UnixMailbox', 'PortableUnixMailbox', 'MmdfMailbox', 'MHMailbox', 'BabylMailbox' ] +if sys.platform != 'win32': + # Define WindowsError so that we can use it in an except statement + # even on non-Windows systems + class WindowsError: + pass class Mailbox: """A group of messages in a particular place.""" @@ -262,10 +268,11 @@ class Maildir(Mailbox): self.remove(key) except KeyError: pass + except WindowsError, e: + if e.errno != 2: # ERROR_FILE_NOT_FOUND + raise except OSError, e: - if e.errno == errno.ENOENT: - pass - else: + if e.errno != errno.ENOENT: raise def __setitem__(self, key, message): @@ -419,6 +426,12 @@ class Maildir(Mailbox): path = os.path.join(self._path, 'tmp', uniq) try: os.stat(path) + except WindowsError, e: + if e.errno == 2: # ERROR_FILE_NOT_FOUND + Maildir._count += 1 + return open(path, 'wb+') + else: + raise except OSError, e: if e.errno == errno.ENOENT: Maildir._count += 1 @@ -566,6 +579,12 @@ class _singlefileMailbox(Mailbox): self._file.close() try: os.rename(new_file.name, self._path) + except WindowsError, e: + if e.errno == 183: # ERROR_ALREADY_EXISTS + os.remove(self._path) + os.rename(new_file.name, self._path) + else: + raise except OSError, e: if e.errno == errno.EEXIST: os.remove(self._path) @@ -1837,6 +1856,13 @@ def _lock_file(f, dotlock=True): else: os.rename(pre_lock.name, f.name + '.lock') dotlock_done = True + except WindowsError, e: + if e.errno == 183: # ERROR_ALREADY_EXISTS + os.remove(pre_lock.name) + raise ExternalClashError('dot lock unavailable: %s' % + f.name) + else: + raise except OSError, e: if e.errno == errno.EEXIST: os.remove(pre_lock.name) |