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


Python win32file._get_osfhandle方法代码示例

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


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

示例1: unlock_and_close

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import _get_osfhandle [as 别名]
def unlock_and_close(self):
      """Close and unlock the file using the win32 primitive."""
      if self._locked:
        try:
          hfile = win32file._get_osfhandle(self._fh.fileno())
          win32file.UnlockFileEx(hfile, 0, -0x10000, pywintypes.OVERLAPPED())
        except pywintypes.error as e:
          if e[0] != _Win32Opener.FILE_ALREADY_UNLOCKED_ERROR:
            raise
      self._locked = False
      if self._fh:
        self._fh.close() 
开发者ID:mortcanty,项目名称:earthengine,代码行数:14,代码来源:locked_file.py

示例2: unlock_and_close

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import _get_osfhandle [as 别名]
def unlock_and_close(self):
      """Close and unlock the file using the win32 primitive."""
      if self._locked:
        try:
          hfile = win32file._get_osfhandle(self._fh.fileno())
          win32file.UnlockFileEx(hfile, 0, -0x10000, pywintypes.OVERLAPPED())
        except pywintypes.error, e:
          if e[0] != _Win32Opener.FILE_ALREADY_UNLOCKED_ERROR:
            raise 
开发者ID:splunk,项目名称:splunk-ref-pas-code,代码行数:11,代码来源:locked_file.py

示例3: _acquire_lock

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import _get_osfhandle [as 别名]
def _acquire_lock(self, for_save=False):
        assert self.__locked_fh is None, 'double lock'

        while True:
            try:
                fd = os.open(self._store,
                             os.O_RDWR | (os.O_CREAT * int(for_save)))
            except FileNotFoundError:
                if not for_save:
                    raise qubes.exc.QubesException(
                        'Qubes XML store {!r} is missing; '
                        'use qubes-create tool'.format(self._store))
                raise

            # While we were waiting for lock, someone could have unlink()ed
            # (or rename()d) our file out of the filesystem. We have to
            # ensure we got lock on something linked to filesystem.
            # If not, try again.
            if os.fstat(fd) != os.stat(self._store):
                os.close(fd)
                continue

            if self.__load_timestamp and \
                    os.path.getmtime(self._store) != self.__load_timestamp:
                os.close(fd)
                raise qubes.exc.QubesException(
                    'Someone else modified qubes.xml in the meantime')

            break

        if os.name == 'posix':
            fcntl.lockf(fd, fcntl.LOCK_EX)
        elif os.name == 'nt':
            # pylint: disable=protected-access
            overlapped = pywintypes.OVERLAPPED()
            win32file.LockFileEx(
                win32file._get_osfhandle(fd),
                win32con.LOCKFILE_EXCLUSIVE_LOCK, 0, -0x10000, overlapped)

        self.__locked_fh = os.fdopen(fd, 'r+b')
        return self.__locked_fh 
开发者ID:QubesOS,项目名称:qubes-core-admin,代码行数:43,代码来源:app.py

示例4: _LockImplWin

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import _get_osfhandle [as 别名]
def _LockImplWin(target_file, flags):
  hfile = win32file._get_osfhandle(target_file.fileno())
  try:
    win32file.LockFileEx(hfile, flags, 0, -0x10000, _OVERLAPPED)
  except pywintypes.error, exc_value:
    if exc_value[0] == 33:
      raise LockException('Error trying acquiring lock of %s: %s' %
                          (target_file.name, exc_value[2]))
    else:
      raise 
开发者ID:FSecureLABS,项目名称:Jandroid,代码行数:12,代码来源:lock.py

示例5: _UnlockImplWin

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import _get_osfhandle [as 别名]
def _UnlockImplWin(target_file):
  hfile = win32file._get_osfhandle(target_file.fileno())
  try:
    win32file.UnlockFileEx(hfile, 0, -0x10000, _OVERLAPPED)
  except pywintypes.error, exc_value:
    if exc_value[0] == 158:
      # error: (158, 'UnlockFileEx', 'The segment is already unlocked.')
      # To match the 'posix' implementation, silently ignore this error
      pass
    else:
      # Q:  Are there exceptions/codes we should be dealing with here?
      raise 
开发者ID:FSecureLABS,项目名称:Jandroid,代码行数:14,代码来源:lock.py

示例6: unlock_and_close

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import _get_osfhandle [as 别名]
def unlock_and_close(self):
        """Close and unlock the file using the win32 primitive."""
        if self._locked:
            try:
                hfile = win32file._get_osfhandle(self._fh.fileno())
                win32file.UnlockFileEx(hfile, 0, -0x10000,
                                       pywintypes.OVERLAPPED())
            except pywintypes.error as e:
                if e[0] != _Win32Opener.FILE_ALREADY_UNLOCKED_ERROR:
                    raise
        self._locked = False
        if self._fh:
            self._fh.close() 
开发者ID:Deltares,项目名称:aqua-monitor,代码行数:15,代码来源:_win32_opener.py

示例7: lock

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import _get_osfhandle [as 别名]
def lock(file, flags):
        hfile = win32file._get_osfhandle(_getfd(file))
        try:
            win32file.LockFileEx(hfile, flags, 0, -0x10000, __overlapped)
        except pywintypes.error, exc_value:
            # error: (33, 'LockFileEx', 'The process cannot access the file because another process has locked a portion of the file.')
            if exc_value[0] == 33:
                raise LockException(LockException.LOCK_FAILED, exc_value[2])
            else:
                # Q:  Are there exceptions/codes we should be dealing with here?
                raise 
开发者ID:harryliu,项目名称:edwin,代码行数:13,代码来源:portalocker.py

示例8: unlock

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import _get_osfhandle [as 别名]
def unlock(file):
        hfile = win32file._get_osfhandle(_getfd(file))
        try:
            win32file.UnlockFileEx(hfile, 0, -0x10000, __overlapped)
        except pywintypes.error, exc_value:
            if exc_value[0] == 158:
                # error: (158, 'UnlockFileEx', 'The segment is already unlocked.')
                # To match the 'posix' implementation, silently ignore this error
                pass
            else:
                # Q:  Are there exceptions/codes we should be dealing with here?
                raise 
开发者ID:harryliu,项目名称:edwin,代码行数:14,代码来源:portalocker.py

示例9: lock

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import _get_osfhandle [as 别名]
def lock(file, flags):
        hfile = win32file._get_osfhandle(fd(file))
        win32file.LockFileEx(hfile, flags, 0, -0x10000, __overlapped) 
开发者ID:blackye,项目名称:luscan-devel,代码行数:5,代码来源:locks.py

示例10: unlock

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import _get_osfhandle [as 别名]
def unlock(file):
        hfile = win32file._get_osfhandle(fd(file))
        win32file.UnlockFileEx(hfile, 0, -0x10000, __overlapped) 
开发者ID:blackye,项目名称:luscan-devel,代码行数:5,代码来源:locks.py

示例11: unlock_and_close

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import _get_osfhandle [as 别名]
def unlock_and_close(self):
            """Close and unlock the file using the win32 primitive."""
            if self._locked:
                try:
                    hfile = win32file._get_osfhandle(self._fh.fileno())
                    win32file.UnlockFileEx(hfile, 0, -0x10000,
                                           pywintypes.OVERLAPPED())
                except pywintypes.error as e:
                    if e[0] != _Win32Opener.FILE_ALREADY_UNLOCKED_ERROR:
                        raise
            self._locked = False
            if self._fh:
                self._fh.close() 
开发者ID:luci,项目名称:luci-py,代码行数:15,代码来源:locked_file.py

示例12: unlock

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import _get_osfhandle [as 别名]
def unlock(file_):
        try:
            savepos = file_.tell()
            if savepos:
                file_.seek(0)

            try:
                msvcrt.locking(file_.fileno(), constants.LOCK_UN, lock_length)
            except IOError as exc_value:
                if exc_value.strerror == 'Permission denied':
                    import pywintypes
                    import win32file
                    import winerror
                    __overlapped = pywintypes.OVERLAPPED()
                    hfile = win32file._get_osfhandle(file_.fileno())
                    try:
                        win32file.UnlockFileEx(
                            hfile, 0, -0x10000, __overlapped)
                    except pywintypes.error as exc_value:
                        if exc_value.winerror == winerror.ERROR_NOT_LOCKED:
                            # error: (158, 'UnlockFileEx',
                            #         'The segment is already unlocked.')
                            # To match the 'posix' implementation, silently
                            # ignore this error
                            pass
                        else:
                            # Q:  Are there exceptions/codes we should be
                            # dealing with here?
                            raise
                else:
                    raise exceptions.LockException(
                        exceptions.LockException.LOCK_FAILED,
                        exc_value.strerror,
                        fh=file_)
            finally:
                if savepos:
                    file_.seek(savepos)
        except IOError as exc_value:
            raise exceptions.LockException(
                exceptions.LockException.LOCK_FAILED, exc_value.strerror,
                fh=file_) 
开发者ID:allegroai,项目名称:trains,代码行数:43,代码来源:portalocker.py

示例13: make_file_sparse

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import _get_osfhandle [as 别名]
def make_file_sparse(path, f, length=0):
        supported = get_sparse_files_support(path)
        if not supported:
            return

        handle = win32file._get_osfhandle(f.fileno())
        _sparse_magic(handle, length) 
开发者ID:kenorb-contrib,项目名称:BitTorrent,代码行数:9,代码来源:Storage_base.py

示例14: get_allocated_regions

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import _get_osfhandle [as 别名]
def get_allocated_regions(path, f=None, begin=0, length=None):
    supported = get_sparse_files_support(path)
    if not supported:
        return
    if os.name == 'nt':
        if not os.path.exists(path):
            return False
        if f is None:
            f = file(path, 'r')
        handle = win32file._get_osfhandle(f.fileno())
        if length is None:
            length = os.path.getsize(path) - begin
        a = SparseSet()
        run = 128
        i = begin
        end = begin + length
        while i < end:
            d = struct.pack("<QQ", i, length)
            try:
                r = win32file.DeviceIoControl(handle, FSCTL_QUERY_ALLOCATED_RANGES,
                                              d, struct.calcsize("<QQ")*run, None)
            except pywintypes.error, e:
                if e.args[0] == winerror.ERROR_MORE_DATA:
                    run *= 2
                    continue
                # I've also seen:
                # error: (1784, 'DeviceIoControl', 'The supplied user buffer is not valid for the requested operation.')
                return
            if not r:
                break
            for c in xrange(0, len(r), 16):
                qq = struct.unpack("<QQ", r[c:c+16])
                b = qq[0]
                e = b + qq[1]
                a.add(b, e)
                i = max(i, e)

        return a 
开发者ID:kenorb-contrib,项目名称:BitTorrent,代码行数:40,代码来源:platform.py

示例15: __init__

# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import _get_osfhandle [as 别名]
def __init__(self, handle):
        from twisted.internet import reactor
        self.reactor = reactor
        self.handle = handle
        self.osfhandle = win32file._get_osfhandle(self.handle.fileno())
        self.mode = self.handle.mode
        # CloseHandle automatically calls CancelIo
        self.close = self.handle.close
        self.fileno = self.handle.fileno
        self.read_op = ReadFileOp()
        self.write_op = WriteFileOp()
        self.readbuf = self.reactor.AllocateReadBuffer(self.buffer_size) 
开发者ID:kenorb-contrib,项目名称:BitTorrent,代码行数:14,代码来源:Storage_IOCP.py


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