code: def can_xattr():
      import tempfile
  
      global _can_xattr
      if _can_xattr is not None:
          return _can_xattr
      if not hasattr(os, "setxattr"):
          can = False
      else:
          import platform
  
          tmp_dir = tempfile.mkdtemp()
          tmp_fp, tmp_name = tempfile.mkstemp(dir=tmp_dir)
          try:
              with open(TESTFN, "wb") as fp:
                  try:
                      # TESTFN & tempfile may use different file systems with
                      # different capabilities
                      os.setxattr(tmp_fp, b"user.test", b"")
                      os.setxattr(tmp_name, b"trusted.foo", b"42")
                      os.setxattr(fp.fileno(), b"user.test", b"")
                      # Kernels < 2.6.39 don't respect setxattr flags.
                      kernel_version = platform.release()
                      m = re.match(r"2.6.(\d{1,2})", kernel_version)
                      can = m is None or int(m.group(1)) >= 39
                  except OSError:
                      can = False
          finally:
              unlink(TESTFN)
              unlink(tmp_name)
              rmdir(tmp_dir)
      _can_xattr = can
      return can
  
imports: import collections.abc
  import contextlib
  import errno
  import os
  import re
  import stat
  import string
  import sys
  import time
  import unittest
  import warnings
  from test import support
label_desc: Use image node_id 4 for calling a global function with example usage: can_xattr() and returns: can, _can_xattr