本文整理汇总了Python中win32file._get_osfhandle函数的典型用法代码示例。如果您正苦于以下问题:Python _get_osfhandle函数的具体用法?Python _get_osfhandle怎么用?Python _get_osfhandle使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_get_osfhandle函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: ntfsID
def ntfsID(f):
target = open(f, 'rb')
id = str(win32file.GetFileInformationByHandle(win32file._get_osfhandle(target.fileno()))[4]) + \
str(win32file.GetFileInformationByHandle(win32file._get_osfhandle(target.fileno()))[8]) + \
str(win32file.GetFileInformationByHandle(win32file._get_osfhandle(target.fileno()))[9])
return id
开发者ID:alexanderduryee,项目名称:fixity,代码行数:7,代码来源:FixityCore.py
示例2: make_file_sparse
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:AchillesA,项目名称:bittorrent-orig,代码行数:7,代码来源:Storage_base.py
示例3: perform_sendfile
def perform_sendfile(act, overlapped):
return (
win32file.TransmitFile(
act.sock, win32file._get_osfhandle(act.file_handle.fileno()), act.length or 0, act.blocksize, overlapped, 0
),
0,
)
开发者ID:seanjensengrey,项目名称:cogen,代码行数:7,代码来源:iocp_impl.py
示例4: set_lock
def set_lock(fname):
"""
Try to lock file and write PID.
Return the status of operation.
"""
global fh
fh = open(fname, 'w')
if os.name == 'nt':
# Code for NT systems got from: http://code.activestate.com/recipes/65203/
import win32con
import win32file
import pywintypes
LOCK_EX = win32con.LOCKFILE_EXCLUSIVE_LOCK
LOCK_SH = 0 # the default
LOCK_NB = win32con.LOCKFILE_FAIL_IMMEDIATELY
# is there any reason not to reuse the following structure?
__overlapped = pywintypes.OVERLAPPED()
hfile = win32file._get_osfhandle(fh.fileno())
try:
win32file.LockFileEx(hfile, LOCK_EX | LOCK_NB, 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:
return False
开发者ID:GrIvA,项目名称:NB,代码行数:33,代码来源:lock.py
示例5: __win32_lock_fd
def __win32_lock_fd(fd, timeout=None):
'''returns True if the file descriptor is successfully locked'''
import pywintypes
import win32con
import win32file
import winerror
try:
handle = win32file._get_osfhandle(fd)
if timeout is None:
win32file.LockFileEx(handle, win32con.LOCKFILE_EXCLUSIVE_LOCK, 0, -0x10000, pywintypes.OVERLAPPED())
return True
if timeout > 0:
start = time.time()
while True:
try:
win32file.LockFileEx(handle, win32con.LOCKFILE_EXCLUSIVE_LOCK | win32con.LOCKFILE_FAIL_IMMEDIATELY, 0, -0x10000, pywintypes.OVERLAPPED())
return True
except pywintypes.error as e:
if e.winerror != winerror.ERROR_LOCK_VIOLATION:
break
time.sleep(0.05)
if time.time() > start + timeout:
break
else:
win32file.LockFileEx(handle, win32con.LOCKFILE_EXCLUSIVE_LOCK | win32con.LOCKFILE_FAIL_IMMEDIATELY, 0, -0x10000, pywintypes.OVERLAPPED())
return True
except pywintypes.error:
pass
return False
开发者ID:bittorrent,项目名称:needy,代码行数:32,代码来源:filesystem.py
示例6: get_allocated_regions
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()
interval = 10000000
i = begin
end = begin + length
while i < end:
d = struct.pack("<QQ", i, interval)
try:
r = win32file.DeviceIoControl(handle, FSCTL_QUERY_ALLOCATED_RANGES,
d, interval, None)
except pywintypes.error, e:
# I've seen:
# error: (1784, 'DeviceIoControl', 'The supplied user buffer is not valid for the requested operation.')
return
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 += interval
return a
开发者ID:DKILLER123,项目名称:torrentflux,代码行数:33,代码来源:platform.py
示例7: acquire
def acquire(self):
# 给文件上锁
if fcntl:
fcntl.flock(self.handle, LOCK_EX)
else:
hfile = win32file._get_osfhandle(self.handle.fileno())
win32file.LockFileEx(hfile, LOCK_EX, 0, -0x10000, overlapped)
开发者ID:szqh97,项目名称:test,代码行数:7,代码来源:processlock.py
示例8: release
def release(self):
# 文件解锁
if fcntl:
fcntl.flock(self.handle, fcntl.LOCK_UN)
else:
hfile = win32file._get_osfhandle(self.handle.fileno())
win32file.UnlockFileEx(hfile, 0, -0x10000, overlapped)
开发者ID:szqh97,项目名称:test,代码行数:7,代码来源:processlock.py
示例9: lock_file
def lock_file(file_descriptor):
"""
Cross-platform utility function for obtaining an exclusive lock on the
given open file.
Based on http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65203.
@param file_descriptor: open file descriptor
@type file_descriptor: file
@raise IOError: if the file cannot be locked
"""
if on_posix():
import fcntl
fcntl.lockf(file_descriptor, fcntl.LOCK_EX|fcntl.LOCK_NB)
else:
import pywintypes, win32con, win32file # pylint: disable-msg=F0401
file_handle = win32file._get_osfhandle(file_descriptor.fileno()) # pylint: disable-msg=W0212
flags = \
win32con.LOCKFILE_EXCLUSIVE_LOCK|win32con.LOCKFILE_FAIL_IMMEDIATELY
try:
win32file.LockFileEx(file_handle, flags, 0, -0x10000,
pywintypes.OVERLAPPED()) # pylint: disable-msg=E1101
except win32file.error, oError:
if oError.args[0] == 33: # somebody else (partly) locked the file
raise IOError(*oError.args) # pylint: disable-msg=W0142
else:
raise # unexpected error code
开发者ID:cmci,项目名称:cecog,代码行数:27,代码来源:fileutils.py
示例10: unlock
def unlock(file):
try:
hfile = win32file._get_osfhandle(file.fileno())
win32file.UnlockFileEx(hfile, 0, 0x7fffffff, __overlapped)
except pywintypes.error, e:
# err 120 is unimplemented call, happens on win9x:
if e.args[0] != 120:
raise e
开发者ID:aponxi,项目名称:libmysqlpp,代码行数:8,代码来源:portautils.py
示例11: open_and_lock
def open_and_lock(self, timeout, delay):
"""Open the file and lock it.
Args:
timeout: float, How long to try to lock for.
delay: float, How long to wait between retries
Raises:
AlreadyLockedException: if the lock is already acquired.
IOError: if the open fails.
CredentialsFileSymbolicLinkError: if the file is a symbolic
link.
"""
if self._locked:
raise AlreadyLockedException('File %s is already locked' %
self._filename)
start_time = time.time()
validate_file(self._filename)
try:
self._fh = open(self._filename, self._mode)
except IOError as e:
# If we can't access with _mode, try _fallback_mode
# and don't lock.
if e.errno == errno.EACCES:
self._fh = open(self._filename, self._fallback_mode)
return
# We opened in _mode, try to lock the file.
while True:
try:
hfile = win32file._get_osfhandle(self._fh.fileno())
win32file.LockFileEx(
hfile,
(win32con.LOCKFILE_FAIL_IMMEDIATELY |
win32con.LOCKFILE_EXCLUSIVE_LOCK), 0, -0x10000,
pywintypes.OVERLAPPED())
self._locked = True
return
except pywintypes.error as e:
if timeout == 0:
raise
# If the error is not that the file is already
# in use, raise.
if e[0] != _Win32Opener.FILE_IN_USE_ERROR:
raise
# We could not acquire the lock. Try again.
if (time.time() - start_time) >= timeout:
logger.warn('Could not lock %s in %s seconds' % (
self._filename, timeout))
if self._fh:
self._fh.close()
self._fh = open(self._filename, self._fallback_mode)
return
time.sleep(delay)
开发者ID:APassanisi,项目名称:Craigslist-Email-to-Spreadsheet,代码行数:57,代码来源:_win32_opener.py
示例12: lock
def lock(file):
try:
hfile = win32file._get_osfhandle(file.fileno())
win32file.LockFileEx(hfile, win32con.LOCKFILE_EXCLUSIVE_LOCK,
0, 0x7fffffff, __overlapped)
except pywintypes.error, e:
# err 120 is unimplemented call, happens on win9x:
if e.args[0] != 120:
raise e
开发者ID:aponxi,项目名称:libmysqlpp,代码行数:9,代码来源:portautils.py
示例13: unlock_and_close
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:B-Rich,项目名称:cs377d-proj1,代码行数:9,代码来源:locked_file.py
示例14: flock
def flock(file, flags):
hfile = _get_osfhandle(file.fileno())
try:
if flags & LOCK_UN:
UnlockFileEx(hfile, 0, -0x10000, __overlapped)
else:
LockFileEx(hfile, flags, 0, -0x10000, __overlapped)
except WinIOError, exc:
raise IOError('[Errno %d] %s' % (exc[0], exc[2]))
开发者ID:digital4rensics,项目名称:canari,代码行数:9,代码来源:fs.py
示例15: __lock_exclusive
def __lock_exclusive(file):
file_handle = __win32file._get_osfhandle(file.fileno())
__win32file.LockFileEx(
file_handle,
__win32con.LOCKFILE_EXCLUSIVE_LOCK,
0,
-65536,
__overlapped
)
开发者ID:msaavedra,项目名称:cross_platform,代码行数:9,代码来源:files.py
示例16: _LockImplWin
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:ds3p2,项目名称:catapult,代码行数:10,代码来源:lock.py
示例17: unlock
def unlock(adRotateHandler, file):
"""used to be in ad.py."""
dsh_utils.db_print('ryw_xp:unlock() entered...', 49)
ad = adRotateHandler
ad.highbits=-0x7fff0000
ad.ov=pywintypes.OVERLAPPED()
ad.hfile = win32file._get_osfhandle(file.fileno())
win32file.UnlockFileEx(ad.hfile,0,ad.highbits,ad.ov) #remove locks
ad.hfile.Close()
开发者ID:aniket134,项目名称:XBMC-video-plugins,代码行数:10,代码来源:dsh_xp.py
示例18: __lock
def __lock(self, breakOnFailed):
lockType = win32con.LOCKFILE_EXCLUSIVE_LOCK
if breakOnFailed:
lockType = lockType | win32con.LOCKFILE_FAIL_IMMEDIATELY
hfile = win32file._get_osfhandle(self.__file.fileno())
try:
win32file.LockFileEx(hfile, lockType, 0, 0xf0, FileLocker.__overlapped)
except pywintypes.error:
self.__file.close()
self.__file = None
raise HasBeenLockedError("Locker has been acquired before")
开发者ID:smsg-game,项目名称:smsg-server,代码行数:11,代码来源:filelocker.py
示例19: lock
def lock(file, flags):
hfile = win32file._get_osfhandle(file.fileno())
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:cumulus13,项目名称:vhostmaker,代码行数:11,代码来源:portalocker.py
示例20: release
def release(self):
try:
win32file.UnlockFileEx(
win32file._get_osfhandle(self._file.fileno()),
0, -0x10000, pywintypes.OVERLAPPED())
except pywintypes.error as e:
# Do not fail unlocking unlocked file.
if e[0] == 158:
pass
else:
raise
开发者ID:SharpLu,项目名称:Sympathy-for-data-benchmark,代码行数:11,代码来源:os_support.py
注:本文中的win32file._get_osfhandle函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论