code: def rmtree(path, ignore_errors=False, onerror=None, *, dir_fd=None):
      """Recursively delete a directory tree.
  
      If dir_fd is not None, it should be a file descriptor open to a directory;
      path will then be relative to that directory.
      dir_fd may not be implemented on your platform.
      If it is unavailable, using it will raise a NotImplementedError.
  
      If ignore_errors is set, errors are ignored; otherwise, if onerror
      is set, it is called to handle the error with arguments (func,
      path, exc_info) where func is platform and implementation dependent;
      path is the argument to that function that caused it to fail; and
      exc_info is a tuple returned by sys.exc_info().  If ignore_errors
      is false and onerror is None, an exception is raised.
  
      """
      sys.audit("shutil.rmtree", path, dir_fd)
      if ignore_errors:
  
          def onerror(*args):
              pass
  
      elif onerror is None:
  
          def onerror(*args):
              raise
  
      if _use_fd_functions:
          # While the unsafe rmtree works fine on bytes, the fd based does not.
          if isinstance(path, bytes):
              path = os.fsdecode(path)
          # Note: To guard against symlink races, we use the standard
          # lstat()/open()/fstat() trick.
          try:
              orig_st = os.lstat(path, dir_fd=dir_fd)
          except Exception:
              onerror(os.lstat, path, sys.exc_info())
              return
          try:
              fd = os.open(path, os.O_RDONLY, dir_fd=dir_fd)
              fd_closed = False
          except Exception:
              onerror(os.open, path, sys.exc_info())
              return
          try:
              if os.path.samestat(orig_st, os.fstat(fd)):
                  _rmtree_safe_fd(fd, path, onerror)
                  try:
                      os.close(fd)
                      fd_closed = True
                      os.rmdir(path, dir_fd=dir_fd)
                  except OSError:
                      onerror(os.rmdir, path, sys.exc_info())
              else:
                  try:
                      # symlinks to directories are forbidden, see bug #1669
                      raise OSError(
                          "Cannot call rmtree on a symbolic link"
                      )
                  except OSError:
                      onerror(os.path.islink, path, sys.exc_info())
          finally:
              if not fd_closed:
                  os.close(fd)
      else:
          if dir_fd is not None:
              raise NotImplementedError(
                  "dir_fd unavailable on this platform"
              )
          try:
              if _rmtree_islink(path):
                  # symlinks to directories are forbidden, see bug #1669
                  raise OSError("Cannot call rmtree on a symbolic link")
          except OSError:
              onerror(os.path.islink, path, sys.exc_info())
              # can't continue even if onerror hook returns
              return
          return _rmtree_unsafe(path, onerror)
  
imports: import os
  import sys
  import stat
  import fnmatch
  import collections
  import errno
label_desc: Use image node_id 18 for calling a global function with example usage: rmtree(path, ignore_errors, onerror) and returns: _rmtree_unsafe