comparison mercurial/win32.py @ 8328:91f1fe78454c

win32: allow catching of both pywintypes.error and WindowsError
author Bryan O'Sullivan <bos@serpentine.com>
date Thu, 26 Mar 2009 13:13:48 -0700
parents 0a9542703300
children 79a12651d46b
comparison
equal deleted inserted replaced
8327:aa25be1c2889 8328:91f1fe78454c
129 winerror.ERROR_WRITE_FAULT: errno.EIO, 129 winerror.ERROR_WRITE_FAULT: errno.EIO,
130 winerror.ERROR_WRITE_PROTECT: errno.EROFS, 130 winerror.ERROR_WRITE_PROTECT: errno.EROFS,
131 } 131 }
132 132
133 def __init__(self, err): 133 def __init__(self, err):
134 self.win_errno, self.win_function, self.win_strerror = err 134 try:
135 if self.win_strerror.endswith('.'): 135 # unpack a pywintypes.error tuple
136 self.win_strerror = self.win_strerror[:-1] 136 self.win_errno, self.win_function, self.win_strerror = err
137 except ValueError:
138 # get attributes from a WindowsError
139 self.win_errno = err.winerror
140 self.win_function = None
141 self.win_strerror = err.strerror
142 self.win_strerror = self.win_strerror.rstrip('.')
137 143
138 class WinIOError(WinError, IOError): 144 class WinIOError(WinError, IOError):
139 def __init__(self, err, filename=None): 145 def __init__(self, err, filename=None):
140 WinError.__init__(self, err) 146 WinError.__init__(self, err)
141 IOError.__init__(self, self.winerror_map.get(self.win_errno, 0), 147 IOError.__init__(self, self.winerror_map.get(self.win_errno, 0),