CodeSafe Functions
Safe eval
Parameters:
expr (str): The expression to evaluate.
allowed_builtins (dict, optional): A dictionary of allowed built-in functions. Defaults to {}.
allowed_vars (dict, optional): A dictionary of allowed variables and functions. Defaults to {}.
timeout (float, optional): Time limit for evaluation in seconds. Defaults to 5.
restricted_imports (list, optional): A list of restricted imports or modules. Defaults to [].
allowed_function_calls (list, optional): A list of allowed function names to call. Defaults to [].
allow_attributes (bool, optional): Whether to allow access to safe attributes and methods (e.g., 'str.upper()'). Defaults to False.
immediate_termination (bool, optional): Whether to forcibly terminate the evaluation if it exceeds the timeout. Defaults to True.
file_access (bool, optional): Whether to allow file access (open, etc.). Defaults to False.
network_access (bool, optional): Whether to allow network access (requests, etc.). Defaults to False.
Returns:
object: The result of the evaluated expression.
Raises:
EvaluationTimeoutError: If the evaluation exceeds the allowed time.
ValueError: If the expression contains unsafe operations.
UnsafeExpressionError: If restricted imports or unsafe nodes are detected in the AST.
SyntaxError: If the expression contains invalid syntax.Function arguments:
Encrypt to file
Run
Decrypt to file
Encrypt
Decrypt
Last updated