From 5f79291b55f9ac9868486ccf05e9b1bf4c74a1ea Mon Sep 17 00:00:00 2001 From: Adam Hopkins Date: Tue, 26 Jan 2021 09:24:38 +0200 Subject: [PATCH] additional compat support --- sanic/router.py | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/sanic/router.py b/sanic/router.py index 4822301a..aef8aa82 100644 --- a/sanic/router.py +++ b/sanic/router.py @@ -1,6 +1,7 @@ from functools import lru_cache from sanic_routing import BaseRouter +from sanic_routing.route import Route from sanic.constants import HTTP_METHODS from sanic.log import logger @@ -21,9 +22,16 @@ class Router(BaseRouter): # TODO: Implement response # - args, # - endpoint, - # - ignore_body, - return handler, (), params, route.path, route.name, None, False + return ( + handler, + (), + params, + route.path, + route.name, + None, + route.ctx.ignore_body, + ) def add( self, @@ -35,10 +43,18 @@ class Router(BaseRouter): ignore_body=False, version=None, name=None, - ): + ) -> Route: # TODO: Implement # - host # - strict_slashes - # - version # - ignore_body - super().add(path=uri, handler=handler, methods=methods, name=name) + if version is not None: + version = str(version).strip("/").lstrip("v") + uri = "/".join([f"/v{version}", uri.lstrip("/")]) + + route = super().add( + path=uri, handler=handler, methods=methods, name=name + ) + route.ctx.ignore_body = ignore_body + + return route