code: def _sanitize_key(key: str) -> str:
      """Returns a sanitized key that is a suitable directory/file name
  
      Documentation from the analog implementation in git-annex
      Annex/Locations.hs
  
      Converts a key into a filename fragment without any directory.
  
      Escape "/" in the key name, to keep a flat tree of files and avoid
      issues with keys containing "/../" or ending with "/" etc.
  
      "/" is escaped to "%" because it's short and rarely used, and resembles
          a slash
      "%" is escaped to "&s", and "&" to "&a"; this ensures that the mapping
          is one to one.
      ":" is escaped to "&c", because it seemed like a good idea at the time.
  
      Changing what this function escapes and how is not a good idea, as it
      can cause existing objects to get lost.
      """
      esc = {
          "/": "%",
          "%": "&s",
          "&": "&a",
          ":": "&c",
      }
      return "".join(esc.get(c, c) for c in key)
  
imports: from __future__ import annotations
  from datalad.utils import ensure_list
label_desc: Use image node_id 3 for calling a global function with example usage: _sanitize_key(key) and returns: str