[Python-checkins] r45900 - python/trunk/Lib/mailbox.py
martin.v.loewis
python-checkins at python.org
Thu May 4 16:27:52 CEST 2006
Author: martin.v.loewis
Date: Thu May 4 16:27:52 2006
New Revision: 45900
Modified:
python/trunk/Lib/mailbox.py
Log:
Update checks to consider Windows error numbers.
Modified: python/trunk/Lib/mailbox.py
==============================================================================
--- python/trunk/Lib/mailbox.py (original)
+++ python/trunk/Lib/mailbox.py Thu May 4 16:27:52 2006
@@ -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 @@
'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 @@
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 @@
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 @@
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 @@
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)
More information about the Python-checkins
mailing list