Skip to content

Commit 532e2c7

Browse files
committed
create submodule for DI
1 parent 8a99f6b commit 532e2c7

File tree

5 files changed

+60
-23
lines changed

5 files changed

+60
-23
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "echonext_di"]
2+
path = echonext_di
3+
url = [email protected]:alexeev-prog/echonext_di.git

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
Welcome to **EchoNext**, where innovation meets simplicity! Are you tired of the sluggishness of traditional web frameworks? Want a solution that keeps pace with your ambitious apps? Look no further. EchoNext is your agile companion in the world of web development!
4141

4242
<p align="center">
43-
<img src="https://raw.githubusercontent.com/alexeev-prog/pyEchoNext/refs/heads/main/docs/logo.jpg" width='600px' height='600px'>
43+
<img src="https://raw.githubusercontent.com/alexeev-prog/pyEchoNext/refs/heads/main/docs/logo.jpg">
4444
</p>
4545

4646
**Imagine** a lightweight framework that empowers you to create modern web applications with lightning speed and flexibility. With EchoNext, you're not just coding; you're building a masterpiece!
@@ -85,7 +85,7 @@ Welcome to **EchoNext**, where innovation meets simplicity! Are you tired of the
8585
| Asynchronous Capabilities | COMING SOON || ✔️ || ✔️ |
8686
| Performance | 🔥 High | 🐢 Moderate | 🚀 Very High | 🐢 Moderate | 🚀 Very High |
8787
| Framework Weight | ✔️ | ✔️ | ✔️ | ❌ Heavy | ✔️ |
88-
| Ecosystem | 🛠️ Modular | 🎨 Flexible | 🎨 Modular | ⚙️ Monolithic | ⚙️ Modular |
88+
| Ecosystem | 🛠️ Flexible | 🎨 Flexible | 🎨 Modular | ⚙️ Monolithic | ⚙️ Modular |
8989
| Ease of Use | ✔️ | ✔️ | ✔️ || ✔️ |
9090
| Configurability | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
9191
| Documentation Quality | 📚 Excellent | 📚 Good | 📚 Excellent | 📚 Very Good | 📚 Good |
@@ -94,7 +94,7 @@ Welcome to **EchoNext**, where innovation meets simplicity! Are you tired of the
9494
| Community Size | 📢 Growing | 📢 Large | 📢 Growing | 📢 Large | 📢 Emerging |
9595
| Built-in Template Engine | ✔️ Jinja2 & builtin | ✔️ Jinja2 | ✔️ Jinja2 | ✔️ Django | ✔️ Jinja2 |
9696
| Task Queue Integration || ✔️ Celery | ✔️ Celery | ✔️ Celery | ✔️ Celery |
97-
| Static File Serving | 🌍 Manual | 🌍 Manual | 🚀 Built-in | 🚀 Built-in | 🚀 Built-in |
97+
| Static File Serving | 🚀 Built-in | 🌍 Manual | 🚀 Built-in | 🚀 Built-in | 🚀 Built-in |
9898
| Analytics Integration | ✔️ Easy | 🛠️ Manual | ✔️ Easy || ✔️ Easy |
9999

100100
📈 Note: Echonext excels in performance while staying lightweight, making it a top-notch choice for your next project!

echonext_di

Submodule echonext_di added at c88fc03

pyechonext/app.py

Lines changed: 53 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from pyechonext.logging import setup_logger
1515
from pyechonext.middleware import BaseMiddleware
1616
from pyechonext.mvc.controllers import PageController
17-
from pyechonext.mvc.routes import Router, RoutesTypes
17+
from pyechonext.mvc.routes import Router, RoutesTypes, Route
1818
from pyechonext.request import Request
1919
from pyechonext.response import Response
2020
from pyechonext.static import StaticFile, StaticFilesManager
@@ -305,15 +305,59 @@ def _serve_static_file(
305305
)
306306
return response
307307

308-
def _handle_request(self, request: Request) -> Response:
308+
def _check_handler(self, request: Request, handler: Callable) -> Callable:
309309
"""
310-
Handle response from request
310+
Check and return handler
311+
312+
:param request: The request
313+
:type request: Request
314+
:param handler: The handler
315+
:type handler: Callable
316+
317+
:returns: handler
318+
:rtype: Callable
319+
320+
:raises MethodNotAllow: request method not allowed
321+
"""
322+
if isinstance(handler, PageController) or inspect.isclass(handler):
323+
handler = getattr(handler, request.method.lower(), None)
311324

312-
:param request: The request
313-
:type request: Request
325+
if handler is None:
326+
raise MethodNotAllow(
327+
f'Method "{request.method.lower()}" don\'t allowed: {request.path}'
328+
)
314329

315-
:returns: Response callable object
316-
:rtype: Response
330+
return handler
331+
332+
def _filling_response(self, route: Route, response: Response, handler: Callable):
333+
"""
334+
Filling response
335+
336+
:param route: The route
337+
:type route: Route
338+
:param response: The response
339+
:type response: Response
340+
:param handler: The handler
341+
:type handler: Callable
342+
"""
343+
if route.route_type == RoutesTypes.URL_BASED:
344+
view = route.handler.get_rendered_view(request, result, self)
345+
response.body = view
346+
else:
347+
string = self.i18n_loader.get_string(result)
348+
response.body = self.get_and_save_cache_item(string, string)
349+
350+
def _handle_request(self, request: Request) -> Response:
351+
"""
352+
Handle response from request
353+
354+
:param request: The request
355+
:type request: Request
356+
357+
:returns: Response callable object
358+
:rtype: Response
359+
360+
:raises URLNotFound: 404 Error
317361
"""
318362
logger.debug(f"Handle request: {request.path}")
319363
response = self._get_response(request)
@@ -323,13 +367,7 @@ def _handle_request(self, request: Request) -> Response:
323367
handler = route.handler
324368

325369
if handler is not None:
326-
if isinstance(handler, PageController) or inspect.isclass(handler):
327-
handler = getattr(handler, request.method.lower(), None)
328-
329-
if handler is None:
330-
raise MethodNotAllow(
331-
f'Method "{request.method.lower()}" don\'t allowed: {request.path}'
332-
)
370+
handler = self._check_handler(request, handler)
333371

334372
result = handler(request, response, **kwargs)
335373

@@ -338,12 +376,7 @@ def _handle_request(self, request: Request) -> Response:
338376
elif result is None:
339377
return response
340378

341-
if route.route_type == RoutesTypes.URL_BASED:
342-
view = route.handler.get_rendered_view(request, result, self)
343-
response.body = view
344-
else:
345-
string = self.i18n_loader.get_string(result)
346-
response.body = self.get_and_save_cache_item(string, string)
379+
self._filling_response(route, response, handler)
347380
else:
348381
raise URLNotFound(f'URL "{request.path}" not found.')
349382

pyechonext/depends/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)