Convert color name or hexcode to (r,g,b) tuple

def color_to_rgb(color):
        """
        Convert color name or hexcode to (r,g,b) tuple
        """
        if isinstance(color, tuple):
            return color
        if color.startswith('#'):
            try:
                return webcolors.hex_to_rgb(color)
            except ValueError:
                raise InvalidColor(color)

        try:
            return webcolors.name_to_rgb(color)
        except ValueError:
            raise InvalidColor(color)