当前位置: 首页>>代码示例>>Python>>正文


Python win32file.GENERIC_WRITE属性代码示例

本文整理汇总了Python中win32file.GENERIC_WRITE属性的典型用法代码示例。如果您正苦于以下问题:Python win32file.GENERIC_WRITE属性的具体用法?Python win32file.GENERIC_WRITE怎么用?Python win32file.GENERIC_WRITE使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在win32file的用法示例。


在下文中一共展示了win32file.GENERIC_WRITE属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: SimpleFileDemo

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import GENERIC_WRITE [as 别名]
def SimpleFileDemo():
    testName = os.path.join( win32api.GetTempPath(), "win32file_demo_test_file")
    if os.path.exists(testName): os.unlink(testName)
    # Open the file for writing.
    handle = win32file.CreateFile(testName, 
                                  win32file.GENERIC_WRITE, 
                                  0, 
                                  None, 
                                  win32con.CREATE_NEW, 
                                  0, 
                                  None)
    test_data = "Hello\0there".encode("ascii")
    win32file.WriteFile(handle, test_data)
    handle.Close()
    # Open it for reading.
    handle = win32file.CreateFile(testName, win32file.GENERIC_READ, 0, None, win32con.OPEN_EXISTING, 0, None)
    rc, data = win32file.ReadFile(handle, 1024)
    handle.Close()
    if data == test_data:
        print "Successfully wrote and read a file"
    else:
        raise Exception("Got different data back???")
    os.unlink(testName) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:25,代码来源:win32fileDemo.py

示例2: _OpenFileForWrite

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import GENERIC_WRITE [as 别名]
def _OpenFileForWrite(self, path):
        try:
            fhandle = self.fhandle = win32file.CreateFile(
                path,
                win32file.GENERIC_READ | win32file.GENERIC_WRITE,
                win32file.FILE_SHARE_READ | win32file.FILE_SHARE_WRITE,
                None,
                win32file.OPEN_EXISTING,
                win32file.FILE_ATTRIBUTE_NORMAL,
                None)
            self.write_enabled = True
            self._closer = weakref.ref(
                self, lambda x: win32file.CloseHandle(fhandle))

            return fhandle

        except pywintypes.error as e:
            raise IOError("Unable to open %s: %s" % (path, e)) 
开发者ID:google,项目名称:rekall,代码行数:20,代码来源:win32.py

示例3: testSimpleFiles

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import GENERIC_WRITE [as 别名]
def testSimpleFiles(self):
        try:
            fd, filename = tempfile.mkstemp()
        except AttributeError:
            self.fail("This test requires Python 2.3 or later")
        os.close(fd)
        os.unlink(filename)
        handle = win32file.CreateFile(filename, win32file.GENERIC_WRITE, 0, None, win32con.CREATE_NEW, 0, None)
        test_data = str2bytes("Hello\0there")
        try:
            win32file.WriteFile(handle, test_data)
            handle.Close()
            # Try and open for read
            handle = win32file.CreateFile(filename, win32file.GENERIC_READ, 0, None, win32con.OPEN_EXISTING, 0, None)
            rc, data = win32file.ReadFile(handle, 1024)
            self.assertEquals(data, test_data)
        finally:
            handle.Close()
            try:
                os.unlink(filename)
            except os.error:
                pass

    # A simple test using normal read/write operations. 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:26,代码来源:test_win32file.py

示例4: open

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import GENERIC_WRITE [as 别名]
def open(self, name):
        """
        Direct open devices.

        :param name: Port name.
        :return: 0 on success
        """
        path = self.ports[name]['path']
        try:
            self.files[path] = win32file.CreateFile(path,
                                                    win32file.GENERIC_WRITE |
                                                    win32file.GENERIC_READ,
                                                    0,
                                                    None,
                                                    win32file.OPEN_EXISTING,
                                                    win32file.FILE_ATTRIBUTE_NORMAL,
                                                    None)
        except win32file.error as exc_detail:
            print("%s\nFAIL: Failed open file %s" % (str(exc_detail), name))
            return exc_detail
        print("PASS: All files opened correctly.") 
开发者ID:avocado-framework,项目名称:avocado-vt,代码行数:23,代码来源:virtio_console_guest.py

示例5: CreateFile

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import GENERIC_WRITE [as 别名]
def CreateFile(self, fname, mode="r", bufsize=-1):
        "Open a file the same way a File Directory migration engine would."
        fname = cygwin2nt(fname)
        UserLog.msg("CreateFile", fname)
        if mode == "r":
            wmode = win32file.GENERIC_READ
        elif mode == "w":
            wmode = win32file.GENERIC_WRITE
        elif mode in ( 'r+', 'w+', 'a+'):
            wmode = win32file.GENERIC_READ | win32file.GENERIC_WRITE
        else:
            raise ValueError, "invalid file mode"
        h = win32file.CreateFile(
            fname,                           #  CTSTR lpFileName,
            wmode,                           #  DWORD dwDesiredAccess,
            win32file.FILE_SHARE_DELETE | win32file.FILE_SHARE_READ | win32file.FILE_SHARE_WRITE, #  DWORD dwShareMode,
            None,                            #  LPSECURITY_ATTRIBUTES lpSecurityAttributes,
            win32file.OPEN_EXISTING,         #  DWORD dwCreationDisposition,
            win32file.FILE_ATTRIBUTE_NORMAL, #  DWORD dwFlagsAndAttributes,
            0,                               #  HANDLE hTemplateFile
            )
        self._files[int(h)] = h
        return int(h) 
开发者ID:kdart,项目名称:pycopia,代码行数:25,代码来源:WindowsServer.py

示例6: csv_export_ram

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import GENERIC_WRITE [as 别名]
def csv_export_ram(self):
        """Dump ram using winpmem"""
        hSvc = create_driver_service(self.logger)
        start_service(hSvc, self.logger)
        try:
            fd = win32file.CreateFile(
                "\\\\.\\pmem",
                win32file.GENERIC_READ | win32file.GENERIC_WRITE,
                win32file.FILE_SHARE_READ | win32file.FILE_SHARE_WRITE,
                None,
                win32file.OPEN_EXISTING,
                win32file.FILE_ATTRIBUTE_NORMAL,
                None)
            try:
                t = time.time()
                image = _Image(fd)
                self.logger.info("Imaging to " + self.output_dir + '\\' + self.computer_name + '_memdump.raw')
                image.DumpWithRead(self.output_dir + '\\' + self.computer_name + '_memdump.raw')
                self.logger.info("Completed in %s seconds" % (time.time() - t))
            finally:
                win32file.CloseHandle(fd)
        finally:
            stop_and_delete_driver_service(hSvc) 
开发者ID:SekoiaLab,项目名称:Fastir_Collector,代码行数:25,代码来源:dump.py

示例7: changeTimestamp

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import GENERIC_WRITE [as 别名]
def changeTimestamp(path,fileName,daylimit):
    print '[*] Inside changeTimestamp'
    dates = {}
    fileName = os.path.join(path, fileName)
    dates['tdata'] = getDate(fileName,daylimit)
    dates['ctime'] = datetime.utcfromtimestamp(os.path.getctime(fileName))
    
    # print "[*] Original time: ",str(dates['ctime'])
    
    if __use_win_32:
        filehandle = win32file.CreateFile(fileName, win32file.GENERIC_WRITE, 0, None, win32con.OPEN_EXISTING, 0, None)
        win32file.SetFileTime(filehandle, dates['tdata'],dates['tdata'],dates['tdata'])
        filehandle.close()
        print "[*] Timestamps changed!!"
    else:
        os.utime(fileName, (time.mktime(dates['tdata'].utctimetuple()),)*2)
    
    dates['mtime'] = datetime.utcfromtimestamp(os.path.getmtime(fileName))    
    # print "[*] Modified time: ",str(dates['mtime']) 
开发者ID:mehulj94,项目名称:BrainDamage,代码行数:21,代码来源:modify_timestamp.py

示例8: win_tun_alloc

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import GENERIC_WRITE [as 别名]
def win_tun_alloc(self, dev, flags):
		TAP_IOCTL_SET_MEDIA_STATUS 	= self.WIN_TAP_CONTROL_CODE(6, 0)
		import pywintypes

		guid = self.WIN_get_device_guid()
		if not guid:
			common.internal_print("Please install OpenVPN's Windows TAP driver (NDIS 6) to use XFLTReaT\r\nhttps://openvpn.net/index.php/open-source/downloads.html", -1)
			sys.exit(-1)

		# create a win32file for manipulating the TUN/TAP interface
		try:
			self.wintun = win32file.CreateFile("\\\\.\\Global\\{0}.tap".format(guid),
				win32file.GENERIC_READ | win32file.GENERIC_WRITE,
				win32file.FILE_SHARE_READ | win32file.FILE_SHARE_WRITE,
				None, win32file.OPEN_EXISTING,
				win32file.FILE_ATTRIBUTE_SYSTEM | win32file.FILE_FLAG_NO_BUFFERING | win32file.FILE_FLAG_OVERLAPPED,
				None)
		except pywintypes.error as e:
			if e.args[0] == 31: # A device attached to the system is not functioning.
				common.internal_print("The TUN device is already in use. Maybe another XFLTReaT is running.", -1)
				sys.exit(-1)	


		# have Windows consider the interface now connected
		win32file.DeviceIoControl(self.wintun, TAP_IOCTL_SET_MEDIA_STATUS, '\x01\x00\x00\x00', 1, None)

		return self.wintun 
开发者ID:earthquake,项目名称:XFLTReaT,代码行数:29,代码来源:interface.py

示例9: testMoreFiles

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import GENERIC_WRITE [as 别名]
def testMoreFiles(self):
        # Create a file in the %TEMP% directory.
        testName = os.path.join( win32api.GetTempPath(), "win32filetest.dat" )
        desiredAccess = win32file.GENERIC_READ | win32file.GENERIC_WRITE
        # Set a flag to delete the file automatically when it is closed.
        fileFlags = win32file.FILE_FLAG_DELETE_ON_CLOSE
        h = win32file.CreateFile( testName, desiredAccess, win32file.FILE_SHARE_READ, None, win32file.CREATE_ALWAYS, fileFlags, 0)
    
        # Write a known number of bytes to the file.
        data = str2bytes("z") * 1025
    
        win32file.WriteFile(h, data)
    
        self.failUnless(win32file.GetFileSize(h) == len(data), "WARNING: Written file does not have the same size as the length of the data in it!")
    
        # Ensure we can read the data back.
        win32file.SetFilePointer(h, 0, win32file.FILE_BEGIN)
        hr, read_data = win32file.ReadFile(h, len(data)+10) # + 10 to get anything extra
        self.failUnless(hr==0, "Readfile returned %d" % hr)

        self.failUnless(read_data == data, "Read data is not what we wrote!")
    
        # Now truncate the file at 1/2 its existing size.
        newSize = len(data)//2
        win32file.SetFilePointer(h, newSize, win32file.FILE_BEGIN)
        win32file.SetEndOfFile(h)
        self.failUnlessEqual(win32file.GetFileSize(h), newSize)
    
        # GetFileAttributesEx/GetFileAttributesExW tests.
        self.failUnlessEqual(win32file.GetFileAttributesEx(testName), win32file.GetFileAttributesExW(testName))

        attr, ct, at, wt, size = win32file.GetFileAttributesEx(testName)
        self.failUnless(size==newSize, 
                        "Expected GetFileAttributesEx to return the same size as GetFileSize()")
        self.failUnless(attr==win32file.GetFileAttributes(testName), 
                        "Expected GetFileAttributesEx to return the same attributes as GetFileAttributes")

        h = None # Close the file by removing the last reference to the handle!

        self.failUnless(not os.path.isfile(testName), "After closing the file, it still exists!") 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:42,代码来源:test_win32file.py

示例10: testFilePointer

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import GENERIC_WRITE [as 别名]
def testFilePointer(self):
        # via [ 979270 ] SetFilePointer fails with negative offset

        # Create a file in the %TEMP% directory.
        filename = os.path.join( win32api.GetTempPath(), "win32filetest.dat" )

        f = win32file.CreateFile(filename,
                                win32file.GENERIC_READ|win32file.GENERIC_WRITE,
                                0,
                                None,
                                win32file.CREATE_ALWAYS,
                                win32file.FILE_ATTRIBUTE_NORMAL,
                                0)
        try:
            #Write some data
            data = str2bytes('Some data')
            (res, written) = win32file.WriteFile(f, data)
            
            self.failIf(res)
            self.assertEqual(written, len(data))
            
            #Move at the beginning and read the data
            win32file.SetFilePointer(f, 0, win32file.FILE_BEGIN)
            (res, s) = win32file.ReadFile(f, len(data))
            
            self.failIf(res)
            self.assertEqual(s, data)
            
            #Move at the end and read the data
            win32file.SetFilePointer(f, -len(data), win32file.FILE_END)
            (res, s) = win32file.ReadFile(f, len(data))
            
            self.failIf(res)
            self.failUnlessEqual(s, data)
        finally:
            f.Close()
            os.unlink(filename) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:39,代码来源:test_win32file.py

示例11: testFileTimesTimezones

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import GENERIC_WRITE [as 别名]
def testFileTimesTimezones(self):
        if not issubclass(pywintypes.TimeType, datetime.datetime):
            # maybe should report 'skipped', but that's not quite right as
            # there is nothing you can do to avoid it being skipped!
            return
        filename = tempfile.mktemp("-testFileTimes")
        now_utc = win32timezone.utcnow()
        now_local = now_utc.astimezone(win32timezone.TimeZoneInfo.local())
        h = win32file.CreateFile(filename,
                                 win32file.GENERIC_READ|win32file.GENERIC_WRITE,
                                 0, None, win32file.CREATE_ALWAYS, 0, 0)
        try:
            win32file.SetFileTime(h, now_utc, now_utc, now_utc)
            ct, at, wt = win32file.GetFileTime(h)
            self.failUnlessEqual(now_local, ct)
            self.failUnlessEqual(now_local, at)
            self.failUnlessEqual(now_local, wt)
            # and the reverse - set local, check against utc
            win32file.SetFileTime(h, now_local, now_local, now_local)
            ct, at, wt = win32file.GetFileTime(h)
            self.failUnlessEqual(now_utc, ct)
            self.failUnlessEqual(now_utc, at)
            self.failUnlessEqual(now_utc, wt)
        finally:
            h.close()
            os.unlink(filename) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:28,代码来源:test_win32file.py

示例12: testSimpleOverlapped

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import GENERIC_WRITE [as 别名]
def testSimpleOverlapped(self):
        # Create a file in the %TEMP% directory.
        import win32event
        testName = os.path.join( win32api.GetTempPath(), "win32filetest.dat" )
        desiredAccess = win32file.GENERIC_WRITE
        overlapped = pywintypes.OVERLAPPED()
        evt = win32event.CreateEvent(None, 0, 0, None)
        overlapped.hEvent = evt
        # Create the file and write shit-loads of data to it.
        h = win32file.CreateFile( testName, desiredAccess, 0, None, win32file.CREATE_ALWAYS, 0, 0)
        chunk_data = str2bytes("z") * 0x8000
        num_loops = 512
        expected_size = num_loops * len(chunk_data)
        for i in range(num_loops):
            win32file.WriteFile(h, chunk_data, overlapped)
            win32event.WaitForSingleObject(overlapped.hEvent, win32event.INFINITE)
            overlapped.Offset = overlapped.Offset + len(chunk_data)
        h.Close()
        # Now read the data back overlapped
        overlapped = pywintypes.OVERLAPPED()
        evt = win32event.CreateEvent(None, 0, 0, None)
        overlapped.hEvent = evt
        desiredAccess = win32file.GENERIC_READ
        h = win32file.CreateFile( testName, desiredAccess, 0, None, win32file.OPEN_EXISTING, 0, 0)
        buffer = win32file.AllocateReadBuffer(0xFFFF)
        while 1:
            try:
                hr, data = win32file.ReadFile(h, buffer, overlapped)
                win32event.WaitForSingleObject(overlapped.hEvent, win32event.INFINITE)
                overlapped.Offset = overlapped.Offset + len(data)
                if not data is buffer:
                    self.fail("Unexpected result from ReadFile - should be the same buffer we passed it")
            except win32api.error:
                break
        h.Close() 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:37,代码来源:test_win32file.py

示例13: conn_loop

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import GENERIC_WRITE [as 别名]
def conn_loop(self):
        self.is_running = True
        self.update_vars()
        self.file_handle = win32file.CreateFile(
            self.ipc_path,
            win32file.GENERIC_READ | win32file.GENERIC_WRITE,
            0, None,
            win32file.OPEN_EXISTING,
            0, None
        )
        while self.is_running:
            try:
                while not self.write_queue.empty():
                    win32file.WriteFile(
                        self.file_handle, self.write_queue.get_nowait())
            except win32file.error:
                logger.debug('Exception while writing to pipe.', exc_info=True)
                self.is_running = False
                break
            size = win32file.GetFileSize(self.file_handle)
            if size > 0:
                while size > 0:
                    # pipe has data to read
                    _, data = win32file.ReadFile(self.file_handle, 4096)
                    self.on_data(data)
                    size = win32file.GetFileSize(self.file_handle)
            else:
                time.sleep(1)
        win32file.CloseHandle(self.file_handle)
        logger.debug('Pipe closed.') 
开发者ID:iamkroot,项目名称:trakt-scrobbler,代码行数:32,代码来源:mpv.py

示例14: connect

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import GENERIC_WRITE [as 别名]
def connect(self):
        """Connect the controller to the console
        NOTE: Blocks until the other side is ready
        """
        if self._is_dolphin:
            if platform.system() == "Windows":
                # "Create File" in windows is what you use to open a file. Not
                #   create one. Because the windows API is stupid.
                self.pipe = win32file.CreateFile(
                    self.pipe_path,
                    win32file.GENERIC_WRITE,
                    0,
                    None,
                    win32file.OPEN_EXISTING,
                    0,
                    None
                )
            else:
                self.pipe = open(self.pipe_path, "w")
            return True
        else:
            # Remove any extra garbage that might have accumulated in the buffer
            self.tastm32.reset_input_buffer()

            # Send reset command
            self.tastm32.write(b'R')
            cmd = self.tastm32.read(2)
            if cmd != b'\x01R':
                # TODO Better error handling logic here
                print("ERROR: TAStm32 did not reset properly. Try power cycling it.")
                return False
            # Set to gamecube mode
            self.tastm32.write(b'SAG\x80\x00')
            cmd = self.tastm32.read(2)
            self.tastm32.reset_input_buffer()
            if cmd != b'\x01S':
                # TODO Better error handling logic here
                print("ERROR: TAStm32 did not set to GCN mode. Try power cycling it.")
                return False
            return True 
开发者ID:altf4,项目名称:libmelee,代码行数:42,代码来源:controller.py

示例15: connect

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import GENERIC_WRITE [as 别名]
def connect(self, address):
        win32pipe.WaitNamedPipe(address, self._timeout)
        try:
            handle = win32file.CreateFile(
                address,
                win32file.GENERIC_READ | win32file.GENERIC_WRITE,
                0,
                None,
                win32file.OPEN_EXISTING,
                cSECURITY_ANONYMOUS | cSECURITY_SQOS_PRESENT,
                0
            )
        except win32pipe.error as e:
            # See Remarks:
            # https://msdn.microsoft.com/en-us/library/aa365800.aspx
            if e.winerror == cERROR_PIPE_BUSY:
                # Another program or thread has grabbed our pipe instance
                # before we got to it. Wait for availability and attempt to
                # connect again.
                win32pipe.WaitNamedPipe(address, RETRY_WAIT_TIMEOUT)
                return self.connect(address)
            raise e

        self.flags = win32pipe.GetNamedPipeInfo(handle)[0]

        self._handle = handle
        self._address = address 
开发者ID:QData,项目名称:deepWordBug,代码行数:29,代码来源:npipesocket.py


注:本文中的win32file.GENERIC_WRITE属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。