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 |
|---|---|---|
|
| Represents the Python language |
|
| 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 |
|---|---|---|
|
| Execution completed successfully |
|
| Error caused by the executed program itself |
|
| Program exceeded allocated resource limits (e.g., memory, time) |
|
| Program attempted forbidden operations or accesses |
|
| Runtime-specific errors during program execution |
|
| 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 |
|---|---|---|
|
| CPU time or wall clock time limit |
|
| Maximum memory usage allowed |
|
| 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 |
|---|---|---|
|
| Program called a forbidden system call |
|
| Unauthorized file system access attempted |
|
| 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 |
|---|---|---|
|
| Program terminated due to a signal (e.g., SIGKILL) |
|
| 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
All enums inherit from both
strandEnum. This dual inheritance allows enum members to behave like strings (e.g., for JSON serialization) while maintaining enum member semantics.The string values used in enums correspond directly to identifiers expected in external interfaces or configuration files, maintaining consistency across the codebase.
The enums group related constants by domain, enhancing code readability, maintainability, and reducing the likelihood of invalid values.
Interaction with Other Parts of the System
These enums are foundational for modules handling code execution, resource management, security enforcement, and result reporting.
For instance:
SupportLanguageis likely used by components responsible for selecting appropriate runtime environments.ResultStatusand related enums are used by execution runners, schedulers, and API layers to standardize the reporting of execution outcomes.ResourceLimitTypeinteracts with resource monitoring and enforcement subsystems.UnauthorizedAccessTypesupports security modules that detect and respond to sandbox violations.RuntimeErrorTypeassists in detailed diagnostics and error handling after program execution.
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:
Clear representation of supported languages and execution result states.
Standardized reporting and handling of resource limits and unauthorized access.
Categorization of runtime errors for better diagnostics.
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.