Upload utils.py with huggingface_hub
Browse files
utils.py
CHANGED
@@ -107,9 +107,9 @@ def safe_eval(expression: str, context: dict, allowed_tokens: list) -> any:
|
|
107 |
execute arbitrary code. The function attempts to mitigate security risks
|
108 |
by restricting the available tokens and not exposing built-in functions.
|
109 |
"""
|
110 |
-
|
111 |
-
if is_made_of_sub_strings(expression,
|
112 |
return eval(expression, {"__builtins__": {}}, context)
|
113 |
raise ValueError(
|
114 |
-
f"The expression '{expression}' can not be evaluated because it contains tokens outside the allowed list of {
|
115 |
)
|
|
|
107 |
execute arbitrary code. The function attempts to mitigate security risks
|
108 |
by restricting the available tokens and not exposing built-in functions.
|
109 |
"""
|
110 |
+
allowed_sub_strings = list(context.keys()) + allowed_tokens
|
111 |
+
if is_made_of_sub_strings(expression, allowed_sub_strings):
|
112 |
return eval(expression, {"__builtins__": {}}, context)
|
113 |
raise ValueError(
|
114 |
+
f"The expression '{expression}' can not be evaluated because it contains tokens outside the allowed list of {allowed_sub_strings}."
|
115 |
)
|