Documentation
Our WebsiteOur Github
  • 👋Welcome to Infinitode Documentation
  • AI Documentation
  • API Documentation
    • Basic Math API Documentation (#Experimental)
    • BMI Calculator API Documentation
    • Character Counter API Documentation
    • Chemical Equation Balancer API Documentation
    • Color Generator API Documentation
    • Date Difference Calculator API Documentation
    • Dungen API Documentation
    • Dungen Dev API Documentation
    • Factorial Calculator API Documentation
    • Fantasy Name Generator API Documentation
    • Fibonacci Sequence Generator API Documentation
    • GCD Calculator API Documentation
    • Hash API Documentation
    • Helix PSA API Documentation
    • LCM Calculator API Documentation
    • Leap Year Checker API Documentation
    • Lorem API Documentation
    • Molar Mass Calculator API Documentation (#Experimental)
    • MycoNom API Documentation
    • Name Generator API Documentation
    • Palindrome Checker API Documentation
    • Password Generator API Documentation
    • Password Strength Detector API Documentation
    • Periodic Table API Documentation
    • Prime Number Checker API Documentation
    • Quadratic Equation Solver API Documentation
    • Random Facts Generator API Documentation
    • Random Quotes Generator API Documentation
    • Roman Numeral Converter API Documentation
    • Simple Interest Calculator API Documentation
    • Slugify API Documentation
    • Text Case Converter API Documentation
    • Unit Converter API Documentation
    • Username Generator API Documentation
    • UUID Generator API Documentation
    • Vowel Counter API Documentation
  • Package Documentation
    • BlurJS Package Documentation
      • BlurJS Usage Examples
      • BlurJS Reference Documentation
    • CodeSafe Package Documentation
      • CodeSafe Reference
        • CodeSafe Functions
    • DeepDefend Package Documentation
      • DeepDefend Reference
        • Attacks Functions
        • Defenses Functions
    • DupliPy Package Documentation
      • DupliPy Reference
        • Formatting Functions
        • Replication Functions
        • Similarity Functions
        • Text Analysis Functions
    • FuncProfiler Package Documentation
      • FuncProfiler Reference
        • FuncProfiler Functions
    • Hued Package Documentation
      • Hued Reference
        • Analysis Functions
        • Colors Functions
        • Conversions Functions
        • Palettes Functions
    • LocalSiteMap Package Documentation
      • LocalSiteMap Reference
        • LocalSiteMap Functions
    • PyAutoPlot Package Documentation
      • PyAutoPlot Reference
        • PyAutoPlot Functions
    • PyWebScrapr Package Documentation
      • PyWebScrapr Reference
        • PyWebScrapr Functions
    • ValX Package Documentation
      • ValX Reference
        • ValX Functions
Powered by GitBook
On this page
  • Safe eval
  • Encrypt to file
  • Run
  • Decrypt to file
  • Encrypt
  • Decrypt

Was this helpful?

  1. Package Documentation
  2. CodeSafe Package Documentation
  3. CodeSafe Reference

CodeSafe Functions

PreviousCodeSafe ReferenceNextDeepDefend Package Documentation

Last updated 5 months ago

Was this helpful?

Available functions:

  • (expr, allowed_builtins, allowed_vars, timeout=5, restricted_imports, allowed_function_calls, immediate_termination=False, file_access=False, network_access=False): Evaluate an expression safely.

  • (code, output_file=None, mapping=default): Encrypt code to a file.

  • (encrypted_file, mapping=default): Run an encrypted code file (only available for code/formats Python understands)

  • (encrypted_file, output_file=None, mapping=default): Decrypt an encrypted file to a new file.

  • (code, mapping=default): Encrypt code, and return it.

  • (encrypted_code, mapping=default): Decrypt the code, and return it.


Safe eval

Evaluate an expression safely.

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 [].
        immediate_termination (bool, optional): Whether to forcibly terminate the evaluation if it exceeds the timeout. Defaults to False.
        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:

expr: An expression to evaluate.

allowed_builtins: A dictionary object of allowed built-in functions. builtins = {"abs": abs, "max": max}

allowed_vars: A dictionary object of allowed variables and functions. {"x": 10, "y": 20, "custom_sum": custom_sum, "long_running_function": long_running_function, "sleep": sleep}. For custom functions, other functions like time.sleep, and other variables in your code.

timeout: The evaluation limit for the call, defaults to 5 seconds.

restricted_imports: A list of restricted imports or modules. ['os', 'sys'].

allowed_function_calls: A list of allowed function calls. Even when allowed_vars contains the function, it is not callable unless passed to this parameter as well. ['custom_sum', 'max', 'abs', 'long_running_function', 'sleep']

immediate_termination: A bool that controls whether to forcibly terminate an evaluation, if it exceeds the timeout, otherwise, the evaluation will continue until it is finished.

file_access: A bool that controls file access, and allows or disallows access to the filesystem. It restricts additional functions and modules from being called. Defaults to False.

internet_access: A bool that controls internet access, and allows or disallows access to network, sockets, requests, and other libraries. Defaults to False.

Encrypt to file

Encrypt code to a file.

Parameters:
        code (str): The Python code to encrypt.
        output_file (str): The path to the output Python file to embed encrypted code.
        mapping (dict): The mapping dictionary for character replacements.

Returns:
        None

Run

Run an encrypted code file (only available for code/formats Python understands).

Parameters:
        encrypted_file (str): Path to the Python file with embedded encrypted code.
        mapping (dict): The mapping dictionary for character replacements.

Returns:
        None

Decrypt to file

Decrypt an encrypted file to a new file.

Parameters:
        encrypted_file (str): Path to the Python file with embedded encrypted code.
        output_file (str): Path to the output Python file for decrypted code.
        mapping (dict): The mapping dictionary for character replacements.

Returns:
        None

Encrypt

Encrypt code, and return it.

Parameters:
        code (str): The Python code to encrypt.
        mapping (dict): The mapping dictionary for character replacements.

Returns:
        str: The encrypted code.

Decrypt

Decrypt code, and return it.

Parameters:
        code (str): The Python code to decrypt.
        mapping (dict): The mapping dictionary for character replacements.

Returns:
        str: The decrypted code.
safe_eval
encrypt_to_file
run
decrypt_to_file
encrypt
decrypt