code: def has_colors (fp):
      
      # The is_tty() function ensures that we do not colorize
      # redirected streams, as this is almost never what we want
      if not is_tty(fp):
          return False
      if os.name == 'nt':
          return True
      elif has_curses:
          import curses
          try:
              curses.setupterm(os.environ.get("TERM"), fp.fileno())
              # More than 8 colors are good enough.
              return curses.tigetnum("colors") >= 8
          except curses.error:
              return False
      return False
docs: Test if given file is an ANSI color enabled tty.