Spaces:
Building
Building
""" | |
Flare – Parameter Validation | |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
Basit tip + regex kontrolü; Spark veya harici lib ile zenginleştirilebilir. | |
""" | |
import re | |
from typing import Any | |
from config_provider import ParameterConfig | |
def validate(value: str, param: ParameterConfig) -> bool: | |
t = param.canonical_type() | |
if t == "int": | |
if not value.isdigit(): return False | |
elif t == "float": | |
try: float(value) | |
except ValueError: return False | |
elif t in ("str", "string"): | |
pass | |
elif t == "bool": | |
if value.lower() not in ("true","false","1","0","evet","hayır"): return False | |
if param.validation_regex and not re.fullmatch(param.validation_regex, value, re.I): | |
return False | |
return True | |