def rename(self, src, dest): try: if iswindows: import win32file, pywintypes try: win32file.MoveFileEx(src, dest, win32file.MOVEFILE_REPLACE_EXISTING|win32file.MOVEFILE_WRITE_THROUGH) except pywintypes.error as e: raise_winerror(e) else: os.rename(src, dest) except EnvironmentError as e: if e.errno != errno.ENOENT: # the source of the rename does not exist raise
def windows_open(path): if isinstance(path, bytes): path = os.fsdecode(path) try: h = win32file.CreateFileW( path, win32file.GENERIC_READ | win32file.GENERIC_WRITE, # Open for reading and writing 0, # Open exclusive None, # No security attributes, ensures handle is not inherited by children win32file.OPEN_ALWAYS, # If file does not exist, create it win32file.FILE_ATTRIBUTE_NORMAL, # Normal attributes None, # No template file ) except pywintypes.error as err: raise_winerror(err) fd = msvcrt.open_osfhandle(h.Detach(), 0) return os.fdopen(fd, 'r+b')