Spaces:
Building
Building
Update validation_engine.py
Browse files- validation_engine.py +22 -6
validation_engine.py
CHANGED
@@ -1,25 +1,41 @@
|
|
1 |
"""
|
2 |
-
Flare – Parameter Validation
|
3 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
4 |
Basit tip + regex kontrolü; Spark veya harici lib ile zenginleştirilebilir.
|
5 |
"""
|
6 |
|
7 |
import re
|
8 |
from typing import Any
|
|
|
9 |
from config_provider import ParameterConfig
|
10 |
|
11 |
def validate(value: str, param: ParameterConfig) -> bool:
|
12 |
t = param.canonical_type()
|
|
|
13 |
if t == "int":
|
14 |
-
if not value.isdigit():
|
|
|
15 |
elif t == "float":
|
16 |
-
try:
|
17 |
-
|
|
|
|
|
18 |
elif t in ("str", "string"):
|
19 |
-
pass
|
20 |
elif t == "bool":
|
21 |
-
if value.lower() not in ("true","false","1","0","evet","hayır"):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
|
|
23 |
if param.validation_regex and not re.fullmatch(param.validation_regex, value, re.I):
|
24 |
return False
|
|
|
25 |
return True
|
|
|
1 |
"""
|
2 |
+
Flare – Parameter Validation (with date support)
|
3 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
4 |
Basit tip + regex kontrolü; Spark veya harici lib ile zenginleştirilebilir.
|
5 |
"""
|
6 |
|
7 |
import re
|
8 |
from typing import Any
|
9 |
+
from datetime import datetime
|
10 |
from config_provider import ParameterConfig
|
11 |
|
12 |
def validate(value: str, param: ParameterConfig) -> bool:
|
13 |
t = param.canonical_type()
|
14 |
+
|
15 |
if t == "int":
|
16 |
+
if not value.isdigit():
|
17 |
+
return False
|
18 |
elif t == "float":
|
19 |
+
try:
|
20 |
+
float(value)
|
21 |
+
except ValueError:
|
22 |
+
return False
|
23 |
elif t in ("str", "string"):
|
24 |
+
pass # All strings are valid
|
25 |
elif t == "bool":
|
26 |
+
if value.lower() not in ("true","false","1","0","evet","hayır"):
|
27 |
+
return False
|
28 |
+
|
29 |
+
# Special handling for date type
|
30 |
+
if param.type == "date":
|
31 |
+
try:
|
32 |
+
# Check if it's a valid ISO date format (YYYY-MM-DD)
|
33 |
+
datetime.strptime(value, "%Y-%m-%d")
|
34 |
+
except ValueError:
|
35 |
+
return False
|
36 |
|
37 |
+
# Regex validation if provided
|
38 |
if param.validation_regex and not re.fullmatch(param.validation_regex, value, re.I):
|
39 |
return False
|
40 |
+
|
41 |
return True
|