MCPcopy Index your code
hub / github.com/python/cpython / can_xattr

Function can_xattr

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

Source from the content-addressed store, hash-verified

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

Callers 1

skip_unless_xattrFunction · 0.85

Calls 9

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

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…