def rgb(x):
    """Return a triple representing rgb color.

    Can convert colors by name or hexcode. Passing in a valid rgb tuple is
    idempotent.

    Example
    -------
    >>> rgb('plum')
    (221, 160, 221)
    >>> rgb('#FFFFFF')
    (255, 255, 255)
    >>> rgb((255, 255, 255))
    (255, 255, 255)
    """
    if isinstance(x, str):
        if x.startswith('#'):
            return hex_to_rgb(x)
        elif x in color_lookup:
            return hex_to_rgb(color_lookup[x])
        else:
            raise ValueError("Unknown color: '{0}'".format(x))
    elif isinstance(x, tuple) and len(x) == 3:
        if 0 < min(x) or max(x) > 255:
            raise ValueError("Invalid RGB tuple")
    else:
        raise TypeError("Don't know how to convert {0} to RGB".format(x))
    return x

#   Example palettes

# Copied from from bokeh.palettes.Greys9
dataset/ETHPy150Open bokeh/datashader/datashader/colors.py/rgb/swapped operands of `<`