def METHOD_NAME(stream):
    """Try to determine if the given stream supports colored output.
    Return True only if the stream declares to be a TTY, if it has a
    file descriptor on which ncurses can initialize a terminal and if
    that terminal's entry in terminfo declares support for colors.
    stream (fileobj): a file-like object (that adheres to the API
        declared in the `io' package).
    return (bool): True if we're sure that colors are supported, False
        if they aren't or if we can't tell.
    """
    if stream.isatty():
        try:
            curses.setupterm(fd=stream.fileno())
            # See `man terminfo` for capabilities' names and meanings.
            if curses.tigetnum("colors") > 0:
                return True
        # fileno() can raise OSError.
        except Exception:
            pass
    return False