Elron commited on
Commit
23cdef0
·
verified ·
1 Parent(s): ff7d384

Upload utils.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. utils.py +3 -3
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
- allowd_sub_strings = list(context.keys()) + allowed_tokens
111
- if is_made_of_sub_strings(expression, allowd_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 {allowd_sub_strings}."
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
  )