changeset 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 aa25be1c2889
children 79a12651d46b
files mercurial/win32.py
diffstat 1 files changed, 9 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- 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):