enums.py


Overview

The enums.py file defines a collection of enumerations (enums) used throughout the InfiniFlow project. These enums provide a type-safe and readable way to represent various fixed sets of related constants, primarily related to supported programming languages, execution result statuses, resource limits, unauthorized access types, and runtime error classifications.

By leveraging Python’s Enum class alongside string values, the enums ensure both clarity in code and ease of serialization/deserialization, especially useful in contexts such as API responses, logging, and configuration.


Enumerations

1. SupportLanguage

Represents the programming languages supported by InfiniFlow for code execution or processing.

Definition:

class SupportLanguage(str, Enum):
    PYTHON = "python"
    NODEJS = "nodejs"

Members:

Member

Value

Description

PYTHON

"python"

Represents the Python language

NODEJS

"nodejs"

Represents the Node.js language

Usage Example:

def run_code(language: SupportLanguage, code: str):
    if language == SupportLanguage.PYTHON:
        # Execute Python code
        pass
    elif language == SupportLanguage.NODEJS:
        # Execute Node.js code
        pass

2. ResultStatus

Enumerates possible outcomes after executing a program or task within the system.

Definition:

class ResultStatus(str, Enum):
    SUCCESS = "success"
    PROGRAM_ERROR = "program_error"
    RESOURCE_LIMIT_EXCEEDED = "resource_limit_exceeded"
    UNAUTHORIZED_ACCESS = "unauthorized_access"
    RUNTIME_ERROR = "runtime_error"
    PROGRAM_RUNNER_ERROR = "program_runner_error"

Members:

Member

Value

Description

SUCCESS

"success"

Execution completed successfully

PROGRAM_ERROR

"program_error"

Error caused by the executed program itself

RESOURCE_LIMIT_EXCEEDED

"resource_limit_exceeded"

Program exceeded allocated resource limits (e.g., memory, time)

UNAUTHORIZED_ACCESS

"unauthorized_access"

Program attempted forbidden operations or accesses

RUNTIME_ERROR

"runtime_error"

Runtime-specific errors during program execution

PROGRAM_RUNNER_ERROR

"program_runner_error"

Errors caused by the program runner infrastructure

Usage Example:

def handle_result(status: ResultStatus):
    if status == ResultStatus.SUCCESS:
        print("Execution succeeded")
    elif status == ResultStatus.RESOURCE_LIMIT_EXCEEDED:
        print("Resource limits exceeded")
    # Additional handling ...

3. ResourceLimitType

Specifies types of resource constraints that can be enforced on program execution.

Definition:

class ResourceLimitType(str, Enum):
    TIME = "time"
    MEMORY = "memory"
    OUTPUT = "output"

Members:

Member

Value

Description

TIME

"time"

CPU time or wall clock time limit

MEMORY

"memory"

Maximum memory usage allowed

OUTPUT

"output"

Maximum output size limit (e.g., stdout, file output)

Usage Example:

def check_resource_limit(limit_type: ResourceLimitType, value: int):
    if limit_type == ResourceLimitType.MEMORY:
        print(f"Memory limit set to {value} MB")

4. UnauthorizedAccessType

Defines categories of unauthorized access attempts detected during program execution, useful for sandboxing and security enforcement.

Definition:

class UnauthorizedAccessType(str, Enum):
    DISALLOWED_SYSCALL = "disallowed_syscall"
    FILE_ACCESS = "file_access"
    NETWORK_ACCESS = "network_access"

Members:

Member

Value

Description

DISALLOWED_SYSCALL

"disallowed_syscall"

Program called a forbidden system call

FILE_ACCESS

"file_access"

Unauthorized file system access attempted

NETWORK_ACCESS

"network_access"

Unauthorized network operations attempted

Usage Example:

def log_unauthorized_access(access_type: UnauthorizedAccessType):
    print(f"Unauthorized access detected: {access_type.value}")

5. RuntimeErrorType

Categorizes runtime errors that may occur during program execution, providing further granularity on failure modes.

Definition:

class RuntimeErrorType(str, Enum):
    SIGNALLED = "signalled"
    NONZERO_EXIT = "nonzero_exit"

Members:

Member

Value

Description

SIGNALLED

"signalled"

Program terminated due to a signal (e.g., SIGKILL)

NONZERO_EXIT

"nonzero_exit"

Program exited with a non-zero exit code

Usage Example:

def analyze_runtime_error(error_type: RuntimeErrorType):
    if error_type == RuntimeErrorType.SIGNALLED:
        print("Process was terminated by a signal.")
    elif error_type == RuntimeErrorType.NONZERO_EXIT:
        print("Process exited with an error code.")

Implementation Details


Interaction with Other Parts of the System

Because these enums represent standardized categories and codes, they facilitate consistent communication between disparate system components, including front-end interfaces, backend services, and logging systems.


Mermaid Diagram

classDiagram
    class SupportLanguage {
        <<Enum>>
        +PYTHON: str = "python"
        +NODEJS: str = "nodejs"
    }
    class ResultStatus {
        <<Enum>>
        +SUCCESS: str = "success"
        +PROGRAM_ERROR: str = "program_error"
        +RESOURCE_LIMIT_EXCEEDED: str = "resource_limit_exceeded"
        +UNAUTHORIZED_ACCESS: str = "unauthorized_access"
        +RUNTIME_ERROR: str = "runtime_error"
        +PROGRAM_RUNNER_ERROR: str = "program_runner_error"
    }
    class ResourceLimitType {
        <<Enum>>
        +TIME: str = "time"
        +MEMORY: str = "memory"
        +OUTPUT: str = "output"
    }
    class UnauthorizedAccessType {
        <<Enum>>
        +DISALLOWED_SYSCALL: str = "disallowed_syscall"
        +FILE_ACCESS: str = "file_access"
        +NETWORK_ACCESS: str = "network_access"
    }
    class RuntimeErrorType {
        <<Enum>>
        +SIGNALLED: str = "signalled"
        +NONZERO_EXIT: str = "nonzero_exit"
    }

Summary

The enums.py file encapsulates key enumerations for the InfiniFlow system, enabling:

These enums are critical for maintaining consistent, readable, and robust code, especially in a system that executes and manages user-submitted programs across multiple languages and environments.