def htmlcolor2rgb(color_str):
    """ convert #RRGGBB to an (R, G, B) tuple """
    color_str = color_str.strip()[-6:]
    if len(color_str) != 6:
        raise ValueError("input #%s is not in #RRGGBB format" % color_str)
    r, g, b = color_str[:2], color_str[2:4], color_str[4:]
    return (int(n, 16) for n in (r, g, b))