RuleChecker Class
- class kwhelp.checks.RuleChecker(rules_all: Optional[Iterable[kwhelp.rules.IRule]] = None, rules_any: Optional[Iterable[kwhelp.rules.IRule]] = None, **kwargs)[source]
Class that validates args match a given rule
- __init__(rules_all: Optional[Iterable[kwhelp.rules.IRule]] = None, rules_any: Optional[Iterable[kwhelp.rules.IRule]] = None, **kwargs)[source]
Constructor
- Parameters
- Keyword Arguments
raise_error (bool, optional) – If
Truethen rules can raise errors when validation fails. DefaultFalse.- Raises
TypeError – If
rule_allis not an iterable objectTypeError – If
rule_anyis not an iterable object
- validate_all(*args, **kwargs) bool[source]
Validates all. All
*argsand**kwargsmust matchrules_all- Returns
Trueif all*argsand**kwargsare valid; Otherwise,False- Return type
bool
- Raises
Exception – If
raise_errorisTrueand validation Fails. The type of exception raised is dependend on theIRulethat caused validation failure. Most rules raise aValueErroror aTypeError.
- validate_any(*args, **kwargs) bool[source]
Validates any. All
*argsand**kwargsmust match on ore more ofrules_any- Returns
Trueif all*argsand**kwargsare valid; Otherwise,False- Return type
bool
- Raises
Exception – If
raise_errorisTrueand validation Fails. The type of exception raised is dependend on theIRulethat caused validation failure. Most rules raise aValueErroror aTypeError.
- property raise_error: bool
Determines if errors will be raised during validation
If
Truethen errors will be raised when validation fails. Default value isTrue.- Getter
Gets if errors can be raised.
- Setter
Sets if errors can be raised.
- property rules_all: Iterable[kwhelp.rules.IRule]
Gets rules passed into
rules_allof constructor used for validation of args.
- property rules_any: Iterable[kwhelp.rules.IRule]
Gets rules passed into
rules_anyof constructor used for validation of args.