From 4c761ae37747628b500e22c3dc8bf06f452801fb Mon Sep 17 00:00:00 2001 From: Leonid Vinogradov Date: Sat, 10 Aug 2024 09:35:15 +0300 Subject: [PATCH] HH-225824 fix fastapi routing --- docs/arguments-validation.md | 7 +- docs/frontik-app.md | 7 +- docs/http-client.md | 13 +- docs/page-generation.md | 2 + docs/postprocessing.md | 2 + docs/routing.md | 37 +++-- examples/example_app/pages/__init__.py | 4 +- examples/example_app/pages/tpl.py | 4 +- frontik/app.py | 100 +++++------ frontik/balancing_client.py | 4 +- frontik/handler_asgi.py | 155 +++++++++--------- frontik/options.py | 1 + frontik/request_context.py | 6 +- frontik/routing.py | 73 +++++++-- .../pages/different_datacenter.py | 6 +- .../pages/no_available_backend.py | 6 +- .../balancer_app/pages/no_retry_error.py | 6 +- .../balancer_app/pages/no_retry_timeout.py | 6 +- .../balancer_app/pages/profile_with_retry.py | 6 +- .../pages/profile_without_retry.py | 6 +- .../balancer_app/pages/requests_count.py | 6 +- .../balancer_app/pages/retry_connect.py | 6 +- .../pages/retry_connect_timeout.py | 6 +- .../balancer_app/pages/retry_count_limit.py | 4 +- .../balancer_app/pages/retry_error.py | 6 +- .../pages/retry_non_idempotent_503.py | 6 +- .../balancer_app/pages/retry_on_timeout.py | 6 +- .../projects/balancer_app/pages/slow_start.py | 6 +- .../pages/speculative_no_retry.py | 6 +- .../balancer_app/pages/speculative_retry.py | 6 +- .../pages/no_retry_error.py | 4 +- .../pages/no_retry_timeout.py | 4 +- .../pages/profile_with_retry.py | 4 +- .../pages/profile_without_retry.py | 4 +- .../pages/retry_connect.py | 4 +- .../broken_balancer_app/pages/retry_error.py | 4 +- .../pages/retry_non_idempotent_503.py | 4 +- .../pages/retry_on_timeout.py | 4 +- .../pages/speculative_no_retry.py | 4 +- .../pages/speculative_retry.py | 4 +- .../pages/call_deregistration_stat.py | 4 +- .../pages/call_registration_stat.py | 4 +- .../pages/v1/agent/service/register.py | 8 +- .../pages/v1/kv/upstream/upstream.py | 8 +- .../projects/no_debug_app/pages/basic_auth.py | 4 +- .../pages/check_workers_count_down.py | 4 +- .../pages/jinja_no_environment.py | 4 +- .../projects/no_debug_app/pages/recursion.py | 4 +- tests/projects/no_debug_app/pages/simple.py | 4 +- .../re_app/pages/jinja_custom_environment.py | 4 +- .../re_app/pages/sentry_not_configured.py | 4 +- tests/projects/re_app/pages/simple.py | 6 +- tests/projects/test_app/pages/api/2/store.py | 8 +- tests/projects/test_app/pages/arguments.py | 4 +- .../test_app/pages/async_group/group.py | 6 +- .../pages/async_group/group_with_futures.py | 4 +- .../async_group/not_waited_failed_requests.py | 12 +- .../pages/async_group/not_waited_requests.py | 10 +- .../test_app/pages/broken_workflow.py | 4 +- tests/projects/test_app/pages/cdata.py | 6 +- tests/projects/test_app/pages/compose_doc.py | 6 +- tests/projects/test_app/pages/debug.py | 8 +- tests/projects/test_app/pages/error_yield.py | 6 +- .../test_app/pages/fail_fast/__init__.py | 10 +- .../pages/fail_fast/fail_fast_without_done.py | 6 +- .../test_app/pages/fail_fast/future.py | 4 +- .../pages/fail_fast/with_postprocessors.py | 6 +- tests/projects/test_app/pages/finish.py | 4 +- tests/projects/test_app/pages/finish_204.py | 4 +- .../pages/finish_with_postprocessors.py | 6 +- .../projects/test_app/pages/handler/delete.py | 8 +- tests/projects/test_app/pages/handler/head.py | 4 +- .../test_app/pages/handler/head_url.py | 4 +- tests/projects/test_app/pages/handler/json.py | 6 +- .../pages/handler/json_optional_args.py | 6 +- .../pages/http_client/custom_headers.py | 6 +- .../test_app/pages/http_client/fibonacci.py | 4 +- .../test_app/pages/http_client/future.py | 6 +- .../pages/http_client/long_page_request.py | 4 +- .../test_app/pages/http_client/parse_error.py | 6 +- .../pages/http_client/parse_response.py | 10 +- .../test_app/pages/http_client/post_simple.py | 6 +- .../test_app/pages/http_client/post_url.py | 6 +- .../test_app/pages/http_client/proxy_code.py | 4 +- .../test_app/pages/http_client/raise_error.py | 4 +- tests/projects/test_app/pages/http_error.py | 4 +- tests/projects/test_app/pages/include_xml.py | 4 +- tests/projects/test_app/pages/json_page.py | 6 +- tests/projects/test_app/pages/kafka.py | 6 +- tests/projects/test_app/pages/log.py | 4 +- .../test_app/pages/mandatory_headers.py | 4 +- .../test_app/pages/nested/nested/nested.py | 4 +- tests/projects/test_app/pages/postprocess.py | 4 +- .../test_app/pages/postprocess_xsl.py | 4 +- tests/projects/test_app/pages/proxy_code.py | 4 +- .../test_app/pages/request_context.py | 6 +- tests/projects/test_app/pages/simple_xml.py | 4 +- tests/projects/test_app/pages/statsd.py | 4 +- .../test_app/pages/test_exception_json.py | 4 +- .../test_app/pages/test_exception_text.py | 4 +- .../test_app/pages/validate_arguments.py | 8 +- .../test_app/pages/write_after_finish.py | 6 +- tests/projects/test_app/pages/write_error.py | 4 +- .../test_app/pages/xsl/apply_error.py | 4 +- .../test_app/pages/xsl/parse_error.py | 4 +- tests/projects/test_app/pages/xsl/simple.py | 4 +- .../test_app/pages/xsl/syntax_error.py | 4 +- tests/test_frontik_testing.py | 6 +- tests/test_sentry_integration.py | 8 +- tests/test_telemetry.py | 6 +- 110 files changed, 498 insertions(+), 427 deletions(-) diff --git a/docs/arguments-validation.md b/docs/arguments-validation.md index c418f0e15..cd0c80301 100644 --- a/docs/arguments-validation.md +++ b/docs/arguments-validation.md @@ -1,14 +1,13 @@ ## Argument validation -Use methods described in +For fastapi routing see fastapi docs - Query - https://fastapi.tiangolo.com/tutorial/query-params-str-validations/ - Body - https://fastapi.tiangolo.com/tutorial/body-fields/ - Body - https://fastapi.tiangolo.com/tutorial/body-nested-models/ +- Path - https://fastapi.tiangolo.com/tutorial/path-params/ -Unlike other params, path params don't work as https://fastapi.tiangolo.com/tutorial/path-params/ -because right now there is no way to set parametric url. Temporarily you can use regex router as a workaround. -We are going to migrate on fastapi native routing soon, so don't use very complicated regex +In legacy controllers, path params don't work as fastapi. You need to use regex router and then get params with `get_path_argument`: Path param example: diff --git a/docs/frontik-app.md b/docs/frontik-app.md index 5ec4e6406..47504a7a6 100644 --- a/docs/frontik-app.md +++ b/docs/frontik-app.md @@ -1,7 +1,7 @@ ## Frontik application structure Each Frontik instance serves one application, which is imported from a package specified in -`app` parameter (see [Running Frontik](/docs/running.md)). +`app_class` parameter (see [Running Frontik](/docs/running.md)). Frontik application is a set of files, organized in the following structure (where `app` is a root folder for an application): @@ -16,7 +16,7 @@ Frontik application is a set of files, organized in the following structure ``` Application root module may contain class with overrides frontik.app.FrontikApplication class, providing application -specific configs and url mappings, for example: +specific configs, for example: ``` from frontik.app import FrontikApplication @@ -25,9 +25,6 @@ from frontik.app import FrontikApplication class MyApplication(FrontikApplication): def application_config(self): return config - - def application_urls(self): - return config.urls ``` Application initialization is done in 2 steps: diff --git a/docs/http-client.md b/docs/http-client.md index 09465235b..2c24dd9d4 100644 --- a/docs/http-client.md +++ b/docs/http-client.md @@ -1,6 +1,17 @@ ## Making HTTP requests -Frontik's [PageHandler](/frontik/handler.py) contains several methods for making HTTP requests to backends: +Frontik uses [balancing client](https://github.com/hhru/balancing-http-client). You can get instance through special dependency: + +```python +from frontik.balancing_client import HttpClientT +from frontik.routing import router + +@router.post('/handler') +async def post_page(http_client: HttpClientT) -> None: + result = await http_client.post_url('http://backend', request.url.path, fail_fast=True) +``` + +In legacy controllers frontik's [PageHandler](/frontik/handler.py) contains several methods for making HTTP requests to backends: get_url, post_url, put_url, etc... Method parameters are: diff --git a/docs/page-generation.md b/docs/page-generation.md index af87849de..f104480aa 100644 --- a/docs/page-generation.md +++ b/docs/page-generation.md @@ -1,5 +1,7 @@ ## Page generation process +Deprecated, works only in routes with `cls=PageHandler`. Use fastapi dependencies/middleware in new code + ![Page generation scheme](/docs/page-generation.png) Typically page generation process is split into several steps: diff --git a/docs/postprocessing.md b/docs/postprocessing.md index 1f037cb16..56b0b66f0 100644 --- a/docs/postprocessing.md +++ b/docs/postprocessing.md @@ -1,5 +1,7 @@ ## Postprocessing +Deprecated, works only in routes with `cls=PageHandler`. Use fastapi dependencies in new code + Postprocessing is a mechanism for inserting and running hooks after finishing all page requests (see [Making HTTP requests](/docs/http-client.md)). diff --git a/docs/routing.md b/docs/routing.md index 084c9a822..78ec89c09 100644 --- a/docs/routing.md +++ b/docs/routing.md @@ -1,34 +1,45 @@ ## Routing in Frontik applications On application start, frontik import all modules from {app_module}.pages so that any controller should be located there. +We use fastapi routing, read [these docs](https://fastapi.tiangolo.com/reference/apirouter/?h=apirouter) for details. A small important difference - you must inherit `frontik.routing.FastAPIRouter` instead `fastapi.APIRouter`. And use `from frontik.routing import router`, if you need default router. + +example: -Controller example: ```python from frontik.routing import router + +@router.get("/users/me") +async def read_user_me(): + return {"username": "fakecurrentuser"} + +``` + +### Deprecated + +Page generation logic with (pre/post)processors and finish group from previous versions is temporarily supported. You need to add `cls=PageHandler` arg to route: + +```python +from frontik.routing import plain_router from frontik.handler import PageHandler -@router.get('/simple_page', cls=PageHandler) # or .post .put .delete .head + +@plain_router.get('/simple_page', cls=PageHandler) # or .post .put .delete .head async def get_page(): ... ``` -First argument path should be exact string for url matching. -If you need regex with path params use `from frontik.routing import regex_router` - -Argument `cls=PageHandler` is required for legacy compatibility, it defines which class will be used to create the handler object. -The handler object can be accessed via `request.state.handler` - -You can use 'dependencies' functions in router or method arguments, see https://fastapi.tiangolo.com/tutorial/dependencies/ and https://fastapi.tiangolo.com/tutorial/bigger-applications/#another-module-with-apirouter for details +If you need regex with path params use `from frontik.routing import regex_router`. The handler object can be accessed via `request.state.handler` +You can use fastapi dependencies functions in router, see https://fastapi.tiangolo.com/tutorial/dependencies/ and https://fastapi.tiangolo.com/tutorial/bigger-applications/#another-module-with-apirouter for details Example with dependencies: + ```python -from frontik.routing import router +from frontik.routing import plain_router from frontik.handler import PageHandler, get_current_handler from fastapi import Depends -@router.get('/simple_page', cls=PageHandler, dependencies=[Depends(my_foo)]) + +@plain_router.get('/simple_page', cls=PageHandler, dependencies=[Depends(my_foo)]) async def get_page(handler=get_current_handler()): ... ``` - -You can create your own router object by extending `frontik.routing.FrontikRouter` and `frontik.routing.FrontikRegexRouter` diff --git a/examples/example_app/pages/__init__.py b/examples/example_app/pages/__init__.py index 3dda6a8f3..71a003e1a 100644 --- a/examples/example_app/pages/__init__.py +++ b/examples/example_app/pages/__init__.py @@ -1,7 +1,7 @@ from frontik.handler import PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router -@router.get('/tpl', cls=PageHandler) +@plain_router.get('/tpl', cls=PageHandler) def get_page(handler: PageHandler = get_current_handler()) -> None: handler.json.put({'text': 'Hello, world!'}) diff --git a/examples/example_app/pages/tpl.py b/examples/example_app/pages/tpl.py index 93aca373b..b8821b001 100644 --- a/examples/example_app/pages/tpl.py +++ b/examples/example_app/pages/tpl.py @@ -1,10 +1,10 @@ from fastapi import Request from frontik.handler import PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router -@router.get('/tpl', cls=PageHandler) +@plain_router.get('/tpl', cls=PageHandler) def get_page(request: Request, handler: PageHandler = get_current_handler()) -> None: handler.set_template('main.html') # This template is located in the `templates` folder handler.json.put(handler.get_url(request.headers.get('host', ''), '/example')) diff --git a/frontik/app.py b/frontik/app.py index 4a7f50b47..4af8a1200 100644 --- a/frontik/app.py +++ b/frontik/app.py @@ -7,7 +7,7 @@ from collections.abc import Callable from ctypes import c_bool, c_int from threading import Lock -from typing import Awaitable, Optional, Union +from typing import Optional, Union from aiokafka import AIOKafkaProducer from fastapi import FastAPI, HTTPException @@ -19,55 +19,40 @@ import frontik.producers.json_producer import frontik.producers.xml_producer -from frontik import integrations, media_types, request_context +from frontik import integrations, media_types from frontik.debug import get_frontik_and_apps_versions from frontik.handler import PageHandler, get_current_handler -from frontik.handler_asgi import serve_request +from frontik.handler_asgi import serve_tornado_request from frontik.handler_return_values import ReturnedValueHandlers, get_default_returned_value_handlers from frontik.integrations.statsd import StatsDClient, StatsDClientStub, create_statsd_client from frontik.options import options from frontik.process import WorkerState -from frontik.routing import import_all_pages, method_not_allowed_router, not_found_router, regex_router, router +from frontik.routing import ( + import_all_pages, + method_not_allowed_router, + not_found_router, + plain_router, + regex_router, + router, + routers, +) from frontik.service_discovery import UpstreamManager -from frontik.util import check_request_id, generate_uniq_timestamp_request_id app_logger = logging.getLogger('app_logger') - - -class AsgiRouter: - async def __call__(self, scope, receive, send): - assert scope['type'] == 'http' - - if 'router' not in scope: - scope['router'] = self - - route = scope['route'] - scope['endpoint'] = route.endpoint - - await route.handle(scope, receive, send) +_server_tasks = set() class FrontikAsgiApp(FastAPI): def __init__(self) -> None: super().__init__() - self.router = AsgiRouter() # type: ignore - self.http_client = None - - -@router.get('/version', cls=PageHandler) -@regex_router.get('/version', cls=PageHandler) -async def get_version(handler: PageHandler = get_current_handler()) -> None: - handler.set_header('Content-Type', 'text/xml') - handler.finish( - etree.tostring(get_frontik_and_apps_versions(handler.application), encoding='utf-8', xml_declaration=True), - ) + self.router = router + self.http_client_factory = None + if options.openapi_enabled: + self.setup() -@router.get('/status', cls=PageHandler) -@regex_router.get('/status', cls=PageHandler) -async def get_status(handler: PageHandler = get_current_handler()) -> None: - handler.set_header('Content-Type', media_types.APPLICATION_JSON) - handler.finish(handler.application.get_current_status()) + for _router in routers: + self.include_router(_router) class FrontikApplication: @@ -113,30 +98,11 @@ def __init__(self, app_module_name: Optional[str] = None) -> None: self.asgi_app = FrontikAsgiApp() - def __call__(self, tornado_request: httputil.HTTPServerRequest) -> Optional[Awaitable[None]]: - # for making more asgi, reimplement tornado.http1connection._server_request_loop and ._read_message - request_id = tornado_request.headers.get('X-Request-Id') or generate_uniq_timestamp_request_id() - if options.validate_request_id: - check_request_id(request_id) - tornado_request.request_id = request_id # type: ignore - - async def _serve_tornado_request( - frontik_app: FrontikApplication, - _tornado_request: httputil.HTTPServerRequest, - asgi_app: FrontikAsgiApp, - ) -> None: - status, reason, headers, data = await serve_request(frontik_app, _tornado_request, asgi_app) - - assert _tornado_request.connection is not None - _tornado_request.connection.set_close_callback(None) # type: ignore - - start_line = httputil.ResponseStartLine('', status, reason) - future = _tornado_request.connection.write_headers(start_line, headers, data) - _tornado_request.connection.finish() - return await future - - with request_context.request_context(request_id): - return asyncio.create_task(_serve_tornado_request(self, tornado_request, self.asgi_app)) + def __call__(self, tornado_request: httputil.HTTPServerRequest) -> None: + # for make it more asgi, reimplement tornado.http1connection._server_request_loop and ._read_message + task = asyncio.create_task(serve_tornado_request(self, self.asgi_app, tornado_request)) + _server_tasks.add(task) + task.add_done_callback(_server_tasks.discard) def create_upstream_manager( self, @@ -188,6 +154,8 @@ async def init(self) -> None: kafka_producer=kafka_producer, ) self.http_client_factory = HttpClientFactory(self.app_name, self.http_client, request_balancer_builder) + self.asgi_app.http_client_factory = self.http_client_factory + if self.worker_state.single_worker_mode: self.worker_state.master_done.value = True @@ -226,3 +194,19 @@ def get_kafka_producer(self, producer_name: str) -> Optional[AIOKafkaProducer]: def log_request(self, tornado_handler: PageHandler) -> None: pass + + +@plain_router.get('/version', cls=PageHandler) +@regex_router.get('/version', cls=PageHandler) +async def get_version(handler: PageHandler = get_current_handler()) -> None: + handler.set_header('Content-Type', 'text/xml') + handler.finish( + etree.tostring(get_frontik_and_apps_versions(handler.application), encoding='utf-8', xml_declaration=True), + ) + + +@plain_router.get('/status', cls=PageHandler) +@regex_router.get('/status', cls=PageHandler) +async def get_status(handler: PageHandler = get_current_handler()) -> None: + handler.set_header('Content-Type', media_types.APPLICATION_JSON) + handler.finish(handler.application.get_current_status()) diff --git a/frontik/balancing_client.py b/frontik/balancing_client.py index 1cc66eeb7..1fcb0481d 100644 --- a/frontik/balancing_client.py +++ b/frontik/balancing_client.py @@ -28,7 +28,7 @@ def modify_http_client_request(request: Request, balanced_request: RequestBuilde ) timeout_checker.check(balanced_request) - if request['pass_debug']: + if request['debug_mode'].pass_debug: balanced_request.headers[DEBUG_HEADER_NAME] = 'true' # debug_timestamp is added to avoid caching of debug responses @@ -46,7 +46,7 @@ async def _get_http_client(request: Request) -> HttpClient: http_client = request['http_client_factory'].get_http_client( modify_http_request_hook=hook, - debug_enabled=request['debug_enabled'], + debug_enabled=request['debug_mode'].enabled, ) return http_client diff --git a/frontik/handler_asgi.py b/frontik/handler_asgi.py index 9e835be36..b147179d5 100644 --- a/frontik/handler_asgi.py +++ b/frontik/handler_asgi.py @@ -4,7 +4,6 @@ import logging from typing import TYPE_CHECKING, Any, Callable, Optional -from fastapi.routing import APIRoute from tornado import httputil from tornado.httputil import HTTPHeaders, HTTPServerRequest @@ -13,7 +12,9 @@ from frontik.handler import PageHandler, get_default_headers, log_request from frontik.handler_active_limit import request_limiter from frontik.json_builder import JsonBuilder +from frontik.options import options from frontik.routing import find_route, get_allowed_methods, method_not_allowed_router, not_found_router +from frontik.util import check_request_id, generate_uniq_timestamp_request_id if TYPE_CHECKING: from frontik.app import FrontikApplication, FrontikAsgiApp @@ -22,66 +23,86 @@ log = logging.getLogger('handler') -async def serve_request( +async def serve_tornado_request( frontik_app: FrontikApplication, - tornado_request: HTTPServerRequest, asgi_app: FrontikAsgiApp, -) -> tuple[int, str, HTTPHeaders, bytes]: - with request_limiter(frontik_app.statsd_client) as accepted: + tornado_request: httputil.HTTPServerRequest, +) -> None: + request_id = tornado_request.headers.get('X-Request-Id') or generate_uniq_timestamp_request_id() + if options.validate_request_id: + check_request_id(request_id) + tornado_request.request_id = request_id # type: ignore + + with request_context.request_context(request_id): log.info('requested url: %s', tornado_request.uri) - if not accepted: - log_request(tornado_request, http.client.SERVICE_UNAVAILABLE) - return make_not_accepted_response() - debug_mode = make_debug_mode(frontik_app, tornado_request) - if debug_mode.auth_failed(): - assert debug_mode.failed_auth_header is not None - log_request(tornado_request, http.client.UNAUTHORIZED) - return make_debug_auth_failed_response(debug_mode.failed_auth_header) + with request_limiter(frontik_app.statsd_client) as accepted: + if not accepted: + status, reason, headers, data = make_not_accepted_response() + else: + status, reason, headers, data = await process_request(frontik_app, asgi_app, tornado_request) - assert tornado_request.method is not None + log_request(tornado_request, status) - route, page_cls, path_params = find_route(tornado_request.path, tornado_request.method) - if route is None and tornado_request.method == 'HEAD': - route, page_cls, path_params = find_route(tornado_request.path, 'GET') + assert tornado_request.connection is not None + tornado_request.connection.set_close_callback(None) # type: ignore - data: bytes + start_line = httputil.ResponseStartLine('', status, reason) + future = tornado_request.connection.write_headers(start_line, headers, data) + tornado_request.connection.finish() + return await future - if route is None: - status, reason, headers, data = await make_not_found_response( - frontik_app, asgi_app, tornado_request, debug_mode - ) - else: - status, reason, headers, data = await execute_page( - frontik_app, asgi_app, tornado_request, route, page_cls, path_params, debug_mode - ) - if debug_mode.enabled: - debug_transform = DebugTransform(frontik_app, debug_mode) - status, headers, data = debug_transform.transform_chunk(tornado_request, status, headers, data) - reason = httputil.responses.get(status, 'Unknown') +async def process_request( + frontik_app: FrontikApplication, + asgi_app: FrontikAsgiApp, + tornado_request: HTTPServerRequest, +) -> tuple[int, str, HTTPHeaders, bytes]: + debug_mode = make_debug_mode(frontik_app, tornado_request) + if debug_mode.auth_failed(): + assert debug_mode.failed_auth_header is not None + return make_debug_auth_failed_response(debug_mode.failed_auth_header) - log_request(tornado_request, status) - return status, reason, headers, data + assert tornado_request.method is not None + assert tornado_request.protocol == 'http' + scope = find_route(tornado_request.path, tornado_request.method) + data: bytes -async def execute_page( - frontik_app: FrontikApplication, + if scope['route'] is None: + status, reason, headers, data = await make_not_found_response(frontik_app, tornado_request, debug_mode) + elif scope['page_cls'] is not None: + status, reason, headers, data = await execute_tornado_page(frontik_app, tornado_request, scope, debug_mode) + else: + status, reason, headers, data = await execute_asgi_page( + asgi_app, + tornado_request, + scope, + debug_mode, + ) + + if debug_mode.enabled: + debug_transform = DebugTransform(frontik_app, debug_mode) + status, headers, data = debug_transform.transform_chunk(tornado_request, status, headers, data) + reason = httputil.responses.get(status, 'Unknown') + + return status, reason, headers, data + + +async def execute_asgi_page( asgi_app: FrontikAsgiApp, tornado_request: HTTPServerRequest, - route: APIRoute, - page_cls: type[PageHandler] | None, - path_params: dict, + scope: dict, debug_mode: DebugMode, ) -> tuple[int, str, HTTPHeaders, bytes]: - request_context.set_handler_name(f'{route.endpoint.__module__}.{route.endpoint.__name__}') - - if page_cls is not None: - return await execute_tornado_page(frontik_app, tornado_request, route, page_cls, path_params, debug_mode) - + request_context.set_handler_name(scope['route']) result: dict = {'headers': get_default_headers()} scope, receive, send = convert_tornado_request_to_asgi( - frontik_app, tornado_request, route, path_params, debug_mode, result + asgi_app, + tornado_request, + scope, + debug_mode, + result, ) await asgi_app(scope, receive, send) @@ -103,7 +124,6 @@ async def execute_page( async def make_not_found_response( frontik_app: FrontikApplication, - asgi_app: FrontikAsgiApp, tornado_request: httputil.HTTPServerRequest, debug_mode: DebugMode, ) -> tuple[int, str, HTTPHeaders, bytes]: @@ -112,13 +132,14 @@ async def make_not_found_response( headers: Any if allowed_methods and len(method_not_allowed_router.routes) != 0: - status, _, headers, data = await execute_page( + status, _, headers, data = await execute_tornado_page( frontik_app, - asgi_app, tornado_request, - method_not_allowed_router.routes[0], # type: ignore - method_not_allowed_router._cls, - {'allowed_methods': allowed_methods}, + { + 'route': method_not_allowed_router.routes[0], + 'page_cls': method_not_allowed_router._cls, + 'path_params': {'allowed_methods': allowed_methods}, + }, debug_mode, ) elif allowed_methods: @@ -126,13 +147,10 @@ async def make_not_found_response( headers = {'Allow': ', '.join(allowed_methods)} data = b'' elif len(not_found_router.routes) != 0: - status, _, headers, data = await execute_page( + status, _, headers, data = await execute_tornado_page( frontik_app, - asgi_app, tornado_request, - not_found_router.routes[0], # type: ignore - not_found_router._cls, - {}, + {'route': not_found_router.routes[0], 'page_cls': not_found_router._cls, 'path_params': {}}, debug_mode, ) else: @@ -185,20 +203,19 @@ def build_error_data( async def execute_tornado_page( frontik_app: FrontikApplication, tornado_request: httputil.HTTPServerRequest, - route: APIRoute, - page_cls: type[PageHandler], - path_params: dict[str, str], + scope: dict, debug_mode: DebugMode, ) -> tuple[int, str, HTTPHeaders, bytes]: + route, page_cls, path_params = scope['route'], scope['page_cls'], scope['path_params'] + request_context.set_handler_name(route) handler: PageHandler = page_cls(frontik_app, tornado_request, route, debug_mode, path_params) return await handler.execute() def convert_tornado_request_to_asgi( - frontik_app: FrontikApplication, + asgi_app: FrontikAsgiApp, tornado_request: httputil.HTTPServerRequest, - route: APIRoute, - path_params: dict[str, str], + scope: dict, debug_mode: DebugMode, result: dict[str, Any], ) -> tuple[dict, Callable, Callable]: @@ -208,24 +225,16 @@ def convert_tornado_request_to_asgi( for value in tornado_request.headers.get_list(header) ] - json_builder = JsonBuilder() - - scope = { - 'type': tornado_request.protocol, + scope.update({ 'http_version': tornado_request.version, - 'path': tornado_request.path, - 'method': tornado_request.method, 'query_string': tornado_request.query.encode(CHARSET), 'headers': headers, 'client': (tornado_request.remote_ip, 0), - 'route': route, - 'path_params': path_params, - 'http_client_factory': frontik_app.http_client_factory, - 'debug_enabled': debug_mode.enabled, - 'pass_debug': debug_mode.pass_debug, + 'http_client_factory': asgi_app.http_client_factory, + 'debug_mode': debug_mode, 'start_time': tornado_request._start_time, - 'json_builder': json_builder, - } + 'json_builder': JsonBuilder(), + }) async def receive(): return { diff --git a/frontik/options.py b/frontik/options.py index fd65f210b..47030134c 100644 --- a/frontik/options.py +++ b/frontik/options.py @@ -17,6 +17,7 @@ class Options: xheaders: bool = False validate_request_id: bool = False xsrf_cookies: bool = False + openapi_enabled: bool = False config: Optional[str] = None host: str = '0.0.0.0' diff --git a/frontik/request_context.py b/frontik/request_context.py index 76a6dd522..a407316e1 100644 --- a/frontik/request_context.py +++ b/frontik/request_context.py @@ -4,6 +4,8 @@ from contextlib import contextmanager from typing import TYPE_CHECKING, Optional +from fastapi.routing import APIRoute + if TYPE_CHECKING: from collections.abc import Iterator @@ -39,8 +41,8 @@ def get_handler_name() -> Optional[str]: return _context.get().handler_name -def set_handler_name(handler_name: str) -> None: - _context.get().handler_name = handler_name +def set_handler_name(route: APIRoute) -> None: + _context.get().handler_name = f'{route.endpoint.__module__}.{route.endpoint.__name__}' def get_log_handler() -> Optional[DebugBufferedHandler]: diff --git a/frontik/routing.py b/frontik/routing.py index eb999838e..fdc6f50db 100644 --- a/frontik/routing.py +++ b/frontik/routing.py @@ -10,6 +10,7 @@ from fastapi import APIRouter from fastapi.routing import APIRoute +from starlette.routing import Match if TYPE_CHECKING: from frontik.handler import PageHandler @@ -19,12 +20,13 @@ routers: list[APIRouter] = [] _plain_routes: dict[tuple[str, str], tuple[APIRoute, type[PageHandler] | None]] = {} _regex_mapping: list[tuple[re.Pattern, APIRoute, Type[PageHandler]]] = [] +_fastapi_routes: list[APIRoute] = [] class FrontikRouter(APIRouter): def __init__(self, *, cls: Optional[Type[PageHandler]] = None, **kwargs: Any) -> None: super().__init__(**kwargs) - routers.append(self) + self.include_in_schema = False self._cls: Optional[Type[PageHandler]] = None self._base_cls: Optional[Type[PageHandler]] = cls @@ -69,7 +71,7 @@ def add_api_route(self, *args: Any, cls: Optional[Type[PageHandler]] = None, **k class FrontikRegexRouter(APIRouter): def __init__(self, *, cls: Optional[Type[PageHandler]] = None, **kwargs: Any) -> None: super().__init__(**kwargs) - routers.append(self) + self.include_in_schema = False self._cls: Optional[Type[PageHandler]] = None self._base_cls: Optional[Type[PageHandler]] = cls @@ -105,6 +107,30 @@ def add_api_route(self, *args: Any, cls: Optional[Type[PageHandler]] = None, **k _regex_mapping.append((re.compile(route.path), route, self._cls)) # type: ignore +class FastAPIRouter(APIRouter): + def __init__(self, include_in_app: bool = True, **kwargs: Any) -> None: + super().__init__(**kwargs) + if include_in_app: + routers.append(self) + + async def __call__(self, scope, receive, send): + assert scope['type'] == 'http' + + if 'router' not in scope: + scope['router'] = self + + route = scope['route'] + await route.handle(scope, receive, send) + + def add_api_route(self, *args: Any, **kwargs: Any) -> None: + super().add_api_route(*args, **kwargs) + _fastapi_routes.append(self.routes[-1]) # type: ignore + + def add_route(self, *args: Any, **kwargs: Any) -> None: + super().add_route(*args, **kwargs) + _fastapi_routes.append(self.routes[-1]) # type: ignore + + def _iter_submodules(path: MutableSequence[str], prefix: str = '') -> Generator: """Find packages recursively, including PEP420 packages""" yield from pkgutil.walk_packages(path, prefix) @@ -140,37 +166,64 @@ def import_all_pages(app_module: str) -> None: raise RuntimeError('failed on import page %s %s', full_name, ex) -router = FrontikRouter() +plain_router = FrontikRouter() +router = FastAPIRouter(include_in_app=False) not_found_router = FrontikRouter() method_not_allowed_router = FrontikRouter() regex_router = FrontikRegexRouter() -routers.extend((router, regex_router)) + + +def _find_fastapi_route(scope: dict) -> Optional[APIRoute]: + partial = None + + for route in _fastapi_routes: + match, child_scope = route.matches(scope) + if match == Match.FULL or (match == Match.PARTIAL and partial is None): + scope.update(child_scope) + scope['route'] = route + return route + + return None def _find_regex_route( path: str, method: str -) -> Union[tuple[APIRoute, Type[PageHandler], dict], tuple[None, None, None]]: +) -> Union[tuple[APIRoute, Type[PageHandler], dict], tuple[None, None, dict]]: for pattern, route, cls in _regex_mapping: match = pattern.match(path) if match and next(iter(route.methods), None) == method: return route, cls, match.groupdict() - return None, None, None + return None, None, {} -def find_route(path: str, method: str) -> tuple[APIRoute, type[PageHandler], dict]: +def find_route(path: str, method: str) -> dict: route: APIRoute route, page_cls, path_params = _find_regex_route(path, method) # type: ignore + scope = { + 'type': 'http', + 'path': path, + 'method': method, + 'route': route, + 'page_cls': page_cls, + 'path_params': path_params, + } if route is None: route, page_cls = _plain_routes.get((path.strip('/'), method), (None, None)) - path_params = {} + scope['route'] = route + scope['page_cls'] = page_cls + + if route is None: + route = _find_fastapi_route(scope) + + if route is None and method == 'HEAD': + return find_route(path, 'GET') if route is None: routing_logger.error('match for request url %s "%s" not found', method, path) - return None, None, None - return route, page_cls, path_params # type: ignore + return scope def get_allowed_methods(path: str) -> list[str]: diff --git a/tests/projects/balancer_app/pages/different_datacenter.py b/tests/projects/balancer_app/pages/different_datacenter.py index 4df600090..f3014b435 100644 --- a/tests/projects/balancer_app/pages/different_datacenter.py +++ b/tests/projects/balancer_app/pages/different_datacenter.py @@ -4,11 +4,11 @@ from frontik import media_types from frontik.handler import PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router from tests.projects.balancer_app import get_server -@router.get('/different_datacenter', cls=PageHandler) +@plain_router.get('/different_datacenter', cls=PageHandler) async def get_page(handler=get_current_handler()): free_server = get_server(handler, 'free') free_server.datacenter = 'dc1' @@ -30,7 +30,7 @@ async def get_page(handler=get_current_handler()): handler.text = result.data -@router.post('/different_datacenter', cls=PageHandler) +@plain_router.post('/different_datacenter', cls=PageHandler) async def post_page(handler=get_current_handler()): handler.set_header('Content-Type', media_types.TEXT_PLAIN) handler.text = 'result' diff --git a/tests/projects/balancer_app/pages/no_available_backend.py b/tests/projects/balancer_app/pages/no_available_backend.py index b2aefc2fd..3aa05c80a 100644 --- a/tests/projects/balancer_app/pages/no_available_backend.py +++ b/tests/projects/balancer_app/pages/no_available_backend.py @@ -3,11 +3,11 @@ from frontik import media_types from frontik.handler import PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router from tests.projects.balancer_app.pages import check_all_requests_done -@router.get('/no_available_backend', cls=PageHandler) +@plain_router.get('/no_available_backend', cls=PageHandler) async def get_page(handler=get_current_handler()): upstreams = handler.application.upstream_manager.get_upstreams() upstreams['no_available_backend'] = Upstream('no_available_backend', {}, []) @@ -26,7 +26,7 @@ async def get_page(handler=get_current_handler()): check_all_requests_done(handler, 'no_available_backend') -@router.post('/no_available_backend', cls=PageHandler) +@plain_router.post('/no_available_backend', cls=PageHandler) async def post_page(handler=get_current_handler()): handler.set_header('Content-Type', media_types.TEXT_PLAIN) handler.text = 'result' diff --git a/tests/projects/balancer_app/pages/no_retry_error.py b/tests/projects/balancer_app/pages/no_retry_error.py index 94d3dbbb7..e55492a0b 100644 --- a/tests/projects/balancer_app/pages/no_retry_error.py +++ b/tests/projects/balancer_app/pages/no_retry_error.py @@ -2,12 +2,12 @@ from frontik import media_types from frontik.handler import PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router from tests.projects.balancer_app import get_server from tests.projects.balancer_app.pages import check_all_requests_done -@router.get('/no_retry_error', cls=PageHandler) +@plain_router.get('/no_retry_error', cls=PageHandler) async def get_page(handler=get_current_handler()): upstreams = handler.application.upstream_manager.get_upstreams() upstreams['no_retry_error'] = Upstream('no_retry_error', {}, [get_server(handler, 'broken')]) @@ -21,7 +21,7 @@ async def get_page(handler=get_current_handler()): check_all_requests_done(handler, 'no_retry_error') -@router.post('/no_retry_error', cls=PageHandler) +@plain_router.post('/no_retry_error', cls=PageHandler) async def post_page(handler=get_current_handler()): handler.set_header('Content-Type', media_types.TEXT_PLAIN) handler.text = 'result' diff --git a/tests/projects/balancer_app/pages/no_retry_timeout.py b/tests/projects/balancer_app/pages/no_retry_timeout.py index a54a15601..56f7eaa43 100644 --- a/tests/projects/balancer_app/pages/no_retry_timeout.py +++ b/tests/projects/balancer_app/pages/no_retry_timeout.py @@ -4,12 +4,12 @@ from frontik import media_types from frontik.handler import PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router from tests.projects.balancer_app import get_server from tests.projects.balancer_app.pages import check_all_requests_done -@router.get('/no_retry_timeout', cls=PageHandler) +@plain_router.get('/no_retry_timeout', cls=PageHandler) async def get_page(handler=get_current_handler()): upstreams = handler.application.upstream_manager.get_upstreams() upstreams['no_retry_timeout'] = Upstream('no_retry_timeout', {}, [get_server(handler, 'broken')]) @@ -23,7 +23,7 @@ async def get_page(handler=get_current_handler()): check_all_requests_done(handler, 'no_retry_timeout') -@router.post('/no_retry_timeout', cls=PageHandler) +@plain_router.post('/no_retry_timeout', cls=PageHandler) async def post_page(handler=get_current_handler()): handler.set_header('Content-Type', media_types.TEXT_PLAIN) handler.text = 'result' diff --git a/tests/projects/balancer_app/pages/profile_with_retry.py b/tests/projects/balancer_app/pages/profile_with_retry.py index 414758955..54c806e2b 100644 --- a/tests/projects/balancer_app/pages/profile_with_retry.py +++ b/tests/projects/balancer_app/pages/profile_with_retry.py @@ -3,11 +3,11 @@ from frontik import media_types from frontik.handler import PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router from tests.projects.balancer_app import get_server -@router.get('/profile_with_retry', cls=PageHandler) +@plain_router.get('/profile_with_retry', cls=PageHandler) async def get_page(handler=get_current_handler()): servers = [get_server(handler, 'broken'), get_server(handler, 'normal')] upstream_config = { @@ -30,7 +30,7 @@ async def get_page(handler=get_current_handler()): handler.text = result.data -@router.put('/profile_with_retry', cls=PageHandler) +@plain_router.put('/profile_with_retry', cls=PageHandler) async def put_page(handler=get_current_handler()): handler.set_header('Content-Type', media_types.TEXT_PLAIN) handler.text = 'result' diff --git a/tests/projects/balancer_app/pages/profile_without_retry.py b/tests/projects/balancer_app/pages/profile_without_retry.py index 9144f5a38..294db6711 100644 --- a/tests/projects/balancer_app/pages/profile_without_retry.py +++ b/tests/projects/balancer_app/pages/profile_without_retry.py @@ -2,11 +2,11 @@ from frontik import media_types from frontik.handler import PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router from tests.projects.balancer_app import get_server -@router.get('/profile_without_retry', cls=PageHandler) +@plain_router.get('/profile_without_retry', cls=PageHandler) async def get_page(handler=get_current_handler()): servers = [get_server(handler, 'broken'), get_server(handler, 'normal')] upstream_config = { @@ -29,7 +29,7 @@ async def get_page(handler=get_current_handler()): handler.text = result.data -@router.put('/profile_without_retry', cls=PageHandler) +@plain_router.put('/profile_without_retry', cls=PageHandler) async def put_page(handler=get_current_handler()): handler.set_header('Content-Type', media_types.TEXT_PLAIN) handler.text = 'result' diff --git a/tests/projects/balancer_app/pages/requests_count.py b/tests/projects/balancer_app/pages/requests_count.py index aaea1fc56..da40461c2 100644 --- a/tests/projects/balancer_app/pages/requests_count.py +++ b/tests/projects/balancer_app/pages/requests_count.py @@ -4,12 +4,12 @@ from frontik import media_types from frontik.handler import PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router from tests.projects.balancer_app import get_server from tests.projects.balancer_app.pages import check_all_requests_done, check_all_servers_occupied -@router.get('/requests_count', cls=PageHandler) +@plain_router.get('/requests_count', cls=PageHandler) async def get_page(handler=get_current_handler()): upstreams = handler.application.upstream_manager.get_upstreams() upstreams['requests_count_async'] = Upstream('requests_count_async', {}, [get_server(handler, 'normal')]) @@ -31,7 +31,7 @@ async def get_page(handler=get_current_handler()): check_all_requests_done(handler, 'requests_count_async') -@router.post('/requests_count', cls=PageHandler) +@plain_router.post('/requests_count', cls=PageHandler) async def post_page(handler=get_current_handler()): handler.set_header('Content-Type', media_types.TEXT_PLAIN) upstreams = handler.application.upstream_manager.get_upstreams() diff --git a/tests/projects/balancer_app/pages/retry_connect.py b/tests/projects/balancer_app/pages/retry_connect.py index 14947108e..5190d88ba 100644 --- a/tests/projects/balancer_app/pages/retry_connect.py +++ b/tests/projects/balancer_app/pages/retry_connect.py @@ -3,13 +3,13 @@ from frontik import media_types from frontik.handler import PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router from frontik.util import gather_list from tests.projects.balancer_app import get_server from tests.projects.balancer_app.pages import check_all_servers_were_occupied -@router.get('/retry_connect', cls=PageHandler) +@plain_router.get('/retry_connect', cls=PageHandler) async def get_page(handler: PageHandler = get_current_handler()) -> None: upstreams = handler.application.upstream_manager.get_upstreams() upstreams['retry_connect'] = Upstream( @@ -35,7 +35,7 @@ async def get_page(handler: PageHandler = get_current_handler()) -> None: handler.text = handler.text + result.data -@router.post('/retry_connect', cls=PageHandler) +@plain_router.post('/retry_connect', cls=PageHandler) async def post_page(handler: PageHandler = get_current_handler()) -> None: handler.set_header('Content-Type', media_types.TEXT_PLAIN) handler.text = 'result' diff --git a/tests/projects/balancer_app/pages/retry_connect_timeout.py b/tests/projects/balancer_app/pages/retry_connect_timeout.py index 82806e56f..d80bdd8a9 100644 --- a/tests/projects/balancer_app/pages/retry_connect_timeout.py +++ b/tests/projects/balancer_app/pages/retry_connect_timeout.py @@ -3,13 +3,13 @@ from frontik import media_types from frontik.handler import PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router from frontik.util import gather_list from tests.projects.balancer_app import get_server from tests.projects.balancer_app.pages import check_all_servers_were_occupied -@router.get('/retry_connect_timeout', cls=PageHandler) +@plain_router.get('/retry_connect_timeout', cls=PageHandler) async def get_page(handler: PageHandler = get_current_handler()) -> None: upstreams = handler.application.upstream_manager.get_upstreams() upstreams['retry_connect_timeout'] = Upstream('retry_connect_timeout', {}, [get_server(handler, 'normal')]) @@ -31,7 +31,7 @@ async def get_page(handler: PageHandler = get_current_handler()) -> None: handler.text = handler.text + result.data -@router.post('/retry_connect_timeout', cls=PageHandler) +@plain_router.post('/retry_connect_timeout', cls=PageHandler) async def post_page(handler: PageHandler = get_current_handler()) -> None: handler.set_header('Content-Type', media_types.TEXT_PLAIN) handler.text = 'result' diff --git a/tests/projects/balancer_app/pages/retry_count_limit.py b/tests/projects/balancer_app/pages/retry_count_limit.py index f4b1e0a8b..fabc3b52f 100644 --- a/tests/projects/balancer_app/pages/retry_count_limit.py +++ b/tests/projects/balancer_app/pages/retry_count_limit.py @@ -1,12 +1,12 @@ from http_client.balancing import Upstream, UpstreamConfig from frontik.handler import PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router from tests.instances import find_free_port from tests.projects.balancer_app import get_server_with_port -@router.get('/retry_count_limit', cls=PageHandler) +@plain_router.get('/retry_count_limit', cls=PageHandler) async def get_page(handler=get_current_handler()): upstream = Upstream( 'retry_count_limit', diff --git a/tests/projects/balancer_app/pages/retry_error.py b/tests/projects/balancer_app/pages/retry_error.py index a25b0e011..061bde4a6 100644 --- a/tests/projects/balancer_app/pages/retry_error.py +++ b/tests/projects/balancer_app/pages/retry_error.py @@ -3,13 +3,13 @@ from frontik import media_types from frontik.handler import PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router from frontik.util import gather_list from tests.projects.balancer_app import get_server from tests.projects.balancer_app.pages import check_all_servers_were_occupied -@router.get('/retry_error', cls=PageHandler) +@plain_router.get('/retry_error', cls=PageHandler) async def get_page(handler=get_current_handler()): upstreams = handler.application.upstream_manager.get_upstreams() upstreams['retry_error'] = Upstream( @@ -34,7 +34,7 @@ async def get_page(handler=get_current_handler()): handler.text = handler.text + result.data -@router.put('/retry_error', cls=PageHandler) +@plain_router.put('/retry_error', cls=PageHandler) async def put_page(handler=get_current_handler()): handler.set_header('Content-Type', media_types.TEXT_PLAIN) handler.text = 'result' diff --git a/tests/projects/balancer_app/pages/retry_non_idempotent_503.py b/tests/projects/balancer_app/pages/retry_non_idempotent_503.py index 3426492c2..98b1866d9 100644 --- a/tests/projects/balancer_app/pages/retry_non_idempotent_503.py +++ b/tests/projects/balancer_app/pages/retry_non_idempotent_503.py @@ -3,13 +3,13 @@ from frontik import media_types from frontik.handler import PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router from frontik.util import gather_list from tests.projects.balancer_app import get_server from tests.projects.balancer_app.pages import check_all_requests_done -@router.get('/retry_non_idempotent_503', cls=PageHandler) +@plain_router.get('/retry_non_idempotent_503', cls=PageHandler) async def get_page(handler=get_current_handler()): upstream_config = {Upstream.DEFAULT_PROFILE: UpstreamConfig(retry_policy={503: {'idempotent': 'true'}})} upstreams = handler.application.upstream_manager.get_upstreams() @@ -40,7 +40,7 @@ async def get_page(handler=get_current_handler()): check_all_requests_done(handler, 'do_not_retry_non_idempotent_503') -@router.post('/retry_non_idempotent_503', cls=PageHandler) +@plain_router.post('/retry_non_idempotent_503', cls=PageHandler) async def post_page(handler=get_current_handler()): handler.set_header('Content-Type', media_types.TEXT_PLAIN) handler.text = 'result' diff --git a/tests/projects/balancer_app/pages/retry_on_timeout.py b/tests/projects/balancer_app/pages/retry_on_timeout.py index 517d921ed..6615944c1 100644 --- a/tests/projects/balancer_app/pages/retry_on_timeout.py +++ b/tests/projects/balancer_app/pages/retry_on_timeout.py @@ -3,12 +3,12 @@ from frontik import media_types from frontik.handler import PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router from tests.projects.balancer_app import get_server from tests.projects.balancer_app.pages import check_all_requests_done -@router.get('/retry_on_timeout', cls=PageHandler) +@plain_router.get('/retry_on_timeout', cls=PageHandler) async def get_page(handler=get_current_handler()): upstreams = handler.application.upstream_manager.get_upstreams() upstreams['retry_on_timeout'] = Upstream( @@ -33,7 +33,7 @@ async def get_page(handler=get_current_handler()): check_all_requests_done(handler, 'retry_on_timeout') -@router.delete('/retry_on_timeout', cls=PageHandler) +@plain_router.delete('/retry_on_timeout', cls=PageHandler) async def delete_page(handler=get_current_handler()): handler.set_header('Content-Type', media_types.TEXT_PLAIN) handler.text = 'result' diff --git a/tests/projects/balancer_app/pages/slow_start.py b/tests/projects/balancer_app/pages/slow_start.py index 3f5adc832..aced5a117 100644 --- a/tests/projects/balancer_app/pages/slow_start.py +++ b/tests/projects/balancer_app/pages/slow_start.py @@ -4,12 +4,12 @@ from frontik import media_types from frontik.handler import PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router from tests.projects.balancer_app import get_server from tests.projects.balancer_app.pages import check_all_requests_done, check_all_servers_were_occupied -@router.get('/slow_start', cls=PageHandler) +@plain_router.get('/slow_start', cls=PageHandler) async def get_page(handler=get_current_handler()): server = get_server(handler, 'normal') server.weight = 5 @@ -43,7 +43,7 @@ async def get_page(handler=get_current_handler()): check_all_requests_done(handler, 'slow_start') -@router.post('/slow_start', cls=PageHandler) +@plain_router.post('/slow_start', cls=PageHandler) async def post_page(handler=get_current_handler()): handler.set_header('Content-Type', media_types.TEXT_PLAIN) upstreams = handler.application.upstream_manager.get_upstreams() diff --git a/tests/projects/balancer_app/pages/speculative_no_retry.py b/tests/projects/balancer_app/pages/speculative_no_retry.py index 5daa99503..a443fb4a3 100644 --- a/tests/projects/balancer_app/pages/speculative_no_retry.py +++ b/tests/projects/balancer_app/pages/speculative_no_retry.py @@ -2,11 +2,11 @@ from frontik import media_types from frontik.handler import PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router from tests.projects.balancer_app import get_server -@router.get('/speculative_no_retry', cls=PageHandler) +@plain_router.get('/speculative_no_retry', cls=PageHandler) async def get_page(handler=get_current_handler()): upstreams = handler.application.upstream_manager.get_upstreams() upstreams['speculative_no_retry'] = Upstream( @@ -31,7 +31,7 @@ async def get_page(handler=get_current_handler()): handler.text = result.data -@router.post('/speculative_no_retry', cls=PageHandler) +@plain_router.post('/speculative_no_retry', cls=PageHandler) async def post_page(handler=get_current_handler()): handler.set_header('Content-Type', media_types.TEXT_PLAIN) handler.text = 'result' diff --git a/tests/projects/balancer_app/pages/speculative_retry.py b/tests/projects/balancer_app/pages/speculative_retry.py index e71b623fb..9c69a978b 100644 --- a/tests/projects/balancer_app/pages/speculative_retry.py +++ b/tests/projects/balancer_app/pages/speculative_retry.py @@ -3,11 +3,11 @@ from frontik import media_types from frontik.handler import PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router from tests.projects.balancer_app import get_server -@router.get('/speculative_retry', cls=PageHandler) +@plain_router.get('/speculative_retry', cls=PageHandler) async def get_page(handler=get_current_handler()): upstreams = handler.application.upstream_manager.get_upstreams() upstreams['speculative_retry'] = Upstream( @@ -31,7 +31,7 @@ async def get_page(handler=get_current_handler()): handler.text = result.data -@router.put('/speculative_retry', cls=PageHandler) +@plain_router.put('/speculative_retry', cls=PageHandler) async def put_page(handler=get_current_handler()): handler.set_header('Content-Type', media_types.TEXT_PLAIN) handler.text = 'result' diff --git a/tests/projects/broken_balancer_app/pages/no_retry_error.py b/tests/projects/broken_balancer_app/pages/no_retry_error.py index ddec3d87a..f23f86258 100644 --- a/tests/projects/broken_balancer_app/pages/no_retry_error.py +++ b/tests/projects/broken_balancer_app/pages/no_retry_error.py @@ -1,9 +1,9 @@ from tornado.web import HTTPError from frontik.handler import PageHandler -from frontik.routing import router +from frontik.routing import plain_router -@router.post('/no_retry_error', cls=PageHandler) +@plain_router.post('/no_retry_error', cls=PageHandler) async def post_page(): raise HTTPError(500, 'something went wrong, no retry') diff --git a/tests/projects/broken_balancer_app/pages/no_retry_timeout.py b/tests/projects/broken_balancer_app/pages/no_retry_timeout.py index 997888138..ce2c0afe2 100644 --- a/tests/projects/broken_balancer_app/pages/no_retry_timeout.py +++ b/tests/projects/broken_balancer_app/pages/no_retry_timeout.py @@ -1,10 +1,10 @@ import asyncio from frontik.handler import PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router -@router.post('/no_retry_timeout', cls=PageHandler) +@plain_router.post('/no_retry_timeout', cls=PageHandler) async def post_page(handler=get_current_handler()): await asyncio.sleep(2) diff --git a/tests/projects/broken_balancer_app/pages/profile_with_retry.py b/tests/projects/broken_balancer_app/pages/profile_with_retry.py index 2d826e4b5..c45553a79 100644 --- a/tests/projects/broken_balancer_app/pages/profile_with_retry.py +++ b/tests/projects/broken_balancer_app/pages/profile_with_retry.py @@ -1,9 +1,9 @@ from tornado.web import HTTPError from frontik.handler import PageHandler -from frontik.routing import router +from frontik.routing import plain_router -@router.put('/profile_with_retry', cls=PageHandler) +@plain_router.put('/profile_with_retry', cls=PageHandler) async def put_page(): raise HTTPError(503, 'broken') diff --git a/tests/projects/broken_balancer_app/pages/profile_without_retry.py b/tests/projects/broken_balancer_app/pages/profile_without_retry.py index e44051a15..e53c348a7 100644 --- a/tests/projects/broken_balancer_app/pages/profile_without_retry.py +++ b/tests/projects/broken_balancer_app/pages/profile_without_retry.py @@ -1,9 +1,9 @@ from tornado.web import HTTPError from frontik.handler import PageHandler -from frontik.routing import router +from frontik.routing import plain_router -@router.put('/profile_without_retry', cls=PageHandler) +@plain_router.put('/profile_without_retry', cls=PageHandler) async def put_page(): raise HTTPError(503, 'broken') diff --git a/tests/projects/broken_balancer_app/pages/retry_connect.py b/tests/projects/broken_balancer_app/pages/retry_connect.py index a54fb1b6f..77a67eae2 100644 --- a/tests/projects/broken_balancer_app/pages/retry_connect.py +++ b/tests/projects/broken_balancer_app/pages/retry_connect.py @@ -1,9 +1,9 @@ from tornado.web import HTTPError from frontik.handler import PageHandler -from frontik.routing import router +from frontik.routing import plain_router -@router.post('/retry_connect', cls=PageHandler) +@plain_router.post('/retry_connect', cls=PageHandler) async def post_page(): raise HTTPError(503, 'broken, retry') diff --git a/tests/projects/broken_balancer_app/pages/retry_error.py b/tests/projects/broken_balancer_app/pages/retry_error.py index 7d4c3c964..45e07b99d 100644 --- a/tests/projects/broken_balancer_app/pages/retry_error.py +++ b/tests/projects/broken_balancer_app/pages/retry_error.py @@ -1,9 +1,9 @@ from tornado.web import HTTPError from frontik.handler import PageHandler -from frontik.routing import router +from frontik.routing import plain_router -@router.put('/retry_error', cls=PageHandler) +@plain_router.put('/retry_error', cls=PageHandler) async def put_page(): raise HTTPError(503, 'broken, retry') diff --git a/tests/projects/broken_balancer_app/pages/retry_non_idempotent_503.py b/tests/projects/broken_balancer_app/pages/retry_non_idempotent_503.py index 8866443f9..fc6dcfb8f 100644 --- a/tests/projects/broken_balancer_app/pages/retry_non_idempotent_503.py +++ b/tests/projects/broken_balancer_app/pages/retry_non_idempotent_503.py @@ -1,9 +1,9 @@ from tornado.web import HTTPError from frontik.handler import PageHandler -from frontik.routing import router +from frontik.routing import plain_router -@router.post('/retry_non_idempotent_503', cls=PageHandler) +@plain_router.post('/retry_non_idempotent_503', cls=PageHandler) async def post_page(): raise HTTPError(503, 'broken, retry') diff --git a/tests/projects/broken_balancer_app/pages/retry_on_timeout.py b/tests/projects/broken_balancer_app/pages/retry_on_timeout.py index 532222539..3b0191046 100644 --- a/tests/projects/broken_balancer_app/pages/retry_on_timeout.py +++ b/tests/projects/broken_balancer_app/pages/retry_on_timeout.py @@ -2,10 +2,10 @@ from frontik import media_types from frontik.handler import PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router -@router.delete('/retry_on_timeout', cls=PageHandler) +@plain_router.delete('/retry_on_timeout', cls=PageHandler) async def delete_page(handler=get_current_handler()): await asyncio.sleep(2) diff --git a/tests/projects/broken_balancer_app/pages/speculative_no_retry.py b/tests/projects/broken_balancer_app/pages/speculative_no_retry.py index e4bd29b05..e58b3fee6 100644 --- a/tests/projects/broken_balancer_app/pages/speculative_no_retry.py +++ b/tests/projects/broken_balancer_app/pages/speculative_no_retry.py @@ -3,10 +3,10 @@ from tornado.web import HTTPError from frontik.handler import PageHandler -from frontik.routing import router +from frontik.routing import plain_router -@router.post('/speculative_no_retry', cls=PageHandler) +@plain_router.post('/speculative_no_retry', cls=PageHandler) async def post_page(): await asyncio.sleep(0.8) raise HTTPError(500, 'broken') diff --git a/tests/projects/broken_balancer_app/pages/speculative_retry.py b/tests/projects/broken_balancer_app/pages/speculative_retry.py index 6ba5d6d5e..595ef840f 100644 --- a/tests/projects/broken_balancer_app/pages/speculative_retry.py +++ b/tests/projects/broken_balancer_app/pages/speculative_retry.py @@ -3,10 +3,10 @@ from tornado.web import HTTPError from frontik.handler import PageHandler -from frontik.routing import router +from frontik.routing import plain_router -@router.put('/speculative_retry', cls=PageHandler) +@plain_router.put('/speculative_retry', cls=PageHandler) async def put_page(): await asyncio.sleep(0.8) raise HTTPError(503, 'broken, retry') diff --git a/tests/projects/consul_mock_app/pages/call_deregistration_stat.py b/tests/projects/consul_mock_app/pages/call_deregistration_stat.py index c7730fdce..c74fa8ef0 100644 --- a/tests/projects/consul_mock_app/pages/call_deregistration_stat.py +++ b/tests/projects/consul_mock_app/pages/call_deregistration_stat.py @@ -1,10 +1,10 @@ import json from frontik.handler import PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router -@router.get('/call_deregistration_stat', cls=PageHandler) +@plain_router.get('/call_deregistration_stat', cls=PageHandler) async def get_page(handler=get_current_handler()): handler.set_status(200) handler.text = json.dumps(handler.application.deregistration_call_counter) diff --git a/tests/projects/consul_mock_app/pages/call_registration_stat.py b/tests/projects/consul_mock_app/pages/call_registration_stat.py index 09a70a6a7..03bf82571 100644 --- a/tests/projects/consul_mock_app/pages/call_registration_stat.py +++ b/tests/projects/consul_mock_app/pages/call_registration_stat.py @@ -1,10 +1,10 @@ import json from frontik.handler import PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router -@router.get('/call_registration_stat', cls=PageHandler) +@plain_router.get('/call_registration_stat', cls=PageHandler) async def get_page(handler=get_current_handler()): handler.set_status(200) handler.text = json.dumps(handler.application.registration_call_counter) diff --git a/tests/projects/consul_mock_app/pages/v1/agent/service/register.py b/tests/projects/consul_mock_app/pages/v1/agent/service/register.py index ea58f6438..496692e4a 100644 --- a/tests/projects/consul_mock_app/pages/v1/agent/service/register.py +++ b/tests/projects/consul_mock_app/pages/v1/agent/service/register.py @@ -1,20 +1,20 @@ from frontik.handler import PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router -@router.get('/v1/agent/service/register', cls=PageHandler) +@plain_router.get('/v1/agent/service/register', cls=PageHandler) async def get_page(handler=get_current_handler()): handler.set_status(200) handler.application.registration_call_counter['get_page'] += 1 -@router.put('/v1/agent/service/register', cls=PageHandler) +@plain_router.put('/v1/agent/service/register', cls=PageHandler) async def put_page(handler=get_current_handler()): handler.set_status(200) handler.application.registration_call_counter['put_page'] += 1 -@router.post('/v1/agent/service/register', cls=PageHandler) +@plain_router.post('/v1/agent/service/register', cls=PageHandler) async def post_page(handler=get_current_handler()): handler.set_status(200) handler.application.registration_call_counter['post_page'] += 1 diff --git a/tests/projects/consul_mock_app/pages/v1/kv/upstream/upstream.py b/tests/projects/consul_mock_app/pages/v1/kv/upstream/upstream.py index 0d48e92e6..aad5841cf 100644 --- a/tests/projects/consul_mock_app/pages/v1/kv/upstream/upstream.py +++ b/tests/projects/consul_mock_app/pages/v1/kv/upstream/upstream.py @@ -1,21 +1,21 @@ import json from frontik.handler import PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router -@router.get('/v1/kv/upstream/', cls=PageHandler) +@plain_router.get('/v1/kv/upstream/', cls=PageHandler) async def get_page(handler=get_current_handler()): handler.set_header('X-Consul-Index', '1') handler.text = json.dumps([{'Value': None, 'CreateIndex': 1, 'ModifyIndex': 1}]) handler.set_status(200) -@router.put('/v1/kv/upstream/', cls=PageHandler) +@plain_router.put('/v1/kv/upstream/', cls=PageHandler) async def put_page(handler=get_current_handler()): handler.set_status(200) -@router.post('/v1/kv/upstream/', cls=PageHandler) +@plain_router.post('/v1/kv/upstream/', cls=PageHandler) async def post_page(handler=get_current_handler()): handler.set_status(200) diff --git a/tests/projects/no_debug_app/pages/basic_auth.py b/tests/projects/no_debug_app/pages/basic_auth.py index d0c652d9e..42c78f024 100644 --- a/tests/projects/no_debug_app/pages/basic_auth.py +++ b/tests/projects/no_debug_app/pages/basic_auth.py @@ -1,9 +1,9 @@ from frontik.auth import check_debug_auth_or_finish from frontik.handler import PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router -@router.get('/basic_auth', cls=PageHandler) +@plain_router.get('/basic_auth', cls=PageHandler) async def get_page(handler: PageHandler = get_current_handler()) -> None: check_debug_auth_or_finish(handler, 'user', 'god') handler.json.put({'authenticated': True}) diff --git a/tests/projects/no_debug_app/pages/check_workers_count_down.py b/tests/projects/no_debug_app/pages/check_workers_count_down.py index 5754b0741..bc7795634 100644 --- a/tests/projects/no_debug_app/pages/check_workers_count_down.py +++ b/tests/projects/no_debug_app/pages/check_workers_count_down.py @@ -1,7 +1,7 @@ from frontik.handler import PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router -@router.get('/check_workers_count_down', cls=PageHandler) +@plain_router.get('/check_workers_count_down', cls=PageHandler) async def get_page(handler=get_current_handler()): handler.text = str(handler.application.worker_state.init_workers_count_down.value) diff --git a/tests/projects/no_debug_app/pages/jinja_no_environment.py b/tests/projects/no_debug_app/pages/jinja_no_environment.py index f749bf4e4..3ccf87e4d 100644 --- a/tests/projects/no_debug_app/pages/jinja_no_environment.py +++ b/tests/projects/no_debug_app/pages/jinja_no_environment.py @@ -1,8 +1,8 @@ from frontik.handler import PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router -@router.get('/jinja_no_environment', cls=PageHandler) +@plain_router.get('/jinja_no_environment', cls=PageHandler) async def get_page(handler=get_current_handler()): handler.set_template('empty.html') handler.json.put({'x': 'y'}) diff --git a/tests/projects/no_debug_app/pages/recursion.py b/tests/projects/no_debug_app/pages/recursion.py index 7412bfb02..7361c090d 100644 --- a/tests/projects/no_debug_app/pages/recursion.py +++ b/tests/projects/no_debug_app/pages/recursion.py @@ -1,9 +1,9 @@ from frontik import media_types from frontik.handler import PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router -@router.get('/recursion', cls=PageHandler) +@plain_router.get('/recursion', cls=PageHandler) async def get_page(handler=get_current_handler()): n = int(handler.get_query_argument('n')) if n > 0: diff --git a/tests/projects/no_debug_app/pages/simple.py b/tests/projects/no_debug_app/pages/simple.py index 9228c3550..4573d4bb6 100644 --- a/tests/projects/no_debug_app/pages/simple.py +++ b/tests/projects/no_debug_app/pages/simple.py @@ -1,10 +1,10 @@ from lxml import etree from frontik.handler import PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router -@router.get('/simple', cls=PageHandler) +@plain_router.get('/simple', cls=PageHandler) async def get_page(handler=get_current_handler()): handler.set_xsl('simple.xsl') handler.doc.put(etree.Element('ok')) diff --git a/tests/projects/re_app/pages/jinja_custom_environment.py b/tests/projects/re_app/pages/jinja_custom_environment.py index c0405b3c7..19c1f4aa0 100644 --- a/tests/projects/re_app/pages/jinja_custom_environment.py +++ b/tests/projects/re_app/pages/jinja_custom_environment.py @@ -1,8 +1,8 @@ from frontik.handler import PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router -@router.get('/jinja_custom_environment', cls=PageHandler) +@plain_router.get('/jinja_custom_environment', cls=PageHandler) async def get_page(handler=get_current_handler()): handler.set_template('jinja_custom_environment.html') handler.json.put({}) diff --git a/tests/projects/re_app/pages/sentry_not_configured.py b/tests/projects/re_app/pages/sentry_not_configured.py index 4acea7427..efcd45812 100644 --- a/tests/projects/re_app/pages/sentry_not_configured.py +++ b/tests/projects/re_app/pages/sentry_not_configured.py @@ -1,7 +1,7 @@ from frontik.handler import PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router -@router.get('/sentry_not_configured', cls=PageHandler) +@plain_router.get('/sentry_not_configured', cls=PageHandler) async def get_page(handler=get_current_handler()): assert not hasattr(handler, 'get_sentry_logger') diff --git a/tests/projects/re_app/pages/simple.py b/tests/projects/re_app/pages/simple.py index 9f0621e40..3101725df 100644 --- a/tests/projects/re_app/pages/simple.py +++ b/tests/projects/re_app/pages/simple.py @@ -1,15 +1,15 @@ from lxml import etree from frontik.handler import PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router -@router.get('/simple', cls=PageHandler) +@plain_router.get('/simple', cls=PageHandler) async def get_page1(handler=get_current_handler()): return await get_page(handler) -@router.get('/not_simple', cls=PageHandler) +@plain_router.get('/not_simple', cls=PageHandler) async def get_page2(handler: PageHandler = get_current_handler()) -> None: return await get_page(handler) diff --git a/tests/projects/test_app/pages/api/2/store.py b/tests/projects/test_app/pages/api/2/store.py index 561bfd144..74dc6b825 100644 --- a/tests/projects/test_app/pages/api/2/store.py +++ b/tests/projects/test_app/pages/api/2/store.py @@ -2,14 +2,14 @@ import json from frontik.handler import PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router class Page(PageHandler): exceptions = [] -@router.post('/api/2/envelope/', cls=Page) +@plain_router.post('/api/2/envelope/', cls=Page) async def post_page(handler: Page = get_current_handler()): messages = gzip.decompress(handler.request.body).decode('utf8') @@ -20,11 +20,11 @@ async def post_page(handler: Page = get_current_handler()): Page.exceptions.append(sentry_event) -@router.get('/api/2/envelope/', cls=Page) +@plain_router.get('/api/2/envelope/', cls=Page) async def get_page(handler=get_current_handler()): handler.json.put({'exceptions': Page.exceptions}) -@router.delete('/api/2/envelope/', cls=Page) +@plain_router.delete('/api/2/envelope/', cls=Page) async def delete_page(): Page.exceptions = [] diff --git a/tests/projects/test_app/pages/arguments.py b/tests/projects/test_app/pages/arguments.py index 9c7b45e45..85a5c30c1 100644 --- a/tests/projects/test_app/pages/arguments.py +++ b/tests/projects/test_app/pages/arguments.py @@ -1,7 +1,7 @@ from frontik.handler import PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router -@router.get('/arguments', cls=PageHandler) +@plain_router.get('/arguments', cls=PageHandler) async def get_page(handler: PageHandler = get_current_handler()) -> None: handler.json.put({'тест': handler.get_argument('param')}) diff --git a/tests/projects/test_app/pages/async_group/group.py b/tests/projects/test_app/pages/async_group/group.py index abc3577f7..987ab5d7c 100644 --- a/tests/projects/test_app/pages/async_group/group.py +++ b/tests/projects/test_app/pages/async_group/group.py @@ -1,11 +1,11 @@ from typing import Any from frontik.handler import PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router from frontik.util import gather_dict -@router.get('/async_group/group', cls=PageHandler) +@plain_router.get('/async_group/group', cls=PageHandler) async def get_page(handler: PageHandler = get_current_handler()) -> None: fail_callback = handler.get_query_argument('fail_callback', 'false') == 'true' fail_request = handler.get_query_argument('fail_request', 'false') == 'true' @@ -37,7 +37,7 @@ async def task() -> Any: handler.json.put({'final_callback_called': True}) -@router.post('/async_group/group', cls=PageHandler) +@plain_router.post('/async_group/group', cls=PageHandler) async def post_page(handler=get_current_handler()): data = handler.get_query_argument('data', None) if data is None: diff --git a/tests/projects/test_app/pages/async_group/group_with_futures.py b/tests/projects/test_app/pages/async_group/group_with_futures.py index ef6dc8567..2bc89962c 100644 --- a/tests/projects/test_app/pages/async_group/group_with_futures.py +++ b/tests/projects/test_app/pages/async_group/group_with_futures.py @@ -1,11 +1,11 @@ from tornado.concurrent import Future from frontik.handler import PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router from frontik.util import gather_dict -@router.get('/async_group/group_with_futures', cls=PageHandler) +@plain_router.get('/async_group/group_with_futures', cls=PageHandler) async def get_page(handler=get_current_handler()): future: Future = Future() diff --git a/tests/projects/test_app/pages/async_group/not_waited_failed_requests.py b/tests/projects/test_app/pages/async_group/not_waited_failed_requests.py index 719d46f38..cb96a3c4d 100644 --- a/tests/projects/test_app/pages/async_group/not_waited_failed_requests.py +++ b/tests/projects/test_app/pages/async_group/not_waited_failed_requests.py @@ -1,5 +1,5 @@ from frontik.handler import PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router class Page(PageHandler): @@ -11,7 +11,7 @@ def _record_failed_request(self, data: dict) -> None: raise ValueError(msg) -@router.get('/async_group/not_waited_failed_requests', cls=Page) +@plain_router.get('/async_group/not_waited_failed_requests', cls=Page) async def get_page(handler: Page = get_current_handler()) -> None: if not handler.data: host = handler.request.headers.get('host', '') @@ -27,21 +27,21 @@ async def get_page(handler: Page = get_current_handler()) -> None: handler.data = {} -@router.post('/async_group/not_waited_failed_requests', cls=Page) +@plain_router.post('/async_group/not_waited_failed_requests', cls=Page) async def post_page(handler: Page = get_current_handler()) -> None: handler._record_failed_request({'post_failed': True}) -@router.put('/async_group/not_waited_failed_requests', cls=Page) +@plain_router.put('/async_group/not_waited_failed_requests', cls=Page) async def put_page(handler: Page = get_current_handler()) -> None: handler._record_failed_request({'put_failed': True}) -@router.delete('/async_group/not_waited_failed_requests', cls=Page) +@plain_router.delete('/async_group/not_waited_failed_requests', cls=Page) async def delete_page(handler: Page = get_current_handler()) -> None: handler._record_failed_request({'delete_failed': True}) -@router.head('/async_group/not_waited_failed_requests', cls=Page) +@plain_router.head('/async_group/not_waited_failed_requests', cls=Page) async def head_page(handler: Page = get_current_handler()) -> None: handler._record_failed_request({'head_failed': True}) diff --git a/tests/projects/test_app/pages/async_group/not_waited_requests.py b/tests/projects/test_app/pages/async_group/not_waited_requests.py index 1991d78d2..108c6a425 100644 --- a/tests/projects/test_app/pages/async_group/not_waited_requests.py +++ b/tests/projects/test_app/pages/async_group/not_waited_requests.py @@ -1,7 +1,7 @@ import asyncio from frontik.handler import AbortAsyncGroup, PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router class Page(PageHandler): @@ -21,7 +21,7 @@ def record_request(self, data: dict) -> None: Page.data.update(data) -@router.get('/async_group/not_waited_requests', cls=Page) +@plain_router.get('/async_group/not_waited_requests', cls=Page) async def get_page(handler: Page = get_current_handler()) -> None: if not handler.data: handler.json.put({'get': True}) @@ -34,16 +34,16 @@ async def get_page(handler: Page = get_current_handler()) -> None: handler.data = {} -@router.post('/async_group/not_waited_requests', cls=Page) +@plain_router.post('/async_group/not_waited_requests', cls=Page) async def post_page(handler=get_current_handler()): handler.record_request({'post_made': True}) -@router.put('/async_group/not_waited_requests', cls=Page) +@plain_router.put('/async_group/not_waited_requests', cls=Page) async def put_page(handler=get_current_handler()): handler.record_request({'put_made': True}) -@router.delete('/async_group/not_waited_requests', cls=Page) +@plain_router.delete('/async_group/not_waited_requests', cls=Page) async def delete_page(handler=get_current_handler()): handler.record_request({'delete_made': True}) diff --git a/tests/projects/test_app/pages/broken_workflow.py b/tests/projects/test_app/pages/broken_workflow.py index 27352ef2e..79166e0b9 100644 --- a/tests/projects/test_app/pages/broken_workflow.py +++ b/tests/projects/test_app/pages/broken_workflow.py @@ -1,11 +1,11 @@ from tornado.web import HTTPError from frontik.handler import PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router from frontik.util import gather_list -@router.get('/broken_workflow', cls=PageHandler) +@plain_router.get('/broken_workflow', cls=PageHandler) async def get_page(handler=get_current_handler()): port = int(handler.get_query_argument('port')) diff --git a/tests/projects/test_app/pages/cdata.py b/tests/projects/test_app/pages/cdata.py index c162bf050..8983833fd 100644 --- a/tests/projects/test_app/pages/cdata.py +++ b/tests/projects/test_app/pages/cdata.py @@ -1,12 +1,12 @@ from lxml import etree from frontik.handler import PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router CDATA_XML = b']]>' -@router.get('/cdata', cls=PageHandler) +@plain_router.get('/cdata', cls=PageHandler) async def get_page(handler=get_current_handler()): result = await handler.post_url(handler.get_header('host'), handler.path) @@ -17,7 +17,7 @@ async def get_page(handler=get_current_handler()): handler.doc.put(xpath) -@router.post('/cdata', cls=PageHandler) +@plain_router.post('/cdata', cls=PageHandler) async def post_page(handler=get_current_handler()): parser = etree.XMLParser(encoding='UTF-8', strip_cdata=False) root = etree.XML(CDATA_XML, parser) diff --git a/tests/projects/test_app/pages/compose_doc.py b/tests/projects/test_app/pages/compose_doc.py index 609e18a31..e65f2ab74 100644 --- a/tests/projects/test_app/pages/compose_doc.py +++ b/tests/projects/test_app/pages/compose_doc.py @@ -3,10 +3,10 @@ from frontik import media_types from frontik.doc import Doc from frontik.handler import PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router -@router.get('/compose_doc', cls=PageHandler) +@plain_router.get('/compose_doc', cls=PageHandler) async def get_page(handler=get_current_handler()): invalid_xml = handler.get_query_argument('invalid', 'false') @@ -16,7 +16,7 @@ async def get_page(handler=get_current_handler()): handler.doc.put(Doc('c')) -@router.post('/compose_doc', cls=PageHandler) +@plain_router.post('/compose_doc', cls=PageHandler) async def post_page(handler=get_current_handler()): invalid_xml = handler.get_body_argument('invalid', 'false') == 'true' diff --git a/tests/projects/test_app/pages/debug.py b/tests/projects/test_app/pages/debug.py index 451106f34..95913ee0f 100644 --- a/tests/projects/test_app/pages/debug.py +++ b/tests/projects/test_app/pages/debug.py @@ -2,10 +2,10 @@ from frontik import media_types from frontik.handler import PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router -@router.get('/debug', cls=PageHandler) +@plain_router.get('/debug', cls=PageHandler) async def get_page(handler=get_current_handler()): handler.log.debug('debug: starting debug page') @@ -46,14 +46,14 @@ def _inner() -> None: handler.log.debug('testing unicode text output', extra={'_text': 'some\nmultiline\nюникод\ndebug'}) -@router.post('/debug', cls=PageHandler) +@plain_router.post('/debug', cls=PageHandler) async def post_page(handler=get_current_handler()): handler.log.debug('this page returns json') handler.json.put({'param1': 'value', 'param2': 'тест', 'тест': 'value'}) -@router.put('/debug', cls=PageHandler) +@plain_router.put('/debug', cls=PageHandler) async def put_page(handler=get_current_handler()): content_type = handler.get_query_argument('type') diff --git a/tests/projects/test_app/pages/error_yield.py b/tests/projects/test_app/pages/error_yield.py index b8d9766c9..56be67dd9 100644 --- a/tests/projects/test_app/pages/error_yield.py +++ b/tests/projects/test_app/pages/error_yield.py @@ -1,13 +1,13 @@ from frontik.handler import PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router -@router.get('/error_yield', cls=PageHandler) +@plain_router.get('/error_yield', cls=PageHandler) async def get_page(handler=get_current_handler()): await handler.post_url(handler.get_header('host'), handler.path) return 1 / 0 -@router.post('/error_yield', cls=PageHandler) +@plain_router.post('/error_yield', cls=PageHandler) async def post_page(handler=get_current_handler()): handler.text = 'result' diff --git a/tests/projects/test_app/pages/fail_fast/__init__.py b/tests/projects/test_app/pages/fail_fast/__init__.py index 069f98113..0fb90ef3a 100644 --- a/tests/projects/test_app/pages/fail_fast/__init__.py +++ b/tests/projects/test_app/pages/fail_fast/__init__.py @@ -1,7 +1,7 @@ from fastapi import Depends from frontik.handler import HTTPErrorWithPostprocessors, PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router from frontik.util import gather_dict @@ -20,7 +20,7 @@ def get_page_fail_fast(self, failed_future): self.finish_with_postprocessors() -@router.get('/fail_fast', cls=Page, dependencies=[Depends(get_page_preprocessor)]) +@plain_router.get('/fail_fast', cls=Page, dependencies=[Depends(get_page_preprocessor)]) async def get_page(handler=get_current_handler()): fail_fast = handler.get_query_argument('fail_fast', 'false') == 'true' @@ -46,7 +46,7 @@ async def get_page(handler=get_current_handler()): handler.json.put(results) -@router.post('/fail_fast', cls=Page) +@plain_router.post('/fail_fast', cls=Page) async def post_page(handler=get_current_handler()): if handler.get_query_argument('fail_fast_default', 'false') == 'true': results = await gather_dict({ @@ -62,14 +62,14 @@ async def post_page(handler=get_current_handler()): handler.json.put({'POST': handler.get_body_argument('param')}) -@router.put('/fail_fast', cls=Page) +@plain_router.put('/fail_fast', cls=Page) async def put_page(handler=get_current_handler()): # Testing parse_on_error=True handler.json.put({'error': 'forbidden'}) raise HTTPErrorWithPostprocessors(int(handler.get_query_argument('code'))) -@router.delete('/fail_fast', cls=Page) +@plain_router.delete('/fail_fast', cls=Page) async def delete_page(handler=get_current_handler()): # Testing invalid return values if handler.get_query_argument('invalid_dict_value', 'false') == 'true': diff --git a/tests/projects/test_app/pages/fail_fast/fail_fast_without_done.py b/tests/projects/test_app/pages/fail_fast/fail_fast_without_done.py index aef672cf0..b785cca15 100644 --- a/tests/projects/test_app/pages/fail_fast/fail_fast_without_done.py +++ b/tests/projects/test_app/pages/fail_fast/fail_fast_without_done.py @@ -1,7 +1,7 @@ from tornado.web import HTTPError from frontik.handler import PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router class Page(PageHandler): @@ -9,11 +9,11 @@ def get_page_fail_fast(self, failed_future): raise HTTPError(401) -@router.get('/fail_fast/fail_fast_without_done', cls=Page) +@plain_router.get('/fail_fast/fail_fast_without_done', cls=Page) async def get_page(handler=get_current_handler()): await handler.post_url(handler.get_header('host'), handler.path, fail_fast=True) -@router.post('/fail_fast/fail_fast_without_done', cls=Page) +@plain_router.post('/fail_fast/fail_fast_without_done', cls=Page) async def post_page(): raise HTTPError(403) diff --git a/tests/projects/test_app/pages/fail_fast/future.py b/tests/projects/test_app/pages/fail_fast/future.py index d8e2e19fb..9e38a012c 100644 --- a/tests/projects/test_app/pages/fail_fast/future.py +++ b/tests/projects/test_app/pages/fail_fast/future.py @@ -4,7 +4,7 @@ from tornado.concurrent import Future from frontik.handler import PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router from frontik.util import gather_dict @@ -27,7 +27,7 @@ def _finish_future(): return future -@router.get('/fail_fast/future', cls=Page) +@plain_router.get('/fail_fast/future', cls=Page) async def get_page(handler=get_current_handler()): fail_future = handler.get_query_argument('fail_future', 'false') == 'true' diff --git a/tests/projects/test_app/pages/fail_fast/with_postprocessors.py b/tests/projects/test_app/pages/fail_fast/with_postprocessors.py index fc3e0136e..9c60b5c86 100644 --- a/tests/projects/test_app/pages/fail_fast/with_postprocessors.py +++ b/tests/projects/test_app/pages/fail_fast/with_postprocessors.py @@ -1,7 +1,7 @@ from tornado.web import HTTPError from frontik.handler import HTTPErrorWithPostprocessors, PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router class Page(PageHandler): @@ -10,12 +10,12 @@ def get_page_fail_fast(self, failed_future): raise HTTPErrorWithPostprocessors(502) -@router.get('/fail_fast/with_postprocessors', cls=Page) +@plain_router.get('/fail_fast/with_postprocessors', cls=Page) async def get_page(handler=get_current_handler()): result = await handler.post_url(handler.get_header('host'), handler.path, fail_fast=True) handler.json.put(result.data) -@router.post('/fail_fast/with_postprocessors', cls=Page) +@plain_router.post('/fail_fast/with_postprocessors', cls=Page) async def post_page(): raise HTTPError(403) diff --git a/tests/projects/test_app/pages/finish.py b/tests/projects/test_app/pages/finish.py index fe24485ea..9bda0c3d7 100644 --- a/tests/projects/test_app/pages/finish.py +++ b/tests/projects/test_app/pages/finish.py @@ -1,8 +1,8 @@ from frontik.handler import PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router -@router.get('/finish', cls=PageHandler) +@plain_router.get('/finish', cls=PageHandler) async def get_page(handler=get_current_handler()): code = int(handler.get_query_argument('code', '200')) diff --git a/tests/projects/test_app/pages/finish_204.py b/tests/projects/test_app/pages/finish_204.py index 3dcfc40fa..6721edda8 100644 --- a/tests/projects/test_app/pages/finish_204.py +++ b/tests/projects/test_app/pages/finish_204.py @@ -1,8 +1,8 @@ from frontik.handler import PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router -@router.get('/finish_204', cls=PageHandler) +@plain_router.get('/finish_204', cls=PageHandler) async def get_page(handler: PageHandler = get_current_handler()) -> None: handler.text = 'data' handler.set_status(204) diff --git a/tests/projects/test_app/pages/finish_with_postprocessors.py b/tests/projects/test_app/pages/finish_with_postprocessors.py index 8c3c193d6..353c0cfc3 100644 --- a/tests/projects/test_app/pages/finish_with_postprocessors.py +++ b/tests/projects/test_app/pages/finish_with_postprocessors.py @@ -2,7 +2,7 @@ from tornado.web import HTTPError from frontik.handler import FinishWithPostprocessors, PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router class Page(PageHandler): @@ -15,7 +15,7 @@ def pp(handler): self.add_postprocessor(pp) -@router.get('/finish_with_postprocessors', cls=Page) +@plain_router.get('/finish_with_postprocessors', cls=Page) async def get_page(handler=get_current_handler()): content_type = handler.get_query_argument('type') @@ -38,6 +38,6 @@ async def fail_request() -> None: raise FinishWithPostprocessors() -@router.post('/finish_with_postprocessors', cls=Page) +@plain_router.post('/finish_with_postprocessors', cls=Page) async def post_page(): pass diff --git a/tests/projects/test_app/pages/handler/delete.py b/tests/projects/test_app/pages/handler/delete.py index c6c940c98..0f655c8ca 100644 --- a/tests/projects/test_app/pages/handler/delete.py +++ b/tests/projects/test_app/pages/handler/delete.py @@ -2,10 +2,10 @@ from frontik.balancing_client import HttpClientT from frontik.json_builder import JsonBuilderT -from frontik.routing import router +from frontik.routing import plain_router -@router.get('/handler/delete') +@plain_router.get('/handler/delete') async def get_page(request: Request, http_client: HttpClientT, json_builder: JsonBuilderT) -> None: result = await http_client.delete_url( 'http://' + request.headers.get('host', ''), request.url.path, data={'data': 'true'} @@ -14,13 +14,13 @@ async def get_page(request: Request, http_client: HttpClientT, json_builder: Jso json_builder.put(result.data) -@router.post('/handler/delete') +@plain_router.post('/handler/delete') async def post_page(request: Request, http_client: HttpClientT, json_builder: JsonBuilderT) -> None: result = await http_client.delete_url('http://backend', request.url.path, fail_fast=True) if not result.failed: json_builder.put(result.data) -@router.delete('/handler/delete') +@plain_router.delete('/handler/delete') async def delete_page(data: str, json_builder: JsonBuilderT) -> None: json_builder.put({'delete': data}) diff --git a/tests/projects/test_app/pages/handler/head.py b/tests/projects/test_app/pages/handler/head.py index 5b056e00b..d8ef47308 100644 --- a/tests/projects/test_app/pages/handler/head.py +++ b/tests/projects/test_app/pages/handler/head.py @@ -1,8 +1,8 @@ from frontik.handler import PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router -@router.head('/handler/head', cls=PageHandler) +@plain_router.head('/handler/head', cls=PageHandler) async def head_page(handler=get_current_handler()): handler.set_header('X-Foo', 'Bar') handler.text = 'response body must be empty for HEAD requests' diff --git a/tests/projects/test_app/pages/handler/head_url.py b/tests/projects/test_app/pages/handler/head_url.py index a63dc240b..2cdb04a10 100644 --- a/tests/projects/test_app/pages/handler/head_url.py +++ b/tests/projects/test_app/pages/handler/head_url.py @@ -1,10 +1,10 @@ import http.client from frontik.handler import PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router -@router.get('/handler/head_url', cls=PageHandler) +@plain_router.get('/handler/head_url', cls=PageHandler) async def get_page(handler: PageHandler = get_current_handler()) -> None: head_result = await handler.head_url(handler.request.headers.get('host', ''), '/handler/head', name='head') diff --git a/tests/projects/test_app/pages/handler/json.py b/tests/projects/test_app/pages/handler/json.py index b1d624567..88aa7585c 100644 --- a/tests/projects/test_app/pages/handler/json.py +++ b/tests/projects/test_app/pages/handler/json.py @@ -1,5 +1,5 @@ from frontik.handler import PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router class Page(PageHandler): @@ -7,11 +7,11 @@ def _page_handler(self) -> None: self.text = self.get_body_argument('foo') -@router.post('/handler/json', cls=Page) +@plain_router.post('/handler/json', cls=Page) async def post_page(handler=get_current_handler()): return handler._page_handler() -@router.put('/handler/json', cls=Page) +@plain_router.put('/handler/json', cls=Page) async def put_page(handler=get_current_handler()): return handler._page_handler() diff --git a/tests/projects/test_app/pages/handler/json_optional_args.py b/tests/projects/test_app/pages/handler/json_optional_args.py index db07df93b..0f3edd6e0 100644 --- a/tests/projects/test_app/pages/handler/json_optional_args.py +++ b/tests/projects/test_app/pages/handler/json_optional_args.py @@ -1,5 +1,5 @@ from frontik.handler import PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router class Page(PageHandler): @@ -7,11 +7,11 @@ def _page_handler(self) -> None: self.text = self.get_body_argument('foo', 'baz') -@router.post('/handler/json_optional_args', cls=Page) +@plain_router.post('/handler/json_optional_args', cls=Page) async def post_page(handler=get_current_handler()): return handler._page_handler() -@router.put('/handler/json_optional_args', cls=Page) +@plain_router.put('/handler/json_optional_args', cls=Page) async def put_page(handler=get_current_handler()): return handler._page_handler() diff --git a/tests/projects/test_app/pages/http_client/custom_headers.py b/tests/projects/test_app/pages/http_client/custom_headers.py index d82d86a57..7c3c4f5b6 100644 --- a/tests/projects/test_app/pages/http_client/custom_headers.py +++ b/tests/projects/test_app/pages/http_client/custom_headers.py @@ -1,5 +1,5 @@ from frontik.handler import PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router class Page(PageHandler): @@ -8,12 +8,12 @@ def modify_http_client_request(self, balanced_request): balanced_request.headers['X-Foo'] = 'Bar' -@router.get('/http_client/custom_headers', cls=Page) +@plain_router.get('/http_client/custom_headers', cls=Page) async def get_page(handler=get_current_handler()): result = await handler.post_url(handler.get_header('host'), handler.path) handler.json.put(result.data) -@router.post('/http_client/custom_headers', cls=Page) +@plain_router.post('/http_client/custom_headers', cls=Page) async def post_page(handler: Page = get_current_handler()): handler.json.put(handler.request.headers) diff --git a/tests/projects/test_app/pages/http_client/fibonacci.py b/tests/projects/test_app/pages/http_client/fibonacci.py index d9bf75f78..cc1e71275 100644 --- a/tests/projects/test_app/pages/http_client/fibonacci.py +++ b/tests/projects/test_app/pages/http_client/fibonacci.py @@ -2,10 +2,10 @@ from frontik import media_types from frontik.handler import PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router -@router.get('/http_client/fibonacci', cls=PageHandler) +@plain_router.get('/http_client/fibonacci', cls=PageHandler) async def get_page(handler=get_current_handler()): n = int(handler.get_query_argument('n')) diff --git a/tests/projects/test_app/pages/http_client/future.py b/tests/projects/test_app/pages/http_client/future.py index a08914af2..50fc814cf 100644 --- a/tests/projects/test_app/pages/http_client/future.py +++ b/tests/projects/test_app/pages/http_client/future.py @@ -1,10 +1,10 @@ import asyncio from frontik.handler import PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router -@router.get('/http_client/future', cls=PageHandler) +@plain_router.get('/http_client/future', cls=PageHandler) async def get_page(handler: PageHandler = get_current_handler()): state = { 'second_callback_must_be_async': True, @@ -28,6 +28,6 @@ async def make_request(): request_future.add_done_callback(handler.finish_group.add_future(additional_task)) -@router.post('/http_client/future', cls=PageHandler) +@plain_router.post('/http_client/future', cls=PageHandler) async def post_page(handler=get_current_handler()): handler.json.put({'yay': 'yay'}) diff --git a/tests/projects/test_app/pages/http_client/long_page_request.py b/tests/projects/test_app/pages/http_client/long_page_request.py index 2bd5762ae..e334ab6ef 100644 --- a/tests/projects/test_app/pages/http_client/long_page_request.py +++ b/tests/projects/test_app/pages/http_client/long_page_request.py @@ -1,5 +1,5 @@ from frontik.handler import PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router class Page(PageHandler): @@ -7,7 +7,7 @@ def request_callback(self, xml: str, error: bool) -> None: self.json.put({'error_received': bool(error)}) -@router.get('/http_client/long_page_request', cls=Page) +@plain_router.get('/http_client/long_page_request', cls=Page) async def get_page(handler=get_current_handler()): result = await handler.post_url(handler.get_header('host'), handler.path, request_timeout=0.5) handler.request_callback(result.data, result.failed) diff --git a/tests/projects/test_app/pages/http_client/parse_error.py b/tests/projects/test_app/pages/http_client/parse_error.py index d7a38a816..ec9180ae4 100644 --- a/tests/projects/test_app/pages/http_client/parse_error.py +++ b/tests/projects/test_app/pages/http_client/parse_error.py @@ -1,8 +1,8 @@ from frontik.handler import PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router -@router.get('/http_client/parse_error', cls=PageHandler) +@plain_router.get('/http_client/parse_error', cls=PageHandler) async def get_page(handler=get_current_handler()): el_result = await handler.post_url(handler.get_header('host'), handler.path + '?mode=xml') element = el_result.data @@ -18,7 +18,7 @@ async def get_page(handler=get_current_handler()): raise AssertionError() -@router.post('/http_client/parse_error', cls=PageHandler) +@plain_router.post('/http_client/parse_error', cls=PageHandler) async def post_page(handler=get_current_handler()): if handler.get_query_argument('mode') == 'xml': handler.text = """this is broken xml""" diff --git a/tests/projects/test_app/pages/http_client/parse_response.py b/tests/projects/test_app/pages/http_client/parse_response.py index 28c227d17..21a5fc91f 100644 --- a/tests/projects/test_app/pages/http_client/parse_response.py +++ b/tests/projects/test_app/pages/http_client/parse_response.py @@ -1,10 +1,10 @@ from tornado.escape import to_unicode from frontik.handler import HTTPErrorWithPostprocessors, PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router -@router.get('/http_client/parse_response', cls=PageHandler) +@plain_router.get('/http_client/parse_response', cls=PageHandler) async def get_page(handler=get_current_handler()): result = await handler.post_url(handler.get_header('host'), handler.path, parse_on_error=True) handler.json.put(result.data) @@ -16,18 +16,18 @@ async def get_page(handler=get_current_handler()): handler.json.put({'delete': to_unicode(result.data)}) -@router.post('/http_client/parse_response', cls=PageHandler) +@plain_router.post('/http_client/parse_response', cls=PageHandler) async def post_page(handler=get_current_handler()): handler.json.put({'post': True}) raise HTTPErrorWithPostprocessors(400) -@router.put('/http_client/parse_response', cls=PageHandler) +@plain_router.put('/http_client/parse_response', cls=PageHandler) async def put_page(handler=get_current_handler()): handler.json.put({'put': True}) raise HTTPErrorWithPostprocessors(400) -@router.delete('/http_client/parse_response', cls=PageHandler) +@plain_router.delete('/http_client/parse_response', cls=PageHandler) async def delete_page(handler=get_current_handler()): handler.text = 'deleted' diff --git a/tests/projects/test_app/pages/http_client/post_simple.py b/tests/projects/test_app/pages/http_client/post_simple.py index 9b8dd1303..be00e2555 100644 --- a/tests/projects/test_app/pages/http_client/post_simple.py +++ b/tests/projects/test_app/pages/http_client/post_simple.py @@ -1,15 +1,15 @@ from frontik import media_types from frontik.handler import PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router -@router.get('/http_client/post_simple', cls=PageHandler) +@plain_router.get('/http_client/post_simple', cls=PageHandler) async def get_page(handler=get_current_handler()): result = await handler.post_url(handler.get_header('host'), handler.path) handler.text = result.data -@router.post('/http_client/post_simple', cls=PageHandler) +@plain_router.post('/http_client/post_simple', cls=PageHandler) async def post_page(handler=get_current_handler()): handler.set_header('Content-Type', media_types.TEXT_PLAIN) handler.text = 'post_url success' diff --git a/tests/projects/test_app/pages/http_client/post_url.py b/tests/projects/test_app/pages/http_client/post_url.py index 422cec1b5..8e4fdd532 100644 --- a/tests/projects/test_app/pages/http_client/post_url.py +++ b/tests/projects/test_app/pages/http_client/post_url.py @@ -2,7 +2,7 @@ from typing import Any from frontik.handler import PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router from frontik.util import any_to_bytes, any_to_unicode FIELDS: dict[str, Any] = { @@ -24,14 +24,14 @@ } -@router.get('/http_client/post_url', cls=PageHandler) +@plain_router.get('/http_client/post_url', cls=PageHandler) async def get_page(handler=get_current_handler()): result = await handler.post_url(handler.get_header('host'), handler.path, data=FIELDS, files=FILES) if not result.failed: handler.json.put(result.data) -@router.post('/http_client/post_url', cls=PageHandler) +@plain_router.post('/http_client/post_url', cls=PageHandler) async def post_page(handler: PageHandler = get_current_handler()): errors_count = 0 body_parts = handler.request.body.split(b'\r\n--') diff --git a/tests/projects/test_app/pages/http_client/proxy_code.py b/tests/projects/test_app/pages/http_client/proxy_code.py index 2d25522d0..9cd0bd2ca 100644 --- a/tests/projects/test_app/pages/http_client/proxy_code.py +++ b/tests/projects/test_app/pages/http_client/proxy_code.py @@ -1,8 +1,8 @@ from frontik.handler import PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router -@router.get('/http_client/proxy_code', cls=PageHandler) +@plain_router.get('/http_client/proxy_code', cls=PageHandler) async def get_page(handler: PageHandler = get_current_handler()): result = await handler.get_url('http://127.0.0.1:' + handler.get_query_argument('port'), '') handler.finish(str(result.status_code)) diff --git a/tests/projects/test_app/pages/http_client/raise_error.py b/tests/projects/test_app/pages/http_client/raise_error.py index 7ddca3a22..5a206dee5 100644 --- a/tests/projects/test_app/pages/http_client/raise_error.py +++ b/tests/projects/test_app/pages/http_client/raise_error.py @@ -1,5 +1,5 @@ from frontik.handler import PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router class Page(PageHandler): @@ -8,6 +8,6 @@ def send_error(self, status_code=500, exc_info=None, **kwargs): self.finish('UnicodeEncodeError') -@router.get('/http_client/raise_error', cls=Page) +@plain_router.get('/http_client/raise_error', cls=Page) async def get_page(handler=get_current_handler()): await handler.post_url(handler.get_header('host'), '/a-вот') diff --git a/tests/projects/test_app/pages/http_error.py b/tests/projects/test_app/pages/http_error.py index 5d37d9cac..cccd991f9 100644 --- a/tests/projects/test_app/pages/http_error.py +++ b/tests/projects/test_app/pages/http_error.py @@ -1,10 +1,10 @@ from tornado.web import HTTPError from frontik.handler import PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router -@router.get('/http_error', cls=PageHandler) +@plain_router.get('/http_error', cls=PageHandler) async def get_page(handler=get_current_handler()): code = int(handler.get_query_argument('code', '200')) raise HTTPError(code) diff --git a/tests/projects/test_app/pages/include_xml.py b/tests/projects/test_app/pages/include_xml.py index f398b4cda..719806316 100644 --- a/tests/projects/test_app/pages/include_xml.py +++ b/tests/projects/test_app/pages/include_xml.py @@ -1,7 +1,7 @@ from frontik.handler import PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router -@router.get('/include_xml', cls=PageHandler) +@plain_router.get('/include_xml', cls=PageHandler) async def get_page(handler=get_current_handler()): handler.doc.put(handler.xml_from_file('aaa.xml')) diff --git a/tests/projects/test_app/pages/json_page.py b/tests/projects/test_app/pages/json_page.py index 388e5f0fc..3492c77a2 100644 --- a/tests/projects/test_app/pages/json_page.py +++ b/tests/projects/test_app/pages/json_page.py @@ -1,6 +1,6 @@ from frontik import media_types from frontik.handler import PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router from frontik.util import gather_dict @@ -16,7 +16,7 @@ def jinja_context_provider(handler): super().prepare() -@router.get('/json_page', cls=Page) +@plain_router.get('/json_page', cls=Page) async def get_page(handler: Page = get_current_handler()) -> None: invalid_json = handler.get_query_argument('invalid', 'false') @@ -35,7 +35,7 @@ async def get_page(handler: Page = get_current_handler()) -> None: handler.json.put(data) -@router.post('/json_page', cls=Page) +@plain_router.post('/json_page', cls=Page) async def post_page(handler=get_current_handler()): invalid_json = handler.get_body_argument('invalid', 'false') == 'true' diff --git a/tests/projects/test_app/pages/kafka.py b/tests/projects/test_app/pages/kafka.py index b8ea3d269..ee744172f 100644 --- a/tests/projects/test_app/pages/kafka.py +++ b/tests/projects/test_app/pages/kafka.py @@ -1,10 +1,10 @@ import asyncio from frontik.handler import PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router -@router.get('/kafka', cls=PageHandler) +@plain_router.get('/kafka', cls=PageHandler) async def get_page(handler=get_current_handler()): request_engine_builder = handler.application.http_client_factory.request_engine_builder request_engine_builder.kafka_producer.enable_for_request_id(handler.request_id) @@ -15,6 +15,6 @@ async def get_page(handler=get_current_handler()): handler.json.put(*request_engine_builder.kafka_producer.disable_and_get_data()) -@router.post('/kafka', cls=PageHandler) +@plain_router.post('/kafka', cls=PageHandler) async def post_page(handler=get_current_handler()): handler.set_status(500) diff --git a/tests/projects/test_app/pages/log.py b/tests/projects/test_app/pages/log.py index a5d2682fe..8284805bf 100644 --- a/tests/projects/test_app/pages/log.py +++ b/tests/projects/test_app/pages/log.py @@ -1,12 +1,12 @@ import logging from frontik.handler import PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router custom_logger = logging.getLogger('custom_logger') -@router.get('/log', cls=PageHandler) +@plain_router.get('/log', cls=PageHandler) async def get_page(handler=get_current_handler()): handler.log.debug('debug') handler.log.info('info') diff --git a/tests/projects/test_app/pages/mandatory_headers.py b/tests/projects/test_app/pages/mandatory_headers.py index aa5547bfd..f2bc912fa 100644 --- a/tests/projects/test_app/pages/mandatory_headers.py +++ b/tests/projects/test_app/pages/mandatory_headers.py @@ -1,10 +1,10 @@ from tornado.web import HTTPError from frontik.handler import PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router -@router.get('/mandatory_headers', cls=PageHandler) +@plain_router.get('/mandatory_headers', cls=PageHandler) async def get_page(handler=get_current_handler()): if handler.get_argument('test_mandatory_headers', None) is not None: handler.set_mandatory_header('TEST_HEADER', 'TEST_HEADER_VALUE') diff --git a/tests/projects/test_app/pages/nested/nested/nested.py b/tests/projects/test_app/pages/nested/nested/nested.py index 752092583..c5c40ba60 100644 --- a/tests/projects/test_app/pages/nested/nested/nested.py +++ b/tests/projects/test_app/pages/nested/nested/nested.py @@ -1,7 +1,7 @@ from frontik.handler import PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router -@router.get('/nested/nested/nested', cls=PageHandler) +@plain_router.get('/nested/nested/nested', cls=PageHandler) async def get_page(handler=get_current_handler()): handler.text = 'OK' diff --git a/tests/projects/test_app/pages/postprocess.py b/tests/projects/test_app/pages/postprocess.py index 2ffe65719..089b119d6 100644 --- a/tests/projects/test_app/pages/postprocess.py +++ b/tests/projects/test_app/pages/postprocess.py @@ -1,7 +1,7 @@ from tornado.web import HTTPError from frontik.handler import PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router class ContentPostprocessor: @@ -22,7 +22,7 @@ def _header_pp(self, tpl, meta_info): return tpl.replace('%%header%%', 'HEADER') -@router.get('/postprocess/', cls=Page) +@plain_router.get('/postprocess/', cls=Page) async def get_page(handler: Page = get_current_handler()) -> None: if handler.get_query_argument('raise_error', None) is not None: handler.add_postprocessor(handler._pp_1) diff --git a/tests/projects/test_app/pages/postprocess_xsl.py b/tests/projects/test_app/pages/postprocess_xsl.py index e88aaaedf..08b6b07c7 100644 --- a/tests/projects/test_app/pages/postprocess_xsl.py +++ b/tests/projects/test_app/pages/postprocess_xsl.py @@ -1,7 +1,7 @@ from lxml import etree from frontik.handler import PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router class Page(PageHandler): @@ -10,7 +10,7 @@ def extract_metainfo_pp(handler, _, meta_info): return ','.join(meta_info) -@router.get('/postprocess_xsl', cls=Page) +@plain_router.get('/postprocess_xsl', cls=Page) async def get_page(handler=get_current_handler()): handler.set_xsl('meta.xsl') handler.doc.put(etree.Element('ok', key=handler.get_query_argument('meta_key', ''))) diff --git a/tests/projects/test_app/pages/proxy_code.py b/tests/projects/test_app/pages/proxy_code.py index 9e1515ac8..6878dd349 100644 --- a/tests/projects/test_app/pages/proxy_code.py +++ b/tests/projects/test_app/pages/proxy_code.py @@ -1,8 +1,8 @@ from frontik.handler import PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router -@router.get('/proxy_code', cls=PageHandler) +@plain_router.get('/proxy_code', cls=PageHandler) async def get_page(handler=get_current_handler()): result = await handler.get_url('http://127.0.0.1:' + handler.get_query_argument('port'), '', request_timeout=0.1) diff --git a/tests/projects/test_app/pages/request_context.py b/tests/projects/test_app/pages/request_context.py index 93393a6cc..8749eeabf 100644 --- a/tests/projects/test_app/pages/request_context.py +++ b/tests/projects/test_app/pages/request_context.py @@ -7,7 +7,7 @@ from frontik import request_context from frontik.handler import PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router async def _callback(name: str, handler: PageHandler) -> None: @@ -26,7 +26,7 @@ def __repr__(self): return 'request_context' -@router.get('/request_context', cls=Page) +@plain_router.get('/request_context', cls=Page) async def get_page(request: Request, handler: Page = get_current_handler()) -> None: def _waited_callback(name: str, _task: Any) -> None: task = asyncio.create_task(_callback(name, handler)) @@ -49,6 +49,6 @@ async def make_request() -> None: future.add_done_callback(partial(_waited_callback, 'future')) -@router.post('/request_context', cls=Page) +@plain_router.post('/request_context', cls=Page) async def post_page(): pass diff --git a/tests/projects/test_app/pages/simple_xml.py b/tests/projects/test_app/pages/simple_xml.py index 2f3520ba3..af06765a4 100644 --- a/tests/projects/test_app/pages/simple_xml.py +++ b/tests/projects/test_app/pages/simple_xml.py @@ -3,10 +3,10 @@ import frontik.doc import frontik.handler from frontik.handler import PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router -@router.get('/simple_xml', cls=PageHandler) +@plain_router.get('/simple_xml', cls=PageHandler) async def get_page(handler=get_current_handler()): handler.doc.put(frontik.doc.Doc()) handler.doc.put(etree.Element('element', name='Test element')) diff --git a/tests/projects/test_app/pages/statsd.py b/tests/projects/test_app/pages/statsd.py index 54a163cab..24790c95d 100644 --- a/tests/projects/test_app/pages/statsd.py +++ b/tests/projects/test_app/pages/statsd.py @@ -1,8 +1,8 @@ from frontik.handler import PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router -@router.get('/statsd', cls=PageHandler) +@plain_router.get('/statsd', cls=PageHandler) async def get_page(handler=get_current_handler()): handler.statsd_client.count('count_metric', 10, tag1='tag1', tag2='tag2') handler.statsd_client.gauge('gauge_metric', 100, tag='tag3') diff --git a/tests/projects/test_app/pages/test_exception_json.py b/tests/projects/test_app/pages/test_exception_json.py index eadb4c78f..73ceb13e1 100644 --- a/tests/projects/test_app/pages/test_exception_json.py +++ b/tests/projects/test_app/pages/test_exception_json.py @@ -1,8 +1,8 @@ from frontik.handler import HTTPErrorWithPostprocessors, PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router -@router.get('/test_exception_json', cls=PageHandler) +@plain_router.get('/test_exception_json', cls=PageHandler) async def get_page(handler=get_current_handler()): handler.json.put({'reason': 'bad argument'}) raise HTTPErrorWithPostprocessors(400) diff --git a/tests/projects/test_app/pages/test_exception_text.py b/tests/projects/test_app/pages/test_exception_text.py index 307083755..255984afc 100644 --- a/tests/projects/test_app/pages/test_exception_text.py +++ b/tests/projects/test_app/pages/test_exception_text.py @@ -1,9 +1,9 @@ from frontik.handler import HTTPErrorWithPostprocessors, PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router from frontik.util import gather_list -@router.get('/test_exception_text', cls=PageHandler) +@plain_router.get('/test_exception_text', cls=PageHandler) async def get_page(handler=get_current_handler()): async def bad_post_requests() -> None: results = await gather_list( diff --git a/tests/projects/test_app/pages/validate_arguments.py b/tests/projects/test_app/pages/validate_arguments.py index 80863945c..725ed86db 100644 --- a/tests/projects/test_app/pages/validate_arguments.py +++ b/tests/projects/test_app/pages/validate_arguments.py @@ -3,7 +3,7 @@ from pydantic import field_validator from frontik.handler import PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router from frontik.validator import BaseValidationModel, Validators @@ -17,7 +17,7 @@ def check_string(cls, value): return 'customString' -@router.get('/validate_arguments', cls=PageHandler) +@plain_router.get('/validate_arguments', cls=PageHandler) async def get_page(handler=get_current_handler()): is_custom_model = handler.get_bool_argument('model', False) empty_default_str = handler.get_str_argument('str_arg_with_default', 'default') @@ -42,7 +42,7 @@ async def get_page(handler=get_current_handler()): }) -@router.post('/validate_arguments', cls=PageHandler) +@plain_router.post('/validate_arguments', cls=PageHandler) async def post_page(handler=get_current_handler()): str_body_arg = handler.get_str_argument('str_argument', 'default', from_body=True) int_body_arg = handler.get_int_argument('int_argument', 0, from_body=True) @@ -50,6 +50,6 @@ async def post_page(handler=get_current_handler()): handler.json.put({'str_body_arg': str_body_arg, 'int_body_arg': int_body_arg}) -@router.put('/validate_arguments', cls=PageHandler) +@plain_router.put('/validate_arguments', cls=PageHandler) async def put_page(handler=get_current_handler()): handler.get_str_argument('str_arg', 3) diff --git a/tests/projects/test_app/pages/write_after_finish.py b/tests/projects/test_app/pages/write_after_finish.py index 14dc31975..28a5fce18 100644 --- a/tests/projects/test_app/pages/write_after_finish.py +++ b/tests/projects/test_app/pages/write_after_finish.py @@ -1,7 +1,7 @@ import asyncio from frontik.handler import FinishWithPostprocessors, PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router class Page(PageHandler): @@ -25,13 +25,13 @@ async def _pp(cls, handler): handler.json.put({'postprocessor_completed': True}) -@router.get('/write_after_finish', cls=Page) +@plain_router.get('/write_after_finish', cls=Page) async def get_page(handler=get_current_handler()): await handler.post_url(handler.get_header('host'), handler.path) # test that postprocessors are scheduled only once raise FinishWithPostprocessors() -@router.post('/write_after_finish', cls=Page) +@plain_router.post('/write_after_finish', cls=Page) async def post_page(handler=get_current_handler()): handler.json.put({'counter': handler.counter_static}) diff --git a/tests/projects/test_app/pages/write_error.py b/tests/projects/test_app/pages/write_error.py index 6615fb964..ab0bfaca8 100644 --- a/tests/projects/test_app/pages/write_error.py +++ b/tests/projects/test_app/pages/write_error.py @@ -1,5 +1,5 @@ from frontik.handler import PageHandler -from frontik.routing import router +from frontik.routing import plain_router class Page(PageHandler): @@ -12,6 +12,6 @@ def write_error(self, status_code=500, **kwargs): self.finish_with_postprocessors() -@router.get('/write_error', cls=Page) +@plain_router.get('/write_error', cls=Page) async def get_page(): raise Exception('exception in handler') diff --git a/tests/projects/test_app/pages/xsl/apply_error.py b/tests/projects/test_app/pages/xsl/apply_error.py index 986c113af..a235d14e0 100644 --- a/tests/projects/test_app/pages/xsl/apply_error.py +++ b/tests/projects/test_app/pages/xsl/apply_error.py @@ -1,10 +1,10 @@ from lxml import etree from frontik.handler import PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router -@router.get('/xsl/apply_error', cls=PageHandler) +@plain_router.get('/xsl/apply_error', cls=PageHandler) async def get_page(handler=get_current_handler()): handler.set_xsl('apply_error.xsl') handler.doc.put(etree.Element('ok')) diff --git a/tests/projects/test_app/pages/xsl/parse_error.py b/tests/projects/test_app/pages/xsl/parse_error.py index 66d94175b..5252dfaad 100644 --- a/tests/projects/test_app/pages/xsl/parse_error.py +++ b/tests/projects/test_app/pages/xsl/parse_error.py @@ -1,10 +1,10 @@ from lxml import etree from frontik.handler import PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router -@router.get('/xsl/parse_error', cls=PageHandler) +@plain_router.get('/xsl/parse_error', cls=PageHandler) async def get_page(handler=get_current_handler()): handler.set_xsl('parse_error.xsl') handler.doc.put(etree.Element('ok')) diff --git a/tests/projects/test_app/pages/xsl/simple.py b/tests/projects/test_app/pages/xsl/simple.py index 46bc41b7b..bf04487ad 100644 --- a/tests/projects/test_app/pages/xsl/simple.py +++ b/tests/projects/test_app/pages/xsl/simple.py @@ -1,10 +1,10 @@ from lxml import etree from frontik.handler import HTTPErrorWithPostprocessors, PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router -@router.get('/xsl/simple', cls=PageHandler) +@plain_router.get('/xsl/simple', cls=PageHandler) async def get_page(handler=get_current_handler()): handler.set_xsl(handler.get_query_argument('template', 'simple.xsl')) handler.doc.put(etree.Element('ok')) diff --git a/tests/projects/test_app/pages/xsl/syntax_error.py b/tests/projects/test_app/pages/xsl/syntax_error.py index 3659ab191..e4f78c172 100644 --- a/tests/projects/test_app/pages/xsl/syntax_error.py +++ b/tests/projects/test_app/pages/xsl/syntax_error.py @@ -1,10 +1,10 @@ from lxml import etree from frontik.handler import PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router -@router.get('/xsl/syntax_error', cls=PageHandler) +@plain_router.get('/xsl/syntax_error', cls=PageHandler) async def get_page(handler=get_current_handler()): handler.set_xsl('syntax_error.xsl') handler.doc.put(etree.Element('ok')) diff --git a/tests/test_frontik_testing.py b/tests/test_frontik_testing.py index d09048647..726f5ba99 100644 --- a/tests/test_frontik_testing.py +++ b/tests/test_frontik_testing.py @@ -3,14 +3,14 @@ from frontik.app import FrontikApplication from frontik.handler import PageHandler, get_current_handler -from frontik.routing import router +from frontik.routing import plain_router from frontik.testing import FrontikTestBase from frontik.util import gather_list from tests import FRONTIK_ROOT from tests.projects.test_app.pages.handler import delete # noqa -@router.get('/sum_values', cls=PageHandler) +@plain_router.get('/sum_values', cls=PageHandler) async def sum_values_page(handler=get_current_handler()): handler.result = 0 service_host = handler.config.serviceHost @@ -25,7 +25,7 @@ async def sum_values_page(handler=get_current_handler()): handler.set_status(400) -@router.get('/config', cls=PageHandler) +@plain_router.get('/config', cls=PageHandler) async def check_config_page(handler=get_current_handler()): handler.text = handler.config.config_param diff --git a/tests/test_sentry_integration.py b/tests/test_sentry_integration.py index ad2245be6..80f03b448 100644 --- a/tests/test_sentry_integration.py +++ b/tests/test_sentry_integration.py @@ -9,7 +9,7 @@ from frontik.app import FrontikApplication from frontik.handler import PageHandler, get_current_handler from frontik.options import options -from frontik.routing import router +from frontik.routing import plain_router from frontik.testing import FrontikTestBase from tests.instances import frontik_re_app, frontik_test_app @@ -19,7 +19,7 @@ def initialize_sentry_logger(self): sentry_sdk.set_user({'id': '123456'}) -@router.get('/sentry_error', cls=Page) +@plain_router.get('/sentry_error', cls=Page) async def get_page(handler: Page = get_current_handler()) -> None: ip = handler.get_query_argument('ip', None) extra = handler.get_query_argument('extra_key', None) @@ -31,12 +31,12 @@ async def get_page(handler: Page = get_current_handler()) -> None: raise Exception('My_sentry_exception') -@router.post('/sentry_error', cls=Page) +@plain_router.post('/sentry_error', cls=Page) async def post_page(): raise HTTPError(500, 'my_HTTPError') -@router.put('/sentry_error', cls=Page) +@plain_router.put('/sentry_error', cls=Page) async def put_page(): sentry_sdk.set_extra('extra_key', 'extra_value') sentry_sdk.capture_message('sentry_message') diff --git a/tests/test_telemetry.py b/tests/test_telemetry.py index 0dfe4b612..b4111ef0a 100644 --- a/tests/test_telemetry.py +++ b/tests/test_telemetry.py @@ -15,7 +15,7 @@ from frontik.handler import PageHandler, get_current_handler from frontik.integrations.telemetry import FrontikIdGenerator, get_netloc from frontik.options import options -from frontik.routing import router +from frontik.routing import plain_router from frontik.testing import FrontikTestBase dummy_request = Request({'type': 'http'}) @@ -69,13 +69,13 @@ def test_get_netloc(self) -> None: assert 'ftp:' == get_netloc('ftp://hh.ru') -@router.get('/page_a', cls=PageHandler) +@plain_router.get('/page_a', cls=PageHandler) async def get_page_a(handler=get_current_handler()): res = await handler.get_url(handler.get_header('host'), '/page_b') handler.json.put(res) -@router.get('/page_b', cls=PageHandler) +@plain_router.get('/page_b', cls=PageHandler) async def get_page_b(handler=get_current_handler()): handler.json.put({})