changeset 8951:835a51e63c5b

windows: fix use of undefined exception (issue1707) This fixes the implied reliance on pywin32 and the win32 module. This also fixes a regression in ae275ad46bd0 that made Mercurial unusable without pywin32.
author Henrik Stuart <hg@hstuart.dk>
date Thu, 25 Jun 2009 22:43:58 +0200
parents be6b57b2bdb8
children 7c7a672e9db7
files mercurial/win32.py mercurial/windows.py
diffstat 2 files changed, 4 insertions(+), 139 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/win32.py	Sat Jun 27 13:05:25 2009 +0200
+++ b/mercurial/win32.py	Thu Jun 25 22:43:58 2009 +0200
@@ -20,139 +20,6 @@
 import osutil, encoding
 from win32com.shell import shell,shellcon
 
-class WinError(Exception):
-    winerror_map = {
-        winerror.ERROR_ACCESS_DENIED: errno.EACCES,
-        winerror.ERROR_ACCOUNT_DISABLED: errno.EACCES,
-        winerror.ERROR_ACCOUNT_RESTRICTION: errno.EACCES,
-        winerror.ERROR_ALREADY_ASSIGNED: errno.EBUSY,
-        winerror.ERROR_ALREADY_EXISTS: errno.EEXIST,
-        winerror.ERROR_ARITHMETIC_OVERFLOW: errno.ERANGE,
-        winerror.ERROR_BAD_COMMAND: errno.EIO,
-        winerror.ERROR_BAD_DEVICE: errno.ENODEV,
-        winerror.ERROR_BAD_DRIVER_LEVEL: errno.ENXIO,
-        winerror.ERROR_BAD_EXE_FORMAT: errno.ENOEXEC,
-        winerror.ERROR_BAD_FORMAT: errno.ENOEXEC,
-        winerror.ERROR_BAD_LENGTH: errno.EINVAL,
-        winerror.ERROR_BAD_PATHNAME: errno.ENOENT,
-        winerror.ERROR_BAD_PIPE: errno.EPIPE,
-        winerror.ERROR_BAD_UNIT: errno.ENODEV,
-        winerror.ERROR_BAD_USERNAME: errno.EINVAL,
-        winerror.ERROR_BROKEN_PIPE: errno.EPIPE,
-        winerror.ERROR_BUFFER_OVERFLOW: errno.ENAMETOOLONG,
-        winerror.ERROR_BUSY: errno.EBUSY,
-        winerror.ERROR_BUSY_DRIVE: errno.EBUSY,
-        winerror.ERROR_CALL_NOT_IMPLEMENTED: errno.ENOSYS,
-        winerror.ERROR_CANNOT_MAKE: errno.EACCES,
-        winerror.ERROR_CANTOPEN: errno.EIO,
-        winerror.ERROR_CANTREAD: errno.EIO,
-        winerror.ERROR_CANTWRITE: errno.EIO,
-        winerror.ERROR_CRC: errno.EIO,
-        winerror.ERROR_CURRENT_DIRECTORY: errno.EACCES,
-        winerror.ERROR_DEVICE_IN_USE: errno.EBUSY,
-        winerror.ERROR_DEV_NOT_EXIST: errno.ENODEV,
-        winerror.ERROR_DIRECTORY: errno.EINVAL,
-        winerror.ERROR_DIR_NOT_EMPTY: errno.ENOTEMPTY,
-        winerror.ERROR_DISK_CHANGE: errno.EIO,
-        winerror.ERROR_DISK_FULL: errno.ENOSPC,
-        winerror.ERROR_DRIVE_LOCKED: errno.EBUSY,
-        winerror.ERROR_ENVVAR_NOT_FOUND: errno.EINVAL,
-        winerror.ERROR_EXE_MARKED_INVALID: errno.ENOEXEC,
-        winerror.ERROR_FILENAME_EXCED_RANGE: errno.ENAMETOOLONG,
-        winerror.ERROR_FILE_EXISTS: errno.EEXIST,
-        winerror.ERROR_FILE_INVALID: errno.ENODEV,
-        winerror.ERROR_FILE_NOT_FOUND: errno.ENOENT,
-        winerror.ERROR_GEN_FAILURE: errno.EIO,
-        winerror.ERROR_HANDLE_DISK_FULL: errno.ENOSPC,
-        winerror.ERROR_INSUFFICIENT_BUFFER: errno.ENOMEM,
-        winerror.ERROR_INVALID_ACCESS: errno.EACCES,
-        winerror.ERROR_INVALID_ADDRESS: errno.EFAULT,
-        winerror.ERROR_INVALID_BLOCK: errno.EFAULT,
-        winerror.ERROR_INVALID_DATA: errno.EINVAL,
-        winerror.ERROR_INVALID_DRIVE: errno.ENODEV,
-        winerror.ERROR_INVALID_EXE_SIGNATURE: errno.ENOEXEC,
-        winerror.ERROR_INVALID_FLAGS: errno.EINVAL,
-        winerror.ERROR_INVALID_FUNCTION: errno.ENOSYS,
-        winerror.ERROR_INVALID_HANDLE: errno.EBADF,
-        winerror.ERROR_INVALID_LOGON_HOURS: errno.EACCES,
-        winerror.ERROR_INVALID_NAME: errno.EINVAL,
-        winerror.ERROR_INVALID_OWNER: errno.EINVAL,
-        winerror.ERROR_INVALID_PARAMETER: errno.EINVAL,
-        winerror.ERROR_INVALID_PASSWORD: errno.EPERM,
-        winerror.ERROR_INVALID_PRIMARY_GROUP: errno.EINVAL,
-        winerror.ERROR_INVALID_SIGNAL_NUMBER: errno.EINVAL,
-        winerror.ERROR_INVALID_TARGET_HANDLE: errno.EIO,
-        winerror.ERROR_INVALID_WORKSTATION: errno.EACCES,
-        winerror.ERROR_IO_DEVICE: errno.EIO,
-        winerror.ERROR_IO_INCOMPLETE: errno.EINTR,
-        winerror.ERROR_LOCKED: errno.EBUSY,
-        winerror.ERROR_LOCK_VIOLATION: errno.EACCES,
-        winerror.ERROR_LOGON_FAILURE: errno.EACCES,
-        winerror.ERROR_MAPPED_ALIGNMENT: errno.EINVAL,
-        winerror.ERROR_META_EXPANSION_TOO_LONG: errno.E2BIG,
-        winerror.ERROR_MORE_DATA: errno.EPIPE,
-        winerror.ERROR_NEGATIVE_SEEK: errno.ESPIPE,
-        winerror.ERROR_NOACCESS: errno.EFAULT,
-        winerror.ERROR_NONE_MAPPED: errno.EINVAL,
-        winerror.ERROR_NOT_ENOUGH_MEMORY: errno.ENOMEM,
-        winerror.ERROR_NOT_READY: errno.EAGAIN,
-        winerror.ERROR_NOT_SAME_DEVICE: errno.EXDEV,
-        winerror.ERROR_NO_DATA: errno.EPIPE,
-        winerror.ERROR_NO_MORE_SEARCH_HANDLES: errno.EIO,
-        winerror.ERROR_NO_PROC_SLOTS: errno.EAGAIN,
-        winerror.ERROR_NO_SUCH_PRIVILEGE: errno.EACCES,
-        winerror.ERROR_OPEN_FAILED: errno.EIO,
-        winerror.ERROR_OPEN_FILES: errno.EBUSY,
-        winerror.ERROR_OPERATION_ABORTED: errno.EINTR,
-        winerror.ERROR_OUTOFMEMORY: errno.ENOMEM,
-        winerror.ERROR_PASSWORD_EXPIRED: errno.EACCES,
-        winerror.ERROR_PATH_BUSY: errno.EBUSY,
-        winerror.ERROR_PATH_NOT_FOUND: errno.ENOENT,
-        winerror.ERROR_PIPE_BUSY: errno.EBUSY,
-        winerror.ERROR_PIPE_CONNECTED: errno.EPIPE,
-        winerror.ERROR_PIPE_LISTENING: errno.EPIPE,
-        winerror.ERROR_PIPE_NOT_CONNECTED: errno.EPIPE,
-        winerror.ERROR_PRIVILEGE_NOT_HELD: errno.EACCES,
-        winerror.ERROR_READ_FAULT: errno.EIO,
-        winerror.ERROR_SEEK: errno.EIO,
-        winerror.ERROR_SEEK_ON_DEVICE: errno.ESPIPE,
-        winerror.ERROR_SHARING_BUFFER_EXCEEDED: errno.ENFILE,
-        winerror.ERROR_SHARING_VIOLATION: errno.EACCES,
-        winerror.ERROR_STACK_OVERFLOW: errno.ENOMEM,
-        winerror.ERROR_SWAPERROR: errno.ENOENT,
-        winerror.ERROR_TOO_MANY_MODULES: errno.EMFILE,
-        winerror.ERROR_TOO_MANY_OPEN_FILES: errno.EMFILE,
-        winerror.ERROR_UNRECOGNIZED_MEDIA: errno.ENXIO,
-        winerror.ERROR_UNRECOGNIZED_VOLUME: errno.ENODEV,
-        winerror.ERROR_WAIT_NO_CHILDREN: errno.ECHILD,
-        winerror.ERROR_WRITE_FAULT: errno.EIO,
-        winerror.ERROR_WRITE_PROTECT: errno.EROFS,
-        }
-
-    def __init__(self, err):
-        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):
-        WinError.__init__(self, err)
-        IOError.__init__(self, self.winerror_map.get(self.win_errno, 0),
-                         self.win_strerror)
-        self.filename = filename
-
-class WinOSError(WinError, OSError):
-    def __init__(self, err):
-        WinError.__init__(self, err)
-        OSError.__init__(self, self.winerror_map.get(self.win_errno, 0),
-                         self.win_strerror)
-
 def os_link(src, dst):
     try:
         win32file.CreateHardLink(dst, src)
@@ -164,12 +31,11 @@
             except:
                 pass
             # Fake hardlinking error
-            raise WinOSError((18, 'CreateHardLink', 'The system cannot '
-                              'move the file to a different disk drive'))
+            raise OSError(errno.EINVAL, 'Hardlinking not supported')
     except pywintypes.error, details:
-        raise WinOSError(details)
+        raise OSError(errno.EINVAL, 'target implements hardlinks improperly')
     except NotImplementedError: # Another fake error win Win98
-        raise WinOSError((18, 'CreateHardLink', 'Hardlinking not supported'))
+        raise OSError(errno.EINVAL, 'Hardlinking not supported')
 
 def nlinks(pathname):
     """Return number of hardlinks for the given file."""
--- a/mercurial/windows.py	Sat Jun 27 13:05:25 2009 +0200
+++ b/mercurial/windows.py	Thu Jun 25 22:43:58 2009 +0200
@@ -8,7 +8,6 @@
 from i18n import _
 import osutil, error
 import errno, msvcrt, os, re, sys
-from mercurial import win32
 
 nulldev = 'NUL:'
 umask = 002
@@ -18,7 +17,7 @@
     try:
         return osutil.posixfile(name, mode, buffering)
     except WindowsError, err:
-        raise win32.WinIOError(err)
+        raise IOError(err.errno, err.strerror)
 posixfile.__doc__ = osutil.posixfile.__doc__
 
 class winstdout(object):