win32: allow catching of both pywintypes.error and WindowsError
authorBryan O'Sullivan <bos@serpentine.com>
Thu, 26 Mar 2009 13:13:48 -0700
changeset 8328 91f1fe78454c
parent 8327 aa25be1c2889
child 8329 79a12651d46b
win32: allow catching of both pywintypes.error and WindowsError
mercurial/win32.py
--- a/mercurial/win32.py	Thu Mar 26 13:12:11 2009 -0700
+++ b/mercurial/win32.py	Thu Mar 26 13:13:48 2009 -0700
@@ -131,9 +131,15 @@
         }
 
     def __init__(self, err):
-        self.win_errno, self.win_function, self.win_strerror = err
-        if self.win_strerror.endswith('.'):
-            self.win_strerror = self.win_strerror[:-1]
+        try:
+            # unpack a pywintypes.error tuple
+            self.win_errno, self.win_function, self.win_strerror = err
+        except ValueError:
+            # get attributes from a WindowsError
+            self.win_errno = err.winerror
+            self.win_function = None
+            self.win_strerror = err.strerror
+        self.win_strerror = self.win_strerror.rstrip('.')
 
 class WinIOError(WinError, IOError):
     def __init__(self, err, filename=None):