Nicer error message when failing to open exclusive file

This commit is contained in:
Kovid Goyal 2013-11-05 13:13:13 +05:30
parent 3164269793
commit 1306591499

View File

@ -28,8 +28,8 @@ class WindowsExclFile(object):
0, # Open exclusive
None, # No security attributes
w.OPEN_ALWAYS, # If file does not exist, create it
w.FILE_ATTRIBUTE_NORMAL, #Normal attributes
None, #No template file
w.FILE_ATTRIBUTE_NORMAL, # Normal attributes
None, # No template file
)
break
except pywintypes.error as err:
@ -38,6 +38,8 @@ class WindowsExclFile(object):
continue
else:
raise
if not hasattr(self, '_handle'):
raise Exception('Failed to open exclusive file: %s' % path)
def seek(self, amt, frm=0):
import win32file as w
@ -67,7 +69,8 @@ class WindowsExclFile(object):
import win32file as w
sz = w.GetFileSize(self._handle)
max = sz - self.tell()
if bytes < 0: bytes = max
if bytes < 0:
bytes = max
bytes = min(max, bytes)
if bytes < 1:
return ''