forked from microsoft/semantic-kernel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidation.py
More file actions
72 lines (53 loc) · 2.15 KB
/
Copy pathvalidation.py
File metadata and controls
72 lines (53 loc) · 2.15 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# Copyright (c) Microsoft. All rights reserved.
from re import match as re_match
from typing import Optional
def validate_skill_name(value: Optional[str]) -> None:
"""
Validates that the skill name is valid.
Valid skill names are non-empty and
match the regex: [0-9A-Za-z_]*
:param value: The skill name to validate.
:raises ValueError: If the skill name is invalid.
"""
if not value:
raise ValueError("The skill name cannot be `None` or empty")
SKILL_NAME_REGEX = r"^[0-9A-Za-z_]*$"
if not re_match(SKILL_NAME_REGEX, value):
raise ValueError(
f"Invalid skill name: {value}. Skill "
f"names may only contain ASCII letters, "
f"digits, and underscores."
)
def validate_function_name(value: Optional[str]) -> None:
"""
Validates that the function name is valid.
Valid function names are non-empty and
match the regex: [0-9A-Za-z_]*
:param value: The function name to validate.
:raises ValueError: If the function name is invalid.
"""
if not value:
raise ValueError("The function name cannot be `None` or empty")
FUNCTION_NAME_REGEX = r"^[0-9A-Za-z_]*$"
if not re_match(FUNCTION_NAME_REGEX, value):
raise ValueError(
f"Invalid function name: {value}. Function "
f"names may only contain ASCII letters, "
f"digits, and underscores."
)
def validate_function_param_name(value: Optional[str]) -> None:
"""
Validates that the function parameter name is valid.
Valid function parameter names are non-empty and
match the regex: [0-9A-Za-z_]*
:param value: The function parameter name to validate.
:raises ValueError: If the function parameter name is invalid.
"""
if not value:
raise ValueError("The function parameter name cannot be `None` or empty")
FUNCTION_PARAM_NAME_REGEX = r"^[0-9A-Za-z_]*$"
if not re_match(FUNCTION_PARAM_NAME_REGEX, value):
raise ValueError(
f"Invalid function parameter name: {value}. Function parameter "
f"names may only contain ASCII letters, digits, and underscores."
)