本文整理匯總了Python中os.supports_effective_ids方法的典型用法代碼示例。如果您正苦於以下問題:Python os.supports_effective_ids方法的具體用法?Python os.supports_effective_ids怎麽用?Python os.supports_effective_ids使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類os
的用法示例。
在下文中一共展示了os.supports_effective_ids方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: list_files
# 需要導入模塊: import os [as 別名]
# 或者: from os import supports_effective_ids [as 別名]
def list_files(path):
"""
Return list of sorted file paths in `path`
Raise ReadError if `path` or any file or directory underneath it is not
readable.
"""
def assert_readable(path):
os_supports_effective_ids = os.access in os.supports_effective_ids
if not os.access(path, os.R_OK, effective_ids=os_supports_effective_ids):
raise error.ReadError(errno.EACCES, path)
if os.path.isfile(path):
assert_readable(path)
return [path]
else:
def onerror(exc):
raise error.ReadError(getattr(exc, 'errno', None),
getattr(exc, 'filename', None))
filepaths = []
for dirpath, dirnames, filenames in os.walk(path, onerror=onerror):
for filename in filenames:
filepath = os.path.join(dirpath, filename)
assert_readable(filepath)
filepaths.append(filepath)
return list(sorted(filepaths, key=lambda fp: str(fp).casefold()))
示例2: requiresWriteAccess
# 需要導入模塊: import os [as 別名]
# 或者: from os import supports_effective_ids [as 別名]
def requiresWriteAccess(self, path):
# effective_ids unavailable on windows
if not os.access(path, os.W_OK,
effective_ids=os.access in os.supports_effective_ids):
self.skipTest('requires write access to the installed location')
filename = os.path.join(path, 'test_zipfile.try')
try:
fd = os.open(filename, os.O_WRONLY | os.O_CREAT)
os.close(fd)
except Exception:
self.skipTest('requires write access to the installed location')
unlink(filename)
示例3: effective_access
# 需要導入模塊: import os [as 別名]
# 或者: from os import supports_effective_ids [as 別名]
def effective_access(*args, **kwargs):
if 'effective_ids' not in kwargs:
try:
kwargs['effective_ids'] = os.access in os.supports_effective_ids
except AttributeError:
pass
return os.access(*args, **kwargs)