<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def has_colors (fp):
 """Test if given file is an ANSI color enabled tty."""

    # 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