mirror of
https://github.com/python/cpython.git
synced 2025-09-27 10:50:04 +00:00
Update checks to consider Windows error numbers.
This commit is contained in:
parent
4fc2bda8d9
commit
08041d582b
1 changed files with 29 additions and 3 deletions
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
"""Read/write support for Maildir, mbox, MH, Babyl, and MMDF mailboxes."""
|
"""Read/write support for Maildir, mbox, MH, Babyl, and MMDF mailboxes."""
|
||||||
|
|
||||||
|
import sys
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
import calendar
|
import calendar
|
||||||
|
@ -23,6 +24,11 @@ __all__ = [ 'Mailbox', 'Maildir', 'mbox', 'MH', 'Babyl', 'MMDF',
|
||||||
'BabylMessage', 'MMDFMessage', 'UnixMailbox',
|
'BabylMessage', 'MMDFMessage', 'UnixMailbox',
|
||||||
'PortableUnixMailbox', 'MmdfMailbox', 'MHMailbox', 'BabylMailbox' ]
|
'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:
|
class Mailbox:
|
||||||
"""A group of messages in a particular place."""
|
"""A group of messages in a particular place."""
|
||||||
|
@ -262,10 +268,11 @@ class Maildir(Mailbox):
|
||||||
self.remove(key)
|
self.remove(key)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
except WindowsError, e:
|
||||||
|
if e.errno != 2: # ERROR_FILE_NOT_FOUND
|
||||||
|
raise
|
||||||
except OSError, e:
|
except OSError, e:
|
||||||
if e.errno == errno.ENOENT:
|
if e.errno != errno.ENOENT:
|
||||||
pass
|
|
||||||
else:
|
|
||||||
raise
|
raise
|
||||||
|
|
||||||
def __setitem__(self, key, message):
|
def __setitem__(self, key, message):
|
||||||
|
@ -419,6 +426,12 @@ class Maildir(Mailbox):
|
||||||
path = os.path.join(self._path, 'tmp', uniq)
|
path = os.path.join(self._path, 'tmp', uniq)
|
||||||
try:
|
try:
|
||||||
os.stat(path)
|
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:
|
except OSError, e:
|
||||||
if e.errno == errno.ENOENT:
|
if e.errno == errno.ENOENT:
|
||||||
Maildir._count += 1
|
Maildir._count += 1
|
||||||
|
@ -566,6 +579,12 @@ class _singlefileMailbox(Mailbox):
|
||||||
self._file.close()
|
self._file.close()
|
||||||
try:
|
try:
|
||||||
os.rename(new_file.name, self._path)
|
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:
|
except OSError, e:
|
||||||
if e.errno == errno.EEXIST:
|
if e.errno == errno.EEXIST:
|
||||||
os.remove(self._path)
|
os.remove(self._path)
|
||||||
|
@ -1837,6 +1856,13 @@ def _lock_file(f, dotlock=True):
|
||||||
else:
|
else:
|
||||||
os.rename(pre_lock.name, f.name + '.lock')
|
os.rename(pre_lock.name, f.name + '.lock')
|
||||||
dotlock_done = True
|
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:
|
except OSError, e:
|
||||||
if e.errno == errno.EEXIST:
|
if e.errno == errno.EEXIST:
|
||||||
os.remove(pre_lock.name)
|
os.remove(pre_lock.name)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue