Spaces:
Building
Building
File size: 1,175 Bytes
c08424b 74f2401 c08424b 2bfc495 c08424b 74f2401 c08424b 74f2401 c08424b 74f2401 c08424b 74f2401 c08424b 74f2401 c08424b 74f2401 2bfc495 74f2401 c08424b 74f2401 c08424b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
"""
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
|