MCPcopy Index your code
hub / github.com/RustPython/RustPython / can_xattr

Function can_xattr

Lib/test/support/os_helper.py:221–251  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

219
220
221def can_xattr():
222 import tempfile
223 global _can_xattr
224 if _can_xattr is not None:
225 return _can_xattr
226 if not hasattr(os, "setxattr"):
227 can = False
228 else:
229 import platform
230 tmp_dir = tempfile.mkdtemp()
231 tmp_fp, tmp_name = tempfile.mkstemp(dir=tmp_dir)
232 try:
233 with open(TESTFN, "wb") as fp:
234 try:
235 # TESTFN & tempfile may use different file systems with
236 # different capabilities
237 os.setxattr(tmp_fp, b"user.test", b"")
238 os.setxattr(tmp_name, b"trusted.foo", b"42")
239 os.setxattr(fp.fileno(), b"user.test", b"")
240 # Kernels < 2.6.39 don't respect setxattr flags.
241 kernel_version = platform.release()
242 m = re.match(r"2.6.(\d{1,2})", kernel_version)
243 can = m is None or int(m.group(1)) >= 39
244 except OSError:
245 can = False
246 finally:
247 unlink(TESTFN)
248 unlink(tmp_name)
249 rmdir(tmp_dir)
250 _can_xattr = can
251 return can
252
253
254def skip_unless_xattr(test):

Callers 1

skip_unless_xattrFunction · 0.85

Calls 10

hasattrFunction · 0.85
unlinkFunction · 0.85
mkdtempMethod · 0.80
setxattrMethod · 0.80
rmdirFunction · 0.70
openFunction · 0.50
filenoMethod · 0.45
releaseMethod · 0.45
matchMethod · 0.45
groupMethod · 0.45

Tested by

no test coverage detected