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


Python win32file.FILE_FLAG_OVERLAPPED属性代码示例

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


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

示例1: setUp

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import FILE_FLAG_OVERLAPPED [as 别名]
def setUp(self):
        self.watcher_threads = []
        self.watcher_thread_changes = []
        self.dir_names = []
        self.dir_handles = []
        for i in range(self.num_test_dirs):
            td = tempfile.mktemp("-test-directory-changes-%d" % i)
            os.mkdir(td)
            self.dir_names.append(td)
            hdir = win32file.CreateFile(td, 
                                        ntsecuritycon.FILE_LIST_DIRECTORY,
                                        win32con.FILE_SHARE_READ,
                                        None, # security desc
                                        win32con.OPEN_EXISTING,
                                        win32con.FILE_FLAG_BACKUP_SEMANTICS |
                                        win32con.FILE_FLAG_OVERLAPPED,
                                        None)
            self.dir_handles.append(hdir)

            changes = []
            t = threading.Thread(target=self._watcherThreadOverlapped,
                                 args=(td, hdir, changes))
            t.start()
            self.watcher_threads.append(t)
            self.watcher_thread_changes.append(changes) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:27,代码来源:test_win32file.py

示例2: win_tun_alloc

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import FILE_FLAG_OVERLAPPED [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

示例3: testCompletionPortsNonQueued

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import FILE_FLAG_OVERLAPPED [as 别名]
def testCompletionPortsNonQueued(self, test_overlapped_death = 0):
        # In 204 we had a reference count bug when OVERLAPPED objects were
        # associated with a completion port other than via
        # PostQueuedCompletionStatus.  This test is based on the reproduction
        # reported with that bug.
        # Create the pipe.
        BUFSIZE = 512
        pipe_name = r"\\.\pipe\pywin32_test_pipe"
        handle = win32pipe.CreateNamedPipe(pipe_name,
                          win32pipe.PIPE_ACCESS_DUPLEX|
                          win32file.FILE_FLAG_OVERLAPPED,
                          win32pipe.PIPE_TYPE_MESSAGE|
                          win32pipe.PIPE_READMODE_MESSAGE|
                          win32pipe.PIPE_WAIT,
                          1, BUFSIZE, BUFSIZE,
                          win32pipe.NMPWAIT_WAIT_FOREVER,
                          None)
        # Create an IOCP and associate it with the handle.        
        port = win32file.CreateIoCompletionPort(-1, 0, 0, 0)
        win32file.CreateIoCompletionPort(handle, port, 1, 0)

        t = threading.Thread(target=self._IOCPServerThread, args=(handle,port, test_overlapped_death))
        t.setDaemon(True) # avoid hanging entire test suite on failure.
        t.start()
        try:
            time.sleep(0.1) # let thread do its thing.
            try:
                win32pipe.CallNamedPipe(r"\\.\pipe\pywin32_test_pipe", str2bytes("Hello there"), BUFSIZE, 0)
            except win32pipe.error:
                # Testing for overlapped death causes this
                if not test_overlapped_death:
                    raise
        finally:
            if not test_overlapped_death:
                handle.Close()
            t.join(3)
            self.failIf(t.isAlive(), "thread didn't finish") 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:39,代码来源:test_win32file.py

示例4: Connect

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import FILE_FLAG_OVERLAPPED [as 别名]
def Connect(self):
        """
        This function tries to connect to the named pipe from AlternateMceIrService.  If it can't connect, it will periodically
        retry until the plugin is stopped or the connection is made.
        """
        self.connecting = True
        #eg.PrintNotice("MCE_Vista: Connect started")
        while self.file is None and self.keepRunning:
            self.SetReceiving(False)
            try:
                self.file = win32file.CreateFile(r'\\.\pipe\MceIr',win32file.GENERIC_READ
                                        |win32file.GENERIC_WRITE,0,None,
                                        win32file.OPEN_EXISTING,win32file.FILE_ATTRIBUTE_NORMAL
                                        |win32file.FILE_FLAG_OVERLAPPED,None)
                if self.sentMessageOnce:
                    eg.PrintNotice("MCE_Vista: Connected to MceIr pipe, started handling IR events")
                    self.plugin.TriggerEvent("Connected")
                    self.sentMessageOnce = False
            except:
                if not self.sentMessageOnce:
                    eg.PrintNotice("MCE_Vista: MceIr pipe is not available, app doesn't seem to be running")
                    eg.PrintNotice("    Will continue to try to connect to MceIr")
                    eg.PrintNotice("    Message = %s"%win32api.FormatMessage(win32api.GetLastError()))
                    self.plugin.TriggerEvent("Disconnected")
                    self.sentMessageOnce = True

                #if self.service and IsServiceStopped(self.service):
                #    eg.PrintNotice("MCE_Vista: MceIr service is stopped, trying to start it...")
                #    StartService(self.service)

                time.sleep(1)
        self.connecting = False
        return 
开发者ID:EventGhost,项目名称:EventGhost,代码行数:35,代码来源:__init__.py

示例5: openTunTap

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import FILE_FLAG_OVERLAPPED [as 别名]
def openTunTap():
    '''
    \brief Open a TUN/TAP interface and switch it to TUN mode.
    
    \return The handler of the interface, which can be used for later
        read/write operations.
    '''
    
    # retrieve the ComponentId from the TUN/TAP interface
    componentId = get_tuntap_ComponentId()
    print('componentId = {0}'.format(componentId))
    
    # create a win32file for manipulating the TUN/TAP interface
    tuntap = win32file.CreateFile(
        r'\\.\Global\%s.tap' % componentId,
        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_OVERLAPPED,
        None
    )
    print('tuntap      = {0}'.format(tuntap.handle))
    
    # have Windows consider the interface now connected
    win32file.DeviceIoControl(
        tuntap,
        TAP_IOCTL_SET_MEDIA_STATUS,
        '\x00\x00\x00\x00',
        None
    )
    
    # prepare the parameter passed to the TAP_IOCTL_CONFIG_TUN commmand.
    # This needs to be a 12-character long string representing
    # - the tun interface's IPv4 address (4 characters)
    # - the tun interface's IPv4 network address (4 characters)
    # - the tun interface's IPv4 network mask (4 characters)
    configTunParam  = []
    configTunParam += TUN_IPv4_ADDRESS
    configTunParam += TUN_IPv4_NETWORK
    configTunParam += TUN_IPv4_NETMASK
    configTunParam  = ''.join([chr(b) for b in configTunParam])
    
    # switch to TUN mode (by default the interface runs in TAP mode)
    win32file.DeviceIoControl(
        tuntap,
        TAP_IOCTL_CONFIG_TUN,
        configTunParam,
        None
    )
    
    # return the handler of the TUN interface
    return tuntap

#=== misc 
开发者ID:alexsunday,项目名称:pyvpn,代码行数:57,代码来源:tun-ping-responder.py

示例6: open_sparse_file

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import FILE_FLAG_OVERLAPPED [as 别名]
def open_sparse_file(path, mode, length=0, overlapped=False):
    supported = get_sparse_files_support(path)
    flags = 0
    # some day I might support sparse files elsewhere
    if not supported and os.name != 'nt':
        return file(path, mode, 0)
    
    flags = win32file.FILE_FLAG_RANDOM_ACCESS
    if overlapped:
        flags |= win32file.FILE_FLAG_OVERLAPPED
    
    # If the hFile handle is opened with the
    # FILE_FLAG_NO_BUFFERING flag set, an application can move the
    # file pointer only to sector-aligned positions.  A
    # sector-aligned position is a position that is a whole number
    # multiple of the volume sector size. An application can
    # obtain a volume sector size by calling the GetDiskFreeSpace
    # function.
    #flags |= win32file.FILE_FLAG_NO_BUFFERING

    access = win32file.GENERIC_READ
    # Shared write is necessary because lock is assigned
    # per file handle. --Dave
    share = win32file.FILE_SHARE_READ | win32file.FILE_SHARE_WRITE
    #share = win32file.FILE_SHARE_READ #| win32file.FILE_SHARE_WRITE

    if is_open_for_write(mode):
        access |= win32file.GENERIC_WRITE

    if isinstance(path, unicode):
        CreateFile = win32file.CreateFileW
    else:
        CreateFile = win32file.CreateFile

    handle = CreateFile(path, access, share, None,
                        win32file.OPEN_ALWAYS,
                        flags, None)
    
    if supported and is_open_for_write(mode):
        _sparse_magic(handle, length)
    fd = win32file._open_osfhandle(handle, os.O_BINARY)
    handle.Detach()

    f = os.fdopen(fd, mode)
    return f 
开发者ID:kenorb-contrib,项目名称:BitTorrent,代码行数:47,代码来源:Storage_base.py


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