Update checks to consider Windows error numbers.

This commit is contained in:
Martin v. Löwis 2006-05-04 14:27:52 +00:00
parent 4fc2bda8d9
commit 08041d582b
1 changed files with 29 additions and 3 deletions

View File

@ -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)