(string)
return True, ""
Check if the rgbradient expression is valid.

    :param str string: The string to validate.
    :rtype: (bool, str)

    >>> is_rgbgradient("foo(colors=0:red)")
    (False, "... It must looks like 'rgbgradient(<PARAMS>)'...")
    >>> is_rgbgradient("rgbgradient(duration=1000)")
    (False, "... You must provide at least one color: ...")
    >>> is_rgbgradient("rgbgradient(colors=red)")
    (False, "invalid color gradient...")
    >>> is_rgbgradient("rgbgradient(colors=0:red; foo=bar)")
    (False, "unknown parameter 'foo'...")
Check if the rgbradient expression is valid.
Check if the rgbradient expression is valid .
def is_rgbgradient(string):
    """Check if the rgbradient expression is valid.

    :param str string: The string to validate.
    :rtype: (bool, str)

    >>> is_rgbgradient("foo(colors=0:red)")
    (False, "... It must looks like 'rgbgradient(<PARAMS>)'...")
    >>> is_rgbgradient("rgbgradient(duration=1000)")
    (False, "... You must provide at least one color: ...")
    >>> is_rgbgradient("rgbgradient(colors=red)")
    (False, "invalid color gradient...")
    >>> is_rgbgradient("rgbgradient(colors=0:red; foo=bar)")
    (False, "unknown parameter 'foo'...")
    """
    try:
        rgbgradient_dict = parse_param_string(
            string,
            value_parsers={
                "rgbgradient": {
                    "duration": int,
                    "colors": parse_color_gradient_string,
                }
            },
        )
    except ValueError as e:
        return False, str(e)

    if "rgbgradient" not in rgbgradient_dict:
        reason = ""
        reason += "invalid rgbgradient expression. "
        reason += "It must looks like 'rgbgradient(<PARAMS>)'."
        return False, reason

    if (
        "colors" not in rgbgradient_dict["rgbgradient"]
        or len(rgbgradient_dict["rgbgradient"]) == 0
    ):
        reason = ""
        reason += "invalid rgbgradient expression. "
        reason += "You must provide at least one color: "
        reason += "'rgbgradient(colors=<POS>: <COLOR>)'."
        return False, reason

    _allowed_params = ["colors", "duration"]
    for key in rgbgradient_dict["rgbgradient"].keys():
        if key not in _allowed_params:
            reason = ""
            reason += "unknown parameter '%s'. " % key
            reason += "Allowed parameters are %s." % ", ".join(
                ["'%s'" % p for p in _allowed_params]
            )
            return False, reason

    return True, ""
def is_rgbgradient ( string ) : try : rgbgradient_dict = parse_param_string ( string , value_parsers = { "rgbgradient" : { "duration" : int , "colors" : parse_color_gradient_string , } } , ) except ValueError as e : return False , str ( e ) if "rgbgradient" not in rgbgradient_dict : reason = "" reason += "invalid rgbgradient expression. " reason += "It must looks like 'rgbgradient(<PARAMS>)'." return False , reason if ( "colors" not in rgbgradient_dict [ "rgbgradient" ] or len ( rgbgradient_dict [ "rgbgradient" ] ) == 0 ) : reason = "" reason += "invalid rgbgradient expression. " reason += "You must provide at least one color: " reason += "'rgbgradient(colors=<POS>: <COLOR>)'." return False , reason _allowed_params = [ "colors" , "duration" ] for key in rgbgradient_dict [ "rgbgradient" ] . keys ( ) : if key not in _allowed_params : reason = "" reason += "unknown parameter '%s'. " % key reason += "Allowed parameters are %s." % ", " . join ( [ "'%s'" % p for p in _allowed_params ] ) return False , reason return True , ""