This documentation was generated with AI assistance and is still being audited. Some, or potentially a lot, of this information may be inaccurate. Learn more.
defvalidate_choice(choices:list[Any])->Callable[[Any,Any,Any],None]:"""Create a validator that ensures value is one of the given choices. Args: choices: List of valid choices Returns: Validator function for use with attrs """defvalidator(instance:Any,attribute:Any,value:Any)->None:ifvaluenotinchoices:# Import ValidationError locally to avoid circular importsfromprovide.foundation.errors.configimportValidationErrorraiseValidationError(f"Invalid value '{value}' for {attribute.name}. Must be one of: {choices!r}",)returnvalidator
defvalidate_log_level(instance:Any,attribute:Any,value:str)->None:"""Validate that a log level is valid."""# Import ValidationError locally to avoid circular importsfromprovide.foundation.errors.configimportValidationErrorifvaluenotin_VALID_LOG_LEVEL_TUPLE:raiseValidationError(_format_invalid_value_error(attribute.name,value,valid_options=list(_VALID_LOG_LEVEL_TUPLE),),)
defvalidate_non_negative(instance:Any,attribute:Any,value:float)->None:"""Validate that a value is non-negative."""# Import ValidationError locally to avoid circular importsfromprovide.foundation.errors.configimportValidationError# Check if value is numericifnotisinstance(value,(int,float)):raiseValidationError(f"Value must be a number, got {type(value).__name__}",)ifvalue<0:raiseValidationError(_format_validation_error(attribute.name,value,"must be non-negative"),)
defvalidate_port(instance:Any,attribute:Any,value:int)->None:"""Validate that a port number is valid."""# Import ValidationError locally to avoid circular importsfromprovide.foundation.errors.configimportValidationErrorifnot1<=value<=65535:raiseValidationError(_format_validation_error(attribute.name,value,"must be between 1 and 65535"),)
defvalidate_positive(instance:Any,attribute:Any,value:float)->None:"""Validate that a value is positive."""# Import ValidationError locally to avoid circular importsfromprovide.foundation.errors.configimportValidationError# Check if value is numericifnotisinstance(value,(int,float)):raiseValidationError(f"Value must be a number, got {type(value).__name__}",)ifvalue<=0:raiseValidationError(_format_validation_error(attribute.name,value,"must be positive"),)
defvalidate_range(min_val:float,max_val:float)->Callable[[Any,Any,Any],None]:"""Create a validator that ensures value is within the given numeric range. Args: min_val: Minimum allowed value (inclusive) max_val: Maximum allowed value (inclusive) Returns: Validator function for use with attrs """defvalidator(instance:Any,attribute:Any,value:Any)->None:# Import ValidationError locally to avoid circular importsfromprovide.foundation.errors.configimportValidationError# Check if value is numericifnotisinstance(value,(int,float)):raiseValidationError(f"Value must be a number, got {type(value).__name__}",)ifnot(min_val<=value<=max_val):raiseValidationError(f"Value must be between {min_val} and {max_val}, got {value}",)returnvalidator
defvalidate_sample_rate(instance:Any,attribute:Any,value:float)->None:"""Validate that a sample rate is between 0.0 and 1.0."""# Import ValidationError locally to avoid circular importsfromprovide.foundation.errors.configimportValidationErrorifnot0.0<=value<=1.0:raiseValidationError(_format_validation_error(attribute.name,value,"must be between 0.0 and 1.0"),)