wappa 0.1.9__py3-none-any.whl โ 0.1.10__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.
Potentially problematic release.
This version of wappa might be problematic. Click here for more details.
- wappa/__init__.py +4 -5
- wappa/api/controllers/webhook_controller.py +5 -2
- wappa/api/dependencies/__init__.py +0 -5
- wappa/api/middleware/error_handler.py +4 -4
- wappa/api/middleware/owner.py +11 -5
- wappa/api/routes/webhooks.py +2 -2
- wappa/cli/__init__.py +1 -1
- wappa/cli/examples/init/app/main.py +2 -1
- wappa/cli/examples/init/app/master_event.py +5 -3
- wappa/cli/examples/json_cache_example/app/__init__.py +1 -1
- wappa/cli/examples/json_cache_example/app/main.py +56 -44
- wappa/cli/examples/json_cache_example/app/master_event.py +181 -145
- wappa/cli/examples/json_cache_example/app/models/__init__.py +1 -1
- wappa/cli/examples/json_cache_example/app/models/json_demo_models.py +32 -51
- wappa/cli/examples/json_cache_example/app/scores/__init__.py +2 -2
- wappa/cli/examples/json_cache_example/app/scores/score_base.py +52 -46
- wappa/cli/examples/json_cache_example/app/scores/score_cache_statistics.py +70 -62
- wappa/cli/examples/json_cache_example/app/scores/score_message_history.py +41 -44
- wappa/cli/examples/json_cache_example/app/scores/score_state_commands.py +83 -71
- wappa/cli/examples/json_cache_example/app/scores/score_user_management.py +73 -57
- wappa/cli/examples/json_cache_example/app/utils/__init__.py +2 -2
- wappa/cli/examples/json_cache_example/app/utils/cache_utils.py +54 -56
- wappa/cli/examples/json_cache_example/app/utils/message_utils.py +85 -80
- wappa/cli/examples/openai_transcript/app/main.py +2 -1
- wappa/cli/examples/openai_transcript/app/master_event.py +31 -22
- wappa/cli/examples/openai_transcript/app/openai_utils/__init__.py +1 -1
- wappa/cli/examples/openai_transcript/app/openai_utils/audio_processing.py +37 -24
- wappa/cli/examples/redis_cache_example/app/__init__.py +1 -1
- wappa/cli/examples/redis_cache_example/app/main.py +56 -44
- wappa/cli/examples/redis_cache_example/app/master_event.py +181 -145
- wappa/cli/examples/redis_cache_example/app/models/redis_demo_models.py +31 -50
- wappa/cli/examples/redis_cache_example/app/scores/__init__.py +2 -2
- wappa/cli/examples/redis_cache_example/app/scores/score_base.py +52 -46
- wappa/cli/examples/redis_cache_example/app/scores/score_cache_statistics.py +70 -62
- wappa/cli/examples/redis_cache_example/app/scores/score_message_history.py +41 -44
- wappa/cli/examples/redis_cache_example/app/scores/score_state_commands.py +83 -71
- wappa/cli/examples/redis_cache_example/app/scores/score_user_management.py +73 -57
- wappa/cli/examples/redis_cache_example/app/utils/__init__.py +2 -2
- wappa/cli/examples/redis_cache_example/app/utils/cache_utils.py +54 -56
- wappa/cli/examples/redis_cache_example/app/utils/message_utils.py +85 -80
- wappa/cli/examples/simple_echo_example/app/__init__.py +1 -1
- wappa/cli/examples/simple_echo_example/app/main.py +41 -33
- wappa/cli/examples/simple_echo_example/app/master_event.py +78 -57
- wappa/cli/examples/wappa_full_example/app/__init__.py +1 -1
- wappa/cli/examples/wappa_full_example/app/handlers/__init__.py +1 -1
- wappa/cli/examples/wappa_full_example/app/handlers/command_handlers.py +134 -126
- wappa/cli/examples/wappa_full_example/app/handlers/message_handlers.py +237 -229
- wappa/cli/examples/wappa_full_example/app/handlers/state_handlers.py +170 -148
- wappa/cli/examples/wappa_full_example/app/main.py +51 -39
- wappa/cli/examples/wappa_full_example/app/master_event.py +179 -120
- wappa/cli/examples/wappa_full_example/app/models/__init__.py +1 -1
- wappa/cli/examples/wappa_full_example/app/models/state_models.py +113 -104
- wappa/cli/examples/wappa_full_example/app/models/user_models.py +92 -76
- wappa/cli/examples/wappa_full_example/app/models/webhook_metadata.py +109 -83
- wappa/cli/examples/wappa_full_example/app/utils/__init__.py +1 -1
- wappa/cli/examples/wappa_full_example/app/utils/cache_utils.py +132 -113
- wappa/cli/examples/wappa_full_example/app/utils/media_handler.py +175 -132
- wappa/cli/examples/wappa_full_example/app/utils/metadata_extractor.py +126 -87
- wappa/cli/main.py +9 -4
- wappa/core/__init__.py +18 -23
- wappa/core/config/settings.py +7 -5
- wappa/core/events/default_handlers.py +1 -1
- wappa/core/factory/wappa_builder.py +38 -25
- wappa/core/plugins/redis_plugin.py +1 -3
- wappa/core/plugins/wappa_core_plugin.py +7 -6
- wappa/core/types.py +12 -12
- wappa/core/wappa_app.py +10 -8
- wappa/database/__init__.py +3 -4
- wappa/domain/enums/messenger_platform.py +1 -2
- wappa/domain/factories/media_factory.py +5 -20
- wappa/domain/factories/message_factory.py +5 -20
- wappa/domain/factories/messenger_factory.py +2 -4
- wappa/domain/interfaces/cache_interface.py +7 -7
- wappa/domain/interfaces/media_interface.py +2 -5
- wappa/domain/models/media_result.py +1 -3
- wappa/domain/models/platforms/platform_config.py +1 -3
- wappa/messaging/__init__.py +9 -12
- wappa/messaging/whatsapp/handlers/whatsapp_media_handler.py +20 -22
- wappa/models/__init__.py +27 -35
- wappa/persistence/__init__.py +12 -15
- wappa/persistence/cache_factory.py +0 -1
- wappa/persistence/json/__init__.py +1 -1
- wappa/persistence/json/cache_adapters.py +37 -25
- wappa/persistence/json/handlers/state_handler.py +60 -52
- wappa/persistence/json/handlers/table_handler.py +51 -49
- wappa/persistence/json/handlers/user_handler.py +71 -55
- wappa/persistence/json/handlers/utils/file_manager.py +42 -39
- wappa/persistence/json/handlers/utils/key_factory.py +1 -1
- wappa/persistence/json/handlers/utils/serialization.py +13 -11
- wappa/persistence/json/json_cache_factory.py +4 -8
- wappa/persistence/json/storage_manager.py +66 -79
- wappa/persistence/memory/__init__.py +1 -1
- wappa/persistence/memory/cache_adapters.py +37 -25
- wappa/persistence/memory/handlers/state_handler.py +62 -52
- wappa/persistence/memory/handlers/table_handler.py +59 -53
- wappa/persistence/memory/handlers/user_handler.py +75 -55
- wappa/persistence/memory/handlers/utils/key_factory.py +1 -1
- wappa/persistence/memory/handlers/utils/memory_store.py +75 -71
- wappa/persistence/memory/handlers/utils/ttl_manager.py +59 -67
- wappa/persistence/memory/memory_cache_factory.py +3 -7
- wappa/persistence/memory/storage_manager.py +52 -62
- wappa/persistence/redis/cache_adapters.py +27 -21
- wappa/persistence/redis/ops.py +11 -11
- wappa/persistence/redis/redis_client.py +4 -6
- wappa/persistence/redis/redis_manager.py +12 -4
- wappa/processors/factory.py +5 -5
- wappa/schemas/factory.py +2 -5
- wappa/schemas/whatsapp/message_types/errors.py +3 -12
- wappa/schemas/whatsapp/validators.py +3 -3
- wappa/webhooks/__init__.py +17 -18
- wappa/webhooks/factory.py +3 -5
- wappa/webhooks/whatsapp/__init__.py +10 -13
- wappa/webhooks/whatsapp/message_types/audio.py +0 -4
- wappa/webhooks/whatsapp/message_types/document.py +1 -9
- wappa/webhooks/whatsapp/message_types/errors.py +3 -12
- wappa/webhooks/whatsapp/message_types/location.py +1 -21
- wappa/webhooks/whatsapp/message_types/sticker.py +1 -5
- wappa/webhooks/whatsapp/message_types/text.py +0 -6
- wappa/webhooks/whatsapp/message_types/video.py +1 -20
- wappa/webhooks/whatsapp/status_models.py +2 -2
- wappa/webhooks/whatsapp/validators.py +3 -3
- {wappa-0.1.9.dist-info โ wappa-0.1.10.dist-info}/METADATA +362 -8
- {wappa-0.1.9.dist-info โ wappa-0.1.10.dist-info}/RECORD +126 -126
- {wappa-0.1.9.dist-info โ wappa-0.1.10.dist-info}/WHEEL +0 -0
- {wappa-0.1.9.dist-info โ wappa-0.1.10.dist-info}/entry_points.txt +0 -0
- {wappa-0.1.9.dist-info โ wappa-0.1.10.dist-info}/licenses/LICENSE +0 -0
wappa/__init__.py
CHANGED
|
@@ -11,19 +11,18 @@ Clean Import Interface (SRP Compliance):
|
|
|
11
11
|
"""
|
|
12
12
|
|
|
13
13
|
# Framework Essentials Only (SRP: Framework Foundation)
|
|
14
|
-
from .core.wappa_app import Wappa
|
|
15
|
-
from .core.events.event_handler import WappaEventHandler
|
|
16
|
-
from .core.factory import WappaBuilder, WappaPlugin
|
|
17
|
-
|
|
18
14
|
# Dynamic version from pyproject.toml
|
|
19
15
|
from .core.config.settings import settings
|
|
16
|
+
from .core.events.event_handler import WappaEventHandler
|
|
17
|
+
from .core.factory import WappaBuilder, WappaPlugin
|
|
18
|
+
from .core.wappa_app import Wappa
|
|
20
19
|
|
|
21
20
|
__version__ = settings.version
|
|
22
21
|
|
|
23
22
|
__all__ = [
|
|
24
23
|
# Core Framework Components
|
|
25
24
|
"Wappa",
|
|
26
|
-
"WappaEventHandler",
|
|
25
|
+
"WappaEventHandler",
|
|
27
26
|
"WappaBuilder",
|
|
28
27
|
"WappaPlugin",
|
|
29
28
|
]
|
|
@@ -144,8 +144,9 @@ class WebhookController:
|
|
|
144
144
|
|
|
145
145
|
# ENHANCED DEBUGGING: Show context details
|
|
146
146
|
from wappa.core.logging.context import get_context_info
|
|
147
|
+
|
|
147
148
|
context_info = get_context_info()
|
|
148
|
-
|
|
149
|
+
|
|
149
150
|
self.logger.debug(
|
|
150
151
|
f"Processing webhook for platform: {platform}, owner: {owner_id}"
|
|
151
152
|
)
|
|
@@ -395,7 +396,9 @@ class WebhookController:
|
|
|
395
396
|
factory_class = create_cache_factory(cache_type)
|
|
396
397
|
cache_factory = factory_class(tenant_id=tenant_id, user_id=user_id)
|
|
397
398
|
|
|
398
|
-
self.logger.debug(
|
|
399
|
+
self.logger.debug(
|
|
400
|
+
f"โ
Created {cache_factory.__class__.__name__} successfully"
|
|
401
|
+
)
|
|
399
402
|
return cache_factory
|
|
400
403
|
|
|
401
404
|
except Exception as e:
|
|
@@ -5,11 +5,6 @@ Provides reusable dependencies for controllers, services, and middleware
|
|
|
5
5
|
following clean architecture patterns.
|
|
6
6
|
"""
|
|
7
7
|
|
|
8
|
-
from functools import lru_cache
|
|
9
|
-
from typing import Annotated
|
|
10
|
-
|
|
11
|
-
from fastapi import Depends, HTTPException, Request
|
|
12
|
-
|
|
13
8
|
# Import existing dependencies
|
|
14
9
|
from .whatsapp_dependencies import *
|
|
15
10
|
from .whatsapp_media_dependencies import *
|
|
@@ -40,11 +40,11 @@ class ErrorHandlerMiddleware(BaseHTTPMiddleware):
|
|
|
40
40
|
|
|
41
41
|
async def _log_http_exception(self, request: Request, exc: HTTPException) -> None:
|
|
42
42
|
"""Log HTTP exceptions with tenant context."""
|
|
43
|
-
|
|
43
|
+
getattr(request.state, "tenant_id", "unknown")
|
|
44
44
|
logger = get_logger(__name__)
|
|
45
45
|
|
|
46
46
|
# Extract user context from request if available
|
|
47
|
-
|
|
47
|
+
getattr(request.state, "user_id", "unknown")
|
|
48
48
|
|
|
49
49
|
logger.warning(
|
|
50
50
|
f"HTTP {exc.status_code} - {request.method} {request.url.path} - "
|
|
@@ -55,8 +55,8 @@ class ErrorHandlerMiddleware(BaseHTTPMiddleware):
|
|
|
55
55
|
self, request: Request, exc: Exception
|
|
56
56
|
) -> JSONResponse:
|
|
57
57
|
"""Handle unexpected exceptions with proper logging and response."""
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
getattr(request.state, "tenant_id", "unknown")
|
|
59
|
+
getattr(request.state, "user_id", "unknown")
|
|
60
60
|
|
|
61
61
|
# Get context-aware logger
|
|
62
62
|
logger = get_logger(__name__)
|
wappa/api/middleware/owner.py
CHANGED
|
@@ -32,14 +32,16 @@ class OwnerMiddleware(BaseHTTPMiddleware):
|
|
|
32
32
|
|
|
33
33
|
try:
|
|
34
34
|
# ENHANCED DEBUGGING: Log all request details
|
|
35
|
-
logger.debug(
|
|
36
|
-
|
|
35
|
+
logger.debug(
|
|
36
|
+
f"๐ OwnerMiddleware processing: {request.method} {request.url.path}"
|
|
37
|
+
)
|
|
38
|
+
|
|
37
39
|
# Extract owner_id from webhook URL pattern: /webhook/messenger/{owner_id}/{platform}
|
|
38
40
|
if request.url.path.startswith("/webhook/"):
|
|
39
41
|
logger.debug(f"๐ฏ Webhook request detected: {request.url.path}")
|
|
40
42
|
path_parts = request.url.path.strip("/").split("/")
|
|
41
43
|
logger.debug(f"๐ Path parts: {path_parts} (length: {len(path_parts)})")
|
|
42
|
-
|
|
44
|
+
|
|
43
45
|
if len(path_parts) >= 4:
|
|
44
46
|
# path_parts = ["webhook", "messenger", "owner_id", "platform"]
|
|
45
47
|
owner_id = path_parts[2]
|
|
@@ -49,14 +51,18 @@ class OwnerMiddleware(BaseHTTPMiddleware):
|
|
|
49
51
|
if self._is_valid_owner_id(owner_id):
|
|
50
52
|
# Set owner_id context from URL
|
|
51
53
|
set_request_context(owner_id=owner_id)
|
|
52
|
-
logger.debug(
|
|
54
|
+
logger.debug(
|
|
55
|
+
f"โ
Owner ID context set successfully: {owner_id}"
|
|
56
|
+
)
|
|
53
57
|
else:
|
|
54
58
|
logger.error(f"โ Invalid owner ID format: {owner_id}")
|
|
55
59
|
raise HTTPException(
|
|
56
60
|
status_code=400, detail=f"Invalid owner ID: {owner_id}"
|
|
57
61
|
)
|
|
58
62
|
else:
|
|
59
|
-
logger.warning(
|
|
63
|
+
logger.warning(
|
|
64
|
+
f"โ ๏ธ Webhook URL does not have enough parts: {path_parts}"
|
|
65
|
+
)
|
|
60
66
|
|
|
61
67
|
# For non-webhook endpoints, use default owner from settings
|
|
62
68
|
elif not self._is_public_endpoint(request.url.path):
|
wappa/api/routes/webhooks.py
CHANGED
|
@@ -161,10 +161,10 @@ def create_webhook_router(event_dispatcher: WappaEventDispatcher) -> APIRouter:
|
|
|
161
161
|
# Generate webhook URLs for this platform and tenant
|
|
162
162
|
try:
|
|
163
163
|
platform_type = PlatformType(platform.lower())
|
|
164
|
-
except ValueError:
|
|
164
|
+
except ValueError as e:
|
|
165
165
|
raise HTTPException(
|
|
166
166
|
status_code=400, detail=f"Unsupported platform: {platform}"
|
|
167
|
-
)
|
|
167
|
+
) from e
|
|
168
168
|
|
|
169
169
|
webhook_url = webhook_url_factory.generate_webhook_url(platform_type, tenant_id)
|
|
170
170
|
verify_url = webhook_url_factory.generate_webhook_url(
|
wappa/cli/__init__.py
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
from wappa import WappaEventHandler
|
|
2
2
|
from wappa.webhooks import IncomingMessageWebhook
|
|
3
3
|
|
|
4
|
+
|
|
4
5
|
class MasterEventHandler(WappaEventHandler):
|
|
5
|
-
|
|
6
6
|
async def process_message(self, webhook: IncomingMessageWebhook):
|
|
7
|
-
await self.messenger.mark_as_read(
|
|
8
|
-
|
|
7
|
+
await self.messenger.mark_as_read(
|
|
8
|
+
webhook.message.message_id, webhook.user.user_id
|
|
9
|
+
)
|
|
10
|
+
await self.messenger.send_text("Welcome to Wappa", webhook.user.user_id)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"""JSON Cache Example - SOLID Architecture Implementation"""
|
|
1
|
+
"""JSON Cache Example - SOLID Architecture Implementation"""
|
|
@@ -46,28 +46,28 @@ from .master_event import JSONCacheExampleHandler
|
|
|
46
46
|
def validate_configuration() -> bool:
|
|
47
47
|
"""
|
|
48
48
|
Validate required configuration settings.
|
|
49
|
-
|
|
49
|
+
|
|
50
50
|
Returns:
|
|
51
51
|
True if configuration is valid, False otherwise
|
|
52
52
|
"""
|
|
53
|
-
|
|
53
|
+
|
|
54
54
|
# Check required WhatsApp credentials
|
|
55
55
|
missing_configs = []
|
|
56
|
-
|
|
56
|
+
|
|
57
57
|
if not settings.wp_access_token:
|
|
58
58
|
missing_configs.append("WP_ACCESS_TOKEN")
|
|
59
|
-
|
|
59
|
+
|
|
60
60
|
if not settings.wp_phone_id:
|
|
61
61
|
missing_configs.append("WP_PHONE_ID")
|
|
62
|
-
|
|
62
|
+
|
|
63
63
|
if not settings.wp_bid:
|
|
64
64
|
missing_configs.append("WP_BID")
|
|
65
|
-
|
|
65
|
+
|
|
66
66
|
if missing_configs:
|
|
67
67
|
logger.error(f"โ Missing required configuration: {', '.join(missing_configs)}")
|
|
68
68
|
logger.error("๐ก Create a .env file with the required credentials")
|
|
69
69
|
return False
|
|
70
|
-
|
|
70
|
+
|
|
71
71
|
logger.info("โ
Configuration validation passed")
|
|
72
72
|
return True
|
|
73
73
|
|
|
@@ -75,14 +75,14 @@ def validate_configuration() -> bool:
|
|
|
75
75
|
def display_startup_information() -> None:
|
|
76
76
|
"""
|
|
77
77
|
Display startup information and demo features.
|
|
78
|
-
|
|
78
|
+
|
|
79
79
|
Shows configuration status, architecture overview,
|
|
80
80
|
and available demo features.
|
|
81
81
|
"""
|
|
82
82
|
print(f"๐ Wappa v{__version__} - JSON Cache Example (SOLID Architecture)")
|
|
83
83
|
print("=" * 80)
|
|
84
84
|
print()
|
|
85
|
-
|
|
85
|
+
|
|
86
86
|
print("๐๏ธ *SOLID ARCHITECTURE IMPLEMENTATION:*")
|
|
87
87
|
print(" โข Single Responsibility: Each score module has one specific concern")
|
|
88
88
|
print(" โข Open/Closed: New score modules can be added without modification")
|
|
@@ -90,22 +90,28 @@ def display_startup_information() -> None:
|
|
|
90
90
|
print(" โข Interface Segregation: Clean, focused interfaces for each concern")
|
|
91
91
|
print(" โข Dependency Inversion: Dependencies injected through abstractions")
|
|
92
92
|
print()
|
|
93
|
-
|
|
93
|
+
|
|
94
94
|
print("๐ *CONFIGURATION STATUS:*")
|
|
95
|
-
print(
|
|
96
|
-
|
|
95
|
+
print(
|
|
96
|
+
f" โข Access Token: {'โ
Configured' if settings.wp_access_token else 'โ Missing'}"
|
|
97
|
+
)
|
|
98
|
+
print(
|
|
99
|
+
f" โข Phone ID: {settings.wp_phone_id if settings.wp_phone_id else 'โ Missing'}"
|
|
100
|
+
)
|
|
97
101
|
print(f" โข Business ID: {'โ
Configured' if settings.wp_bid else 'โ Missing'}")
|
|
98
|
-
print(
|
|
99
|
-
print(
|
|
102
|
+
print(" โข JSON Cache: โ
No external dependencies required")
|
|
103
|
+
print(
|
|
104
|
+
f" โข Environment: {'๐ ๏ธ Development' if settings.is_development else '๐ Production'}"
|
|
105
|
+
)
|
|
100
106
|
print()
|
|
101
|
-
|
|
107
|
+
|
|
102
108
|
print("๐ฏ *SCORE MODULES (BUSINESS LOGIC):*")
|
|
103
109
|
print(" โข UserManagementScore: User profile and caching logic")
|
|
104
110
|
print(" โข MessageHistoryScore: Message logging and /HISTORY command")
|
|
105
|
-
print(" โข StateCommandsScore: /WAPPA and /EXIT command processing")
|
|
111
|
+
print(" โข StateCommandsScore: /WAPPA and /EXIT command processing")
|
|
106
112
|
print(" โข CacheStatisticsScore: Cache monitoring and /STATS command")
|
|
107
113
|
print()
|
|
108
|
-
|
|
114
|
+
|
|
109
115
|
print("๐งช *DEMO FEATURES:*")
|
|
110
116
|
print(" 1. Send any message โ User profile created/updated + message logged")
|
|
111
117
|
print(" 2. Send '/WAPPA' โ Enter special state with cache management")
|
|
@@ -114,15 +120,15 @@ def display_startup_information() -> None:
|
|
|
114
120
|
print(" 5. Send '/HISTORY' โ View your last 20 messages with timestamps")
|
|
115
121
|
print(" 6. Send '/STATS' โ View comprehensive cache statistics")
|
|
116
122
|
print()
|
|
117
|
-
|
|
123
|
+
|
|
118
124
|
print("๐ *JSON CACHE ARCHITECTURE:*")
|
|
119
125
|
print(" โข user_cache: User profiles stored in {project_root}/cache/users/")
|
|
120
|
-
print(" โข table_cache: Message history in {project_root}/cache/tables/")
|
|
126
|
+
print(" โข table_cache: Message history in {project_root}/cache/tables/")
|
|
121
127
|
print(" โข state_cache: Command state management in {project_root}/cache/states/")
|
|
122
128
|
print(" โข TTL Support: Metadata-based expiration with lazy cleanup")
|
|
123
129
|
print(" โข File Safety: Atomic write operations prevent corruption")
|
|
124
130
|
print()
|
|
125
|
-
|
|
131
|
+
|
|
126
132
|
print("๐ง *TECHNICAL FEATURES:*")
|
|
127
133
|
print(" โข File-based persistence with project root auto-detection")
|
|
128
134
|
print(" โข BaseModel JSON serialization with datetime handling")
|
|
@@ -139,22 +145,22 @@ def display_startup_information() -> None:
|
|
|
139
145
|
def create_wappa_application() -> Wappa:
|
|
140
146
|
"""
|
|
141
147
|
Create and configure the Wappa application.
|
|
142
|
-
|
|
148
|
+
|
|
143
149
|
This function follows Single Responsibility Principle by focusing
|
|
144
150
|
only on application creation and initial configuration.
|
|
145
|
-
|
|
151
|
+
|
|
146
152
|
Returns:
|
|
147
153
|
Configured Wappa application instance
|
|
148
154
|
"""
|
|
149
|
-
|
|
155
|
+
|
|
150
156
|
try:
|
|
151
157
|
# Create Wappa instance with JSON cache
|
|
152
158
|
logger.info("๐๏ธ Creating Wappa application with JSON cache...")
|
|
153
159
|
app = Wappa(cache="json")
|
|
154
|
-
|
|
160
|
+
|
|
155
161
|
logger.info("โ
Wappa application created successfully")
|
|
156
162
|
return app
|
|
157
|
-
|
|
163
|
+
|
|
158
164
|
except Exception as e:
|
|
159
165
|
logger.error(f"โ Failed to create Wappa application: {e}")
|
|
160
166
|
raise
|
|
@@ -163,51 +169,55 @@ def create_wappa_application() -> Wappa:
|
|
|
163
169
|
def main() -> None:
|
|
164
170
|
"""
|
|
165
171
|
Main application entry point.
|
|
166
|
-
|
|
172
|
+
|
|
167
173
|
Demonstrates SOLID principles in action:
|
|
168
174
|
- Single Responsibility: Each function has one clear purpose
|
|
169
175
|
- Dependency Inversion: Dependencies flow from abstractions
|
|
170
176
|
- Open/Closed: System is open for extension via score modules
|
|
171
177
|
"""
|
|
172
|
-
|
|
178
|
+
|
|
173
179
|
logger.info("๐ Starting JSON Cache Example with SOLID Architecture")
|
|
174
|
-
|
|
180
|
+
|
|
175
181
|
try:
|
|
176
182
|
# Display startup information
|
|
177
183
|
display_startup_information()
|
|
178
|
-
|
|
184
|
+
|
|
179
185
|
# Validate configuration before proceeding
|
|
180
186
|
if not validate_configuration():
|
|
181
|
-
logger.error(
|
|
187
|
+
logger.error(
|
|
188
|
+
"โ Configuration validation failed - cannot start application"
|
|
189
|
+
)
|
|
182
190
|
return
|
|
183
|
-
|
|
191
|
+
|
|
184
192
|
# Create Wappa application
|
|
185
193
|
app = create_wappa_application()
|
|
186
|
-
|
|
194
|
+
|
|
187
195
|
# Create and set the SOLID WappaEventHandler implementation
|
|
188
196
|
handler = JSONCacheExampleHandler()
|
|
189
197
|
app.set_event_handler(handler)
|
|
190
|
-
|
|
191
|
-
logger.info(
|
|
192
|
-
|
|
198
|
+
|
|
199
|
+
logger.info(
|
|
200
|
+
"โ
Application initialization completed with SOLID WappaEventHandler"
|
|
201
|
+
)
|
|
202
|
+
|
|
193
203
|
print("๐ Starting SOLID JSON cache demo server...")
|
|
194
204
|
print("๐ก Press CTRL+C to stop the server")
|
|
195
205
|
print("๐พ Cache files will be created in the project's cache/ directory")
|
|
196
206
|
print("=" * 80)
|
|
197
207
|
print()
|
|
198
|
-
|
|
208
|
+
|
|
199
209
|
# Start the application
|
|
200
210
|
# The framework will handle dependency injection automatically
|
|
201
211
|
app.run()
|
|
202
|
-
|
|
212
|
+
|
|
203
213
|
except KeyboardInterrupt:
|
|
204
214
|
logger.info("๐ Application stopped by user")
|
|
205
215
|
print("\n๐ JSON cache demo stopped by user")
|
|
206
|
-
|
|
216
|
+
|
|
207
217
|
except Exception as e:
|
|
208
218
|
logger.error(f"โ Application startup error: {e}", exc_info=True)
|
|
209
219
|
print(f"\nโ Server error: {e}")
|
|
210
|
-
|
|
220
|
+
|
|
211
221
|
finally:
|
|
212
222
|
logger.info("๐ JSON cache demo completed")
|
|
213
223
|
print("๐ JSON cache demo completed")
|
|
@@ -219,17 +229,19 @@ def main() -> None:
|
|
|
219
229
|
try:
|
|
220
230
|
logger.info("๐ฆ Creating module-level Wappa application instance")
|
|
221
231
|
app = Wappa(cache="json")
|
|
222
|
-
|
|
232
|
+
|
|
223
233
|
# Create and set the SOLID WappaEventHandler implementation
|
|
224
234
|
handler = JSONCacheExampleHandler()
|
|
225
235
|
app.set_event_handler(handler)
|
|
226
|
-
|
|
227
|
-
logger.info(
|
|
228
|
-
|
|
236
|
+
|
|
237
|
+
logger.info(
|
|
238
|
+
"โ
Module-level application instance ready with SOLID WappaEventHandler"
|
|
239
|
+
)
|
|
240
|
+
|
|
229
241
|
except Exception as e:
|
|
230
242
|
logger.error(f"โ Failed to create module-level app instance: {e}")
|
|
231
243
|
raise
|
|
232
244
|
|
|
233
245
|
|
|
234
246
|
if __name__ == "__main__":
|
|
235
|
-
main()
|
|
247
|
+
main()
|