code: def _color_code(spec, base):
      """
      Workhorse of encoding a color. Give preference to named colors from
      ANSI, then to specific numeric or tuple specs. If those don't work,
      try looking up look CSS color names or parsing CSS hex and rgb color
      specifications.
  
      :param str|int|tuple|list spec: Unparsed color specification
      :param int base: Either 30 or 40, signifying the base value
          for color encoding (foreground and background respectively).
          Low values are added directly to the base. Higher values use `
          base + 8` (i.e. 38 or 48) then extended codes.
      :returns: Discovered ANSI color encoding.
      :rtype: str
      :raises: ValueError if cannot parse the color spec.
      """
      if is_string(spec):
          spec = spec.strip().lower()
  
      if spec == "default":
          return _join(base + 9)
      elif spec in COLORS:
          return _join(base + COLORS.index(spec))
      elif isinstance(spec, int) and 0 <= spec <= 255:
          return _join(base + 8, 5, spec)
      elif isinstance(spec, (tuple, list)):
          return _join(base + 8, 2, _join(*spec))
      else:
          rgb = parse_rgb(spec)
          # parse_rgb raises ValueError if cannot parse spec
          return _join(base + 8, 2, _join(*rgb))
  
file_path: keepsake/python/keepsake/_vendor/colors/colors.py
imports: from __future__ import absolute_import, print_function
  import re
  import sys
  from .csscolors import parse_rgb, css_colors
  from functools import partial
label_desc: Use image node_id 3 for calling a global function with example usage: _color_code(spec, base) and returns: _join, _join, _join, _join, _join