unrealon 1.1.6__py3-none-any.whl → 2.0.5__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (144) hide show
  1. {unrealon-1.1.6.dist-info/licenses → unrealon-2.0.5.dist-info}/LICENSE +1 -1
  2. unrealon-2.0.5.dist-info/METADATA +491 -0
  3. unrealon-2.0.5.dist-info/RECORD +128 -0
  4. {unrealon-1.1.6.dist-info → unrealon-2.0.5.dist-info}/WHEEL +2 -1
  5. unrealon-2.0.5.dist-info/entry_points.txt +3 -0
  6. unrealon-2.0.5.dist-info/top_level.txt +3 -0
  7. unrealon_browser/__init__.py +5 -6
  8. unrealon_browser/cli/browser_cli.py +18 -9
  9. unrealon_browser/cli/interactive_mode.py +13 -4
  10. unrealon_browser/core/browser_manager.py +29 -16
  11. unrealon_browser/dto/__init__.py +21 -0
  12. unrealon_browser/dto/bot_detection.py +175 -0
  13. unrealon_browser/dto/models/config.py +9 -3
  14. unrealon_browser/managers/__init__.py +1 -1
  15. unrealon_browser/managers/logger_bridge.py +1 -4
  16. unrealon_browser/stealth/__init__.py +27 -0
  17. unrealon_browser/stealth/bypass_techniques.pyc +0 -0
  18. unrealon_browser/stealth/manager.pyc +0 -0
  19. unrealon_browser/stealth/nodriver_stealth.pyc +0 -0
  20. unrealon_browser/stealth/playwright_stealth.pyc +0 -0
  21. unrealon_browser/stealth/scanner_tester.pyc +0 -0
  22. unrealon_browser/stealth/undetected_chrome.pyc +0 -0
  23. unrealon_core/__init__.py +172 -0
  24. unrealon_core/config/__init__.py +16 -0
  25. unrealon_core/config/environment.py +151 -0
  26. unrealon_core/config/urls.py +94 -0
  27. unrealon_core/enums/__init__.py +24 -0
  28. unrealon_core/enums/status.py +216 -0
  29. unrealon_core/enums/types.py +240 -0
  30. unrealon_core/error_handling/__init__.py +45 -0
  31. unrealon_core/error_handling/circuit_breaker.py +292 -0
  32. unrealon_core/error_handling/error_context.py +324 -0
  33. unrealon_core/error_handling/recovery.py +371 -0
  34. unrealon_core/error_handling/retry.py +268 -0
  35. unrealon_core/exceptions/__init__.py +46 -0
  36. unrealon_core/exceptions/base.py +292 -0
  37. unrealon_core/exceptions/communication.py +22 -0
  38. unrealon_core/exceptions/driver.py +11 -0
  39. unrealon_core/exceptions/proxy.py +11 -0
  40. unrealon_core/exceptions/task.py +12 -0
  41. unrealon_core/exceptions/validation.py +17 -0
  42. unrealon_core/models/__init__.py +79 -0
  43. unrealon_core/models/arq_context.py +252 -0
  44. unrealon_core/models/arq_responses.py +125 -0
  45. unrealon_core/models/base.py +291 -0
  46. unrealon_core/models/bridge_stats.py +58 -0
  47. unrealon_core/models/communication.py +39 -0
  48. unrealon_core/models/connection_stats.py +47 -0
  49. unrealon_core/models/driver.py +30 -0
  50. unrealon_core/models/driver_details.py +98 -0
  51. unrealon_core/models/logging.py +28 -0
  52. unrealon_core/models/task.py +21 -0
  53. unrealon_core/models/typed_responses.py +210 -0
  54. unrealon_core/models/websocket/__init__.py +91 -0
  55. unrealon_core/models/websocket/base.py +49 -0
  56. unrealon_core/models/websocket/config.py +200 -0
  57. unrealon_core/models/websocket/driver.py +215 -0
  58. unrealon_core/models/websocket/errors.py +138 -0
  59. unrealon_core/models/websocket/heartbeat.py +100 -0
  60. unrealon_core/models/websocket/logging.py +261 -0
  61. unrealon_core/models/websocket/proxy.py +496 -0
  62. unrealon_core/models/websocket/tasks.py +275 -0
  63. unrealon_core/models/websocket/utils.py +153 -0
  64. unrealon_core/models/websocket_session.py +144 -0
  65. unrealon_core/monitoring/__init__.py +43 -0
  66. unrealon_core/monitoring/alerts.py +398 -0
  67. unrealon_core/monitoring/dashboard.py +307 -0
  68. unrealon_core/monitoring/health_check.py +354 -0
  69. unrealon_core/monitoring/metrics.py +352 -0
  70. unrealon_core/utils/__init__.py +11 -0
  71. unrealon_core/utils/time.py +61 -0
  72. unrealon_core/version.py +219 -0
  73. unrealon_driver/__init__.py +90 -51
  74. unrealon_driver/core_module/__init__.py +34 -0
  75. unrealon_driver/core_module/base.py +184 -0
  76. unrealon_driver/core_module/config.py +30 -0
  77. unrealon_driver/core_module/event_manager.py +127 -0
  78. unrealon_driver/core_module/protocols.py +98 -0
  79. unrealon_driver/core_module/registry.py +146 -0
  80. unrealon_driver/decorators/__init__.py +15 -0
  81. unrealon_driver/decorators/retry.py +117 -0
  82. unrealon_driver/decorators/schedule.py +137 -0
  83. unrealon_driver/decorators/task.py +61 -0
  84. unrealon_driver/decorators/timing.py +132 -0
  85. unrealon_driver/driver/__init__.py +20 -0
  86. unrealon_driver/driver/communication/__init__.py +10 -0
  87. unrealon_driver/driver/communication/session.py +203 -0
  88. unrealon_driver/driver/communication/websocket_client.py +205 -0
  89. unrealon_driver/driver/core/__init__.py +10 -0
  90. unrealon_driver/driver/core/config.py +175 -0
  91. unrealon_driver/driver/core/driver.py +221 -0
  92. unrealon_driver/driver/factory/__init__.py +9 -0
  93. unrealon_driver/driver/factory/manager_factory.py +130 -0
  94. unrealon_driver/driver/lifecycle/__init__.py +11 -0
  95. unrealon_driver/driver/lifecycle/daemon.py +76 -0
  96. unrealon_driver/driver/lifecycle/initialization.py +97 -0
  97. unrealon_driver/driver/lifecycle/shutdown.py +48 -0
  98. unrealon_driver/driver/monitoring/__init__.py +9 -0
  99. unrealon_driver/driver/monitoring/health.py +63 -0
  100. unrealon_driver/driver/utilities/__init__.py +10 -0
  101. unrealon_driver/driver/utilities/logging.py +51 -0
  102. unrealon_driver/driver/utilities/serialization.py +61 -0
  103. unrealon_driver/managers/__init__.py +32 -0
  104. unrealon_driver/managers/base.py +174 -0
  105. unrealon_driver/managers/browser.py +98 -0
  106. unrealon_driver/managers/cache.py +116 -0
  107. unrealon_driver/managers/http.py +107 -0
  108. unrealon_driver/managers/logger.py +286 -0
  109. unrealon_driver/managers/proxy.py +99 -0
  110. unrealon_driver/managers/registry.py +87 -0
  111. unrealon_driver/managers/threading.py +54 -0
  112. unrealon_driver/managers/update.py +107 -0
  113. unrealon_driver/utils/__init__.py +9 -0
  114. unrealon_driver/utils/time.py +10 -0
  115. unrealon-1.1.6.dist-info/METADATA +0 -625
  116. unrealon-1.1.6.dist-info/RECORD +0 -55
  117. unrealon-1.1.6.dist-info/entry_points.txt +0 -9
  118. unrealon_browser/managers/stealth.py +0 -388
  119. unrealon_driver/README.md +0 -0
  120. unrealon_driver/exceptions.py +0 -33
  121. unrealon_driver/html_analyzer/__init__.py +0 -32
  122. unrealon_driver/html_analyzer/cleaner.py +0 -657
  123. unrealon_driver/html_analyzer/config.py +0 -64
  124. unrealon_driver/html_analyzer/manager.py +0 -247
  125. unrealon_driver/html_analyzer/models.py +0 -115
  126. unrealon_driver/html_analyzer/websocket_analyzer.py +0 -157
  127. unrealon_driver/models/__init__.py +0 -31
  128. unrealon_driver/models/websocket.py +0 -98
  129. unrealon_driver/parser/__init__.py +0 -36
  130. unrealon_driver/parser/cli_manager.py +0 -142
  131. unrealon_driver/parser/daemon_manager.py +0 -403
  132. unrealon_driver/parser/managers/__init__.py +0 -25
  133. unrealon_driver/parser/managers/config.py +0 -293
  134. unrealon_driver/parser/managers/error.py +0 -412
  135. unrealon_driver/parser/managers/result.py +0 -321
  136. unrealon_driver/parser/parser_manager.py +0 -458
  137. unrealon_driver/smart_logging/__init__.py +0 -24
  138. unrealon_driver/smart_logging/models.py +0 -44
  139. unrealon_driver/smart_logging/smart_logger.py +0 -406
  140. unrealon_driver/smart_logging/unified_logger.py +0 -525
  141. unrealon_driver/websocket/__init__.py +0 -31
  142. unrealon_driver/websocket/client.py +0 -249
  143. unrealon_driver/websocket/config.py +0 -188
  144. unrealon_driver/websocket/manager.py +0 -90
@@ -0,0 +1,172 @@
1
+ """
2
+ UnrealOn Core Package
3
+
4
+ Core models, enums, and exceptions for the UnrealOn RPC system.
5
+ This package provides the foundational data structures and utilities
6
+ used across all UnrealOn components.
7
+
8
+ Phase 1: Bedrock Foundation
9
+ - Base Pydantic models with strict validation
10
+ - Core enums and constants
11
+ - Custom exceptions hierarchy
12
+ - 100% test coverage required
13
+ """
14
+
15
+ # Import unified version system
16
+ from unrealon_core.version import get_rpc_version, get_version_info
17
+
18
+ __version__ = get_rpc_version()
19
+ __author__ = "UnrealOn Team"
20
+
21
+ # Import main components for easy access
22
+ from .models.base import UnrealOnBaseModel, TimestampedModel, IdentifiedModel, StatusModel
23
+ from .models.arq_context import (
24
+ ARQWorkerContext, ARQWorkerStats, TaskAssignmentParams, TaskResultParams,
25
+ LogEntryParams, DriverRegistrationParams, HeartbeatParams
26
+ )
27
+ from .models.arq_responses import (
28
+ TaskAssignmentResponse, TaskResultResponse, LogEntryResponse,
29
+ DriverRegistrationResponse, HeartbeatResponse, PingResponse
30
+ )
31
+ from .models.typed_responses import (
32
+ HealthCheckResult, StatusInfo, SessionInfo, ProxyStats,
33
+ ThreadStats, CacheStats, BatchStats
34
+ )
35
+ from .models.communication import (
36
+ MessageType as WebSocketMessageType, WebSocketMessage,
37
+ DriverRegistrationMessage, RegistrationResponseMessage,
38
+ TaskAssignmentMessage, TaskResultMessage,
39
+ LogEntryMessage, LogBatchMessage,
40
+ HeartbeatMessage, ConfigurationUpdateMessage,
41
+ ErrorMessage, AckMessage,
42
+ create_error_message, create_ack_message,
43
+ # Data models for strict typing
44
+ TaskAssignmentData, TaskResultData,
45
+ DriverRegistrationData, HeartbeatData, LogEntryData, LogContext
46
+ )
47
+ from .enums.status import DriverStatus, TaskStatus, ProxyStatus, LogLevel
48
+ from .enums.types import MessageType, ProxyType, TaskPriority
49
+ from .exceptions.base import UnrealOnError
50
+ from .exceptions.validation import ValidationError as UnrealOnValidationError
51
+ from .exceptions.communication import CommunicationError
52
+
53
+ # Error handling system
54
+ from .error_handling import (
55
+ RetryConfig, RetryStrategy, RetryResult,
56
+ ExponentialBackoff, LinearBackoff, FixedBackoff,
57
+ retry_async, retry_sync,
58
+ CircuitBreakerConfig, CircuitBreakerState,
59
+ CircuitBreaker, circuit_breaker,
60
+ ErrorContext, ErrorSeverity,
61
+ create_error_context, format_error_context,
62
+ RecoveryStrategy, RecoveryAction,
63
+ AutoRecovery, recovery_handler
64
+ )
65
+
66
+ # Monitoring system
67
+ from .monitoring import (
68
+ HealthStatus, HealthCheckResult, ComponentHealth,
69
+ HealthChecker, health_check_decorator,
70
+ MetricType, MetricValue, Metric,
71
+ MetricsCollector, counter, gauge, histogram, timer,
72
+ AlertSeverity, AlertRule, Alert,
73
+ AlertManager, alert_on_condition,
74
+ DashboardData, SystemStatus,
75
+ MonitoringDashboard, get_system_overview
76
+ )
77
+
78
+ # Configuration system
79
+ from .config.environment import (
80
+ EnvironmentConfig, Environment,
81
+ get_environment_config, set_environment_config
82
+ )
83
+ from .config.urls import (
84
+ URLConfig,
85
+ get_url_config
86
+ )
87
+ from .models.websocket.config import (
88
+ DriverConfiguration,
89
+ LoggingConfiguration,
90
+ TaskConfiguration,
91
+ ProxyConfiguration
92
+ )
93
+
94
+ __all__ = [
95
+ # Version info
96
+ "__version__",
97
+ "__author__",
98
+ "__phase__",
99
+
100
+ # Base models
101
+ "UnrealOnBaseModel",
102
+ "TimestampedModel",
103
+ "IdentifiedModel",
104
+ "StatusModel",
105
+
106
+ # WebSocket Communication models
107
+ "WebSocketMessageType",
108
+ "WebSocketMessage",
109
+ "DriverRegistrationMessage",
110
+ "RegistrationResponseMessage",
111
+ "TaskAssignmentMessage",
112
+ "TaskResultMessage",
113
+ "LogEntryMessage",
114
+ "LogBatchMessage",
115
+ "HeartbeatMessage",
116
+ "ConfigurationUpdateMessage",
117
+ "ErrorMessage",
118
+ "AckMessage",
119
+ "create_error_message",
120
+ "create_ack_message",
121
+
122
+ # Data models for strict typing
123
+ "TaskAssignmentData",
124
+ "TaskResultData",
125
+ "DriverRegistrationData",
126
+ "HeartbeatData",
127
+ "LogEntryData",
128
+ "LogContext",
129
+
130
+ # Status enums
131
+ "DriverStatus",
132
+ "TaskStatus",
133
+ "ProxyStatus",
134
+ "LogLevel",
135
+
136
+ # Type enums
137
+ "MessageType",
138
+ "ProxyType",
139
+ "TaskPriority",
140
+
141
+ # Exceptions
142
+ "UnrealOnError",
143
+ "UnrealOnValidationError",
144
+ "CommunicationError",
145
+
146
+ # Error handling system
147
+ "RetryConfig", "RetryStrategy", "RetryResult",
148
+ "ExponentialBackoff", "LinearBackoff", "FixedBackoff",
149
+ "retry_async", "retry_sync",
150
+ "CircuitBreakerConfig", "CircuitBreakerState",
151
+ "CircuitBreaker", "circuit_breaker",
152
+ "ErrorContext", "ErrorSeverity",
153
+ "create_error_context", "format_error_context",
154
+ "RecoveryStrategy", "RecoveryAction",
155
+ "AutoRecovery", "recovery_handler",
156
+
157
+ # Monitoring system
158
+ "HealthStatus", "HealthCheckResult", "ComponentHealth",
159
+ "HealthChecker", "health_check_decorator",
160
+ "MetricType", "MetricValue", "Metric",
161
+ "MetricsCollector", "counter", "gauge", "histogram", "timer",
162
+ "AlertSeverity", "AlertRule", "Alert",
163
+ "AlertManager", "alert_on_condition",
164
+ "DashboardData", "SystemStatus",
165
+ "MonitoringDashboard", "get_system_overview",
166
+
167
+ # Configuration system
168
+ "EnvironmentConfig", "Environment", "URLConfig",
169
+ "get_environment_config", "set_environment_config", "get_url_config",
170
+ "DriverConfiguration", "LoggingConfiguration",
171
+ "TaskConfiguration", "ProxyConfiguration",
172
+ ]
@@ -0,0 +1,16 @@
1
+ """
2
+ Configuration management for UnrealOn platform.
3
+
4
+ This module provides centralized configuration management with support for
5
+ development and production environments.
6
+ """
7
+
8
+ from .environment import EnvironmentConfig, get_environment_config
9
+ from .urls import URLConfig, get_url_config
10
+
11
+ __all__ = [
12
+ "EnvironmentConfig",
13
+ "URLConfig",
14
+ "get_environment_config",
15
+ "get_url_config",
16
+ ]
@@ -0,0 +1,151 @@
1
+ """
2
+ Environment configuration management.
3
+
4
+ Handles switching between development and production environments.
5
+ """
6
+
7
+ import os
8
+ from enum import Enum
9
+ from typing import Optional
10
+ from pydantic import BaseModel, Field, ConfigDict
11
+
12
+
13
+ class Environment(str, Enum):
14
+ """Environment types."""
15
+ DEVELOPMENT = "development"
16
+ PRODUCTION = "production"
17
+ TESTING = "testing"
18
+
19
+
20
+ class EnvironmentConfig(BaseModel):
21
+ """Environment configuration settings with all system URLs and settings."""
22
+
23
+ model_config = ConfigDict(
24
+ # Add any specific config here if needed
25
+ )
26
+
27
+ environment: Environment = Field(
28
+ default=Environment.DEVELOPMENT,
29
+ description="Current environment"
30
+ )
31
+
32
+ debug: bool = Field(
33
+ default=True,
34
+ description="Enable debug mode"
35
+ )
36
+
37
+ log_level: str = Field(
38
+ default="INFO",
39
+ description="Logging level"
40
+ )
41
+
42
+ # System URLs - environment-aware
43
+ redis_url: str = Field(
44
+ default_factory=lambda: os.getenv("REDIS_URL", "redis://localhost:6379/0"),
45
+ description="Redis connection URL"
46
+ )
47
+
48
+ max_workers: int = Field(
49
+ default_factory=lambda: int(os.getenv("MAX_WORKERS", "10")),
50
+ description="Maximum number of workers"
51
+ )
52
+
53
+ @classmethod
54
+ def from_env(cls) -> "EnvironmentConfig":
55
+ """Create config from environment variables."""
56
+ env_name = os.getenv("UNREALON_ENV", "development").lower()
57
+
58
+ # Map environment names
59
+ env_mapping = {
60
+ "dev": Environment.DEVELOPMENT,
61
+ "development": Environment.DEVELOPMENT,
62
+ "prod": Environment.PRODUCTION,
63
+ "production": Environment.PRODUCTION,
64
+ "test": Environment.TESTING,
65
+ "testing": Environment.TESTING,
66
+ }
67
+
68
+ environment = env_mapping.get(env_name, Environment.DEVELOPMENT)
69
+
70
+ return cls(
71
+ environment=environment,
72
+ debug=environment != Environment.PRODUCTION,
73
+ log_level=os.getenv("UNREALON_LOG_LEVEL", "DEBUG" if environment != Environment.PRODUCTION else "INFO")
74
+ )
75
+
76
+ @property
77
+ def is_development(self) -> bool:
78
+ """Check if running in development mode."""
79
+ return self.environment == Environment.DEVELOPMENT
80
+
81
+ @property
82
+ def is_production(self) -> bool:
83
+ """Check if running in production mode."""
84
+ return self.environment == Environment.PRODUCTION
85
+
86
+ @property
87
+ def is_testing(self) -> bool:
88
+ """Check if running in testing mode."""
89
+ return self.environment == Environment.TESTING
90
+
91
+ @property
92
+ def websocket_url(self) -> str:
93
+ """Get WebSocket URL based on environment."""
94
+ # Check explicit env var first
95
+ if ws_url := os.getenv("WEBSOCKET_URL"):
96
+ return ws_url
97
+
98
+ if self.is_production:
99
+ return "wss://ws.unrealon.com/ws"
100
+ elif self.is_development:
101
+ return "ws://localhost:8001/ws" # RPC server port
102
+ else: # testing
103
+ return "ws://localhost:8001/ws"
104
+
105
+ @property
106
+ def api_url(self) -> str:
107
+ """Get API URL based on environment."""
108
+ # Check explicit env var first
109
+ if api_url := os.getenv("API_URL"):
110
+ return api_url
111
+
112
+ if self.is_production:
113
+ return "https://api-m.unrealon.com"
114
+ elif self.is_development:
115
+ return "http://localhost:8002" # Backend server port
116
+ else: # testing
117
+ return "http://localhost:8002"
118
+
119
+ @property
120
+ def django_api_url(self) -> str:
121
+ """Get Django API URL based on environment."""
122
+ # Check explicit env var first
123
+ if api_url := os.getenv("DJANGO_API_URL"):
124
+ return api_url
125
+
126
+ if self.is_production:
127
+ return "https://api.unrealon.com"
128
+ elif self.is_development:
129
+ return "http://localhost:8000" # Django server port
130
+ else: # testing
131
+ return "http://localhost:8000"
132
+
133
+
134
+ # Global config instance
135
+ _environment_config: Optional[EnvironmentConfig] = None
136
+
137
+
138
+ def get_environment_config() -> EnvironmentConfig:
139
+ """Get the global environment configuration."""
140
+ global _environment_config
141
+
142
+ if _environment_config is None:
143
+ _environment_config = EnvironmentConfig.from_env()
144
+
145
+ return _environment_config
146
+
147
+
148
+ def set_environment_config(config: EnvironmentConfig) -> None:
149
+ """Set the global environment configuration."""
150
+ global _environment_config
151
+ _environment_config = config
@@ -0,0 +1,94 @@
1
+ """
2
+ URL configuration management.
3
+
4
+ Provides centralized URL management with environment-specific endpoints.
5
+ """
6
+
7
+ from typing import Optional
8
+ from pydantic import BaseModel, Field, HttpUrl, ConfigDict
9
+ from .environment import get_environment_config, Environment
10
+
11
+
12
+ class URLConfig(BaseModel):
13
+ """URL configuration for different services."""
14
+
15
+ model_config = ConfigDict(
16
+ # Add any specific config here if needed
17
+ )
18
+
19
+ # Scanner/Detection URLs
20
+ scanner_url: str = Field(
21
+ default="https://cloud.unrealon.com/scanner",
22
+ description="URL for browser detection and stealth testing"
23
+ )
24
+
25
+ # Cloud platform URLs
26
+ cloud_base_url: str = Field(
27
+ description="Base URL for UnrealOn Cloud platform"
28
+ )
29
+
30
+ # API endpoints
31
+ api_base_url: str = Field(
32
+ description="Base URL for API endpoints"
33
+ )
34
+
35
+ @classmethod
36
+ def for_environment(cls, environment: Optional[Environment] = None) -> "URLConfig":
37
+ """Create URL config for specific environment."""
38
+ if environment is None:
39
+ environment = get_environment_config().environment
40
+
41
+ if environment == Environment.PRODUCTION:
42
+ return cls(
43
+ # scanner_url="https://cloud.unrealon.com/scanner",
44
+ cloud_base_url="https://cloud.unrealon.com",
45
+ api_base_url="https://api.unrealon.com"
46
+ )
47
+ # elif environment == Environment.TESTING:
48
+ # return cls(
49
+ # scanner_url="https://staging.unrealon.com/scanner",
50
+ # cloud_base_url="https://staging.unrealon.com",
51
+ # api_base_url="https://api-staging.unrealon.com"
52
+ # )
53
+ else: # Development
54
+ return cls(
55
+ # scanner_url="http://localhost:3000/scanner",
56
+ cloud_base_url="http://localhost:3000",
57
+ api_base_url="http://localhost:8000"
58
+ )
59
+
60
+ @property
61
+ def stealth_test_url(self) -> str:
62
+ """Get the URL for stealth testing (replaces bot.sannysoft.com)."""
63
+ return self.scanner_url
64
+
65
+ @property
66
+ def detection_test_url(self) -> str:
67
+ """Get the URL for browser detection testing."""
68
+ return self.scanner_url
69
+
70
+
71
+ # Global config instance
72
+ _url_config: Optional[URLConfig] = None
73
+
74
+
75
+ def get_url_config() -> URLConfig:
76
+ """Get the global URL configuration."""
77
+ global _url_config
78
+
79
+ if _url_config is None:
80
+ _url_config = URLConfig.for_environment()
81
+
82
+ return _url_config
83
+
84
+
85
+ def set_url_config(config: URLConfig) -> None:
86
+ """Set the global URL configuration."""
87
+ global _url_config
88
+ _url_config = config
89
+
90
+
91
+ def reset_url_config() -> None:
92
+ """Reset URL config to reload from environment."""
93
+ global _url_config
94
+ _url_config = None
@@ -0,0 +1,24 @@
1
+ """
2
+ UnrealOn Core Enums
3
+
4
+ All enums and constants used across the UnrealOn system.
5
+ These provide type safety and consistent values throughout the codebase.
6
+
7
+ Phase 1: Foundation enums with strict validation
8
+ """
9
+
10
+ from .status import DriverStatus, TaskStatus, ProxyStatus, LogLevel
11
+ from .types import MessageType, ProxyType, TaskPriority
12
+
13
+ __all__ = [
14
+ # Status enums
15
+ "DriverStatus",
16
+ "TaskStatus",
17
+ "ProxyStatus",
18
+ "LogLevel",
19
+
20
+ # Type enums
21
+ "MessageType",
22
+ "ProxyType",
23
+ "TaskPriority",
24
+ ]
@@ -0,0 +1,216 @@
1
+ """
2
+ Status enums for UnrealOn system.
3
+
4
+ These enums define all possible status values for different
5
+ components in the system. Using enums ensures type safety
6
+ and prevents invalid status values.
7
+
8
+ Phase 1: Foundation status enums
9
+ """
10
+
11
+ from enum import Enum
12
+
13
+
14
+ class DriverStatus(str, Enum):
15
+ """
16
+ Driver connection and operational status.
17
+
18
+ Used to track the current state of driver connections
19
+ and their ability to process tasks.
20
+ """
21
+
22
+ # Connection states
23
+ DISCONNECTED = "disconnected" # Driver is not connected
24
+ CONNECTING = "connecting" # Driver is attempting to connect
25
+ CONNECTED = "connected" # Driver is connected and idle
26
+
27
+ # Operational states
28
+ BUSY = "busy" # Driver is processing a task
29
+ READY = "ready" # Driver is ready to receive tasks
30
+
31
+ # Error states
32
+ ERROR = "error" # Driver encountered an error
33
+ TIMEOUT = "timeout" # Driver connection timed out
34
+
35
+ # Maintenance states
36
+ MAINTENANCE = "maintenance" # Driver is in maintenance mode
37
+ SHUTDOWN = "shutdown" # Driver is shutting down
38
+
39
+ def is_connected(self) -> bool:
40
+ """Check if driver is in a connected state."""
41
+ return self in [
42
+ DriverStatus.CONNECTED,
43
+ DriverStatus.BUSY,
44
+ DriverStatus.READY
45
+ ]
46
+
47
+ def is_available(self) -> bool:
48
+ """Check if driver is available for new tasks."""
49
+ return self in [
50
+ DriverStatus.CONNECTED,
51
+ DriverStatus.READY
52
+ ]
53
+
54
+ def is_error_state(self) -> bool:
55
+ """Check if driver is in an error state."""
56
+ return self in [
57
+ DriverStatus.ERROR,
58
+ DriverStatus.TIMEOUT
59
+ ]
60
+
61
+
62
+ class TaskStatus(str, Enum):
63
+ """
64
+ Task execution status throughout its lifecycle.
65
+
66
+ Tracks a task from creation through completion,
67
+ including error and retry states.
68
+ """
69
+
70
+ # Initial states
71
+ CREATED = "created" # Task created but not queued
72
+ PENDING = "pending" # Task queued, waiting for assignment
73
+ ASSIGNED = "assigned" # Task assigned to a driver
74
+
75
+ # Execution states
76
+ RUNNING = "running" # Task is being executed
77
+ PAUSED = "paused" # Task execution paused
78
+
79
+ # Completion states
80
+ COMPLETED = "completed" # Task completed successfully
81
+ FAILED = "failed" # Task failed permanently
82
+ CANCELLED = "cancelled" # Task was cancelled
83
+
84
+ # Retry states
85
+ RETRYING = "retrying" # Task is being retried
86
+ RETRY_FAILED = "retry_failed" # All retries exhausted
87
+
88
+ # Timeout states
89
+ TIMEOUT = "timeout" # Task execution timed out
90
+
91
+ def is_active(self) -> bool:
92
+ """Check if task is actively being processed."""
93
+ return self in [
94
+ TaskStatus.ASSIGNED,
95
+ TaskStatus.RUNNING,
96
+ TaskStatus.RETRYING
97
+ ]
98
+
99
+ def is_completed(self) -> bool:
100
+ """Check if task has reached a final state."""
101
+ return self in [
102
+ TaskStatus.COMPLETED,
103
+ TaskStatus.FAILED,
104
+ TaskStatus.CANCELLED,
105
+ TaskStatus.RETRY_FAILED,
106
+ TaskStatus.TIMEOUT
107
+ ]
108
+
109
+ def is_successful(self) -> bool:
110
+ """Check if task completed successfully."""
111
+ return self == TaskStatus.COMPLETED
112
+
113
+ def can_retry(self) -> bool:
114
+ """Check if task can be retried."""
115
+ return self in [
116
+ TaskStatus.FAILED,
117
+ TaskStatus.TIMEOUT
118
+ ]
119
+
120
+
121
+ class ProxyStatus(str, Enum):
122
+ """
123
+ Proxy server health and availability status.
124
+
125
+ Used to track proxy server health and determine
126
+ which proxies should be used for requests.
127
+ """
128
+
129
+ # Operational states
130
+ ACTIVE = "active" # Proxy is healthy and available
131
+ INACTIVE = "inactive" # Proxy is temporarily unavailable
132
+
133
+ # Health states
134
+ HEALTHY = "healthy" # Proxy is responding normally
135
+ DEGRADED = "degraded" # Proxy is slow but functional
136
+
137
+ # Error states
138
+ BANNED = "banned" # Proxy is banned/blocked
139
+ TIMEOUT = "timeout" # Proxy is not responding
140
+ ERROR = "error" # Proxy returned errors
141
+
142
+ # Testing states
143
+ TESTING = "testing" # Proxy is being health-checked
144
+ UNKNOWN = "unknown" # Proxy status is unknown
145
+
146
+ def is_usable(self) -> bool:
147
+ """Check if proxy can be used for requests."""
148
+ return self in [
149
+ ProxyStatus.ACTIVE,
150
+ ProxyStatus.HEALTHY,
151
+ ProxyStatus.DEGRADED
152
+ ]
153
+
154
+ def is_healthy(self) -> bool:
155
+ """Check if proxy is in good health."""
156
+ return self in [
157
+ ProxyStatus.ACTIVE,
158
+ ProxyStatus.HEALTHY
159
+ ]
160
+
161
+ def needs_health_check(self) -> bool:
162
+ """Check if proxy needs a health check."""
163
+ return self in [
164
+ ProxyStatus.UNKNOWN,
165
+ ProxyStatus.TIMEOUT,
166
+ ProxyStatus.ERROR
167
+ ]
168
+
169
+
170
+ class LogLevel(str, Enum):
171
+ """
172
+ Logging levels for the UnrealOn system.
173
+
174
+ Standard logging levels with additional
175
+ system-specific levels for better categorization.
176
+ """
177
+
178
+ # Standard levels
179
+ DEBUG = "debug" # Detailed debugging information
180
+ INFO = "info" # General information
181
+ WARNING = "warning" # Warning messages
182
+ ERROR = "error" # Error messages
183
+ CRITICAL = "critical" # Critical system errors
184
+
185
+ # System-specific levels
186
+ TRACE = "trace" # Very detailed tracing
187
+ PERFORMANCE = "performance" # Performance-related logs
188
+ SECURITY = "security" # Security-related logs
189
+ AUDIT = "audit" # Audit trail logs
190
+
191
+ def get_numeric_level(self) -> int:
192
+ """Get numeric level for comparison."""
193
+ levels = {
194
+ LogLevel.TRACE: 5,
195
+ LogLevel.DEBUG: 10,
196
+ LogLevel.INFO: 20,
197
+ LogLevel.PERFORMANCE: 25,
198
+ LogLevel.WARNING: 30,
199
+ LogLevel.ERROR: 40,
200
+ LogLevel.SECURITY: 45,
201
+ LogLevel.CRITICAL: 50,
202
+ LogLevel.AUDIT: 60,
203
+ }
204
+ return levels.get(self, 20)
205
+
206
+ def is_at_least(self, other: 'LogLevel') -> bool:
207
+ """Check if this level is at least as severe as another."""
208
+ return self.get_numeric_level() >= other.get_numeric_level()
209
+
210
+ @classmethod
211
+ def from_string(cls, level_str: str) -> 'LogLevel':
212
+ """Create LogLevel from string, with fallback to INFO."""
213
+ try:
214
+ return cls(level_str.lower())
215
+ except ValueError:
216
+ return cls.INFO