flare / validation_engine.py
ciyidogan's picture
Update validation_engine.py
74f2401 verified
raw
history blame
1.18 kB
"""
Flare – Parameter Validation (with date support)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Basit tip + regex kontrolü; Spark veya harici lib ile zenginleştirilebilir.
"""
import re
from typing import Any
from datetime import datetime
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 # All strings are valid
elif t == "bool":
if value.lower() not in ("true","false","1","0","evet","hayır"):
return False
# Special handling for date type
if param.type == "date":
try:
# Check if it's a valid ISO date format (YYYY-MM-DD)
datetime.strptime(value, "%Y-%m-%d")
except ValueError:
return False
# Regex validation if provided
if param.validation_regex and not re.fullmatch(param.validation_regex, value, re.I):
return False
return True