diff mercurial/win32.py @ 8421:b6d0fa8c7685

posixfile: remove posixfile_nt and fix import bug in windows.py The posixfile_nt class has been superseded by posixfile in osutils.c, which works on Windows NT and above. All other systems get the regular python file class which is assigned to posixfile in posix.py (for POSIX) and in the pure python version of osutils.py (for Win 9x or Windows NT in pure mode).
author Sune Foldager <cryo@cyanite.org>
date Wed, 13 May 2009 21:36:16 +0200
parents 79a12651d46b
children 284fda4cd093
line wrap: on
line diff
--- a/mercurial/win32.py	Thu May 14 14:12:32 2009 -0700
+++ b/mercurial/win32.py	Wed May 13 21:36:16 2009 +0200
@@ -264,114 +264,6 @@
     return [os.path.join(userdir, 'mercurial.ini'),
             os.path.join(userdir, '.hgrc')]
 
-class posixfile_nt(object):
-    '''file object with posix-like semantics.  on windows, normal
-    files can not be deleted or renamed if they are open. must open
-    with win32file.FILE_SHARE_DELETE. this flag does not exist on
-    windows < nt, so do not use this class there.'''
-
-    # ideally, we could use win32file._open_osfhandle and avoid this
-    # class entirely, but we would need the win32 _fdopen function,
-    # which is not exported by the win32file module.
-
-    def __init__(self, name, mode='rb'):
-        self.closed = False
-        self.name = name
-        self.mode = mode
-        access = 0
-        if 'r' in mode or '+' in mode:
-            access |= win32file.GENERIC_READ
-        if 'w' in mode or 'a' in mode or '+' in mode:
-            access |= win32file.GENERIC_WRITE
-        if 'r' in mode:
-            creation = win32file.OPEN_EXISTING
-        elif 'a' in mode:
-            creation = win32file.OPEN_ALWAYS
-        else:
-            creation = win32file.CREATE_ALWAYS
-        try:
-            self.handle = win32file.CreateFile(name,
-                                               access,
-                                               win32file.FILE_SHARE_READ |
-                                               win32file.FILE_SHARE_WRITE |
-                                               win32file.FILE_SHARE_DELETE,
-                                               None,
-                                               creation,
-                                               win32file.FILE_ATTRIBUTE_NORMAL,
-                                               0)
-        except pywintypes.error, err:
-            raise WinIOError(err, name)
-
-    def __iter__(self):
-        for line in self.readlines():
-            yield line
-
-    def read(self, count=-1):
-        try:
-            cs = cStringIO.StringIO()
-            while count:
-                wincount = int(count)
-                if wincount == -1:
-                    wincount = 1048576
-                val, data = win32file.ReadFile(self.handle, wincount)
-                if not data: break
-                cs.write(data)
-                if count != -1:
-                    count -= len(data)
-            return cs.getvalue()
-        except pywintypes.error, err:
-            raise WinIOError(err)
-
-    def readlines(self, sizehint=None):
-        # splitlines() splits on single '\r' while readlines()
-        # does not. cStringIO has a well behaving readlines() and is fast.
-        return cStringIO.StringIO(self.read()).readlines()
-
-    def write(self, data):
-        try:
-            if 'a' in self.mode:
-                win32file.SetFilePointer(self.handle, 0, win32file.FILE_END)
-            nwrit = 0
-            while nwrit < len(data):
-                val, nwrit = win32file.WriteFile(self.handle, data)
-                data = data[nwrit:]
-        except pywintypes.error, err:
-            raise WinIOError(err)
-
-    def writelines(self, sequence):
-        for s in sequence:
-            self.write(s)
-
-    def seek(self, pos, whence=0):
-        try:
-            win32file.SetFilePointer(self.handle, int(pos), whence)
-        except pywintypes.error, err:
-            raise WinIOError(err)
-
-    def tell(self):
-        try:
-            return win32file.SetFilePointer(self.handle, 0,
-                                            win32file.FILE_CURRENT)
-        except pywintypes.error, err:
-            raise WinIOError(err)
-
-    def close(self):
-        if not self.closed:
-            self.handle = None
-            self.closed = True
-
-    def flush(self):
-        # we have no application-level buffering
-        pass
-
-    def truncate(self, pos=0):
-        try:
-            win32file.SetFilePointer(self.handle, int(pos),
-                                     win32file.FILE_BEGIN)
-            win32file.SetEndOfFile(self.handle)
-        except pywintypes.error, err:
-            raise WinIOError(err)
-
 def getuser():
     '''return name of current user'''
     return win32api.GetUserName()