debug and working stage--squash
This commit is contained in:
@@ -404,7 +404,7 @@ class Sanic(BaseSanic):
|
||||
|
||||
# find all the parameters we will need to build in the URL
|
||||
# matched_params = re.findall(self.router.parameter_pattern, uri)
|
||||
route.finalize_params()
|
||||
route.finalize()
|
||||
for params in route.params.values():
|
||||
# name, _type, pattern = self.router.parse_parameter_string(match)
|
||||
# we only want to match against each individual parameter
|
||||
@@ -552,7 +552,7 @@ class Sanic(BaseSanic):
|
||||
# Execute Handler
|
||||
# -------------------------------------------- #
|
||||
|
||||
request.uri_template = uri
|
||||
request.uri_template = f"/{uri}"
|
||||
if handler is None:
|
||||
raise ServerError(
|
||||
(
|
||||
@@ -561,7 +561,7 @@ class Sanic(BaseSanic):
|
||||
)
|
||||
)
|
||||
|
||||
request.endpoint = endpoint
|
||||
request.endpoint = request.name
|
||||
|
||||
# Run response handler
|
||||
response = handler(request, *args, **kwargs)
|
||||
@@ -1035,12 +1035,13 @@ class Sanic(BaseSanic):
|
||||
"""To be ASGI compliant, our instance must be a callable that accepts
|
||||
three arguments: scope, receive, send. See the ASGI reference for more
|
||||
details: https://asgi.readthedocs.io/en/latest/"""
|
||||
# raise Exception("call")
|
||||
self.asgi = True
|
||||
self.router.finalize()
|
||||
asgi_app = await ASGIApp.create(self, scope, receive, send)
|
||||
await asgi_app()
|
||||
|
||||
_asgi_single_callable = True # We conform to ASGI 3.0 single-callable
|
||||
# _asgi_single_callable = True # We conform to ASGI 3.0 single-callable
|
||||
|
||||
# -------------------------------------------------------------------- #
|
||||
# Configuration
|
||||
|
||||
@@ -131,6 +131,7 @@ class Lifespan:
|
||||
in sequence since the ASGI lifespan protocol only supports a single
|
||||
startup event.
|
||||
"""
|
||||
print(">>> starting up")
|
||||
self.asgi_app.sanic_app.router.finalize()
|
||||
listeners = self.asgi_app.sanic_app.listeners.get(
|
||||
"before_server_start", []
|
||||
@@ -191,6 +192,7 @@ class ASGIApp:
|
||||
async def create(
|
||||
cls, sanic_app, scope: ASGIScope, receive: ASGIReceive, send: ASGISend
|
||||
) -> "ASGIApp":
|
||||
raise Exception("create")
|
||||
instance = cls()
|
||||
instance.sanic_app = sanic_app
|
||||
instance.transport = MockTransport(scope, receive, send)
|
||||
@@ -204,6 +206,7 @@ class ASGIApp:
|
||||
]
|
||||
)
|
||||
instance.lifespan = Lifespan(instance)
|
||||
print(instance.lifespan)
|
||||
|
||||
if scope["type"] == "lifespan":
|
||||
await instance.lifespan(scope, receive, send)
|
||||
@@ -293,4 +296,5 @@ class ASGIApp:
|
||||
"""
|
||||
Handle the incoming request.
|
||||
"""
|
||||
print("......")
|
||||
await self.sanic_app.handle_request(self.request)
|
||||
|
||||
@@ -115,8 +115,7 @@ class Blueprint(BaseSanic):
|
||||
and self.strict_slashes is not None
|
||||
else future.strict_slashes
|
||||
)
|
||||
|
||||
print(uri, strict_slashes)
|
||||
name = app._generate_name(future.name)
|
||||
|
||||
apply_route = FutureRoute(
|
||||
future.handler,
|
||||
@@ -126,7 +125,7 @@ class Blueprint(BaseSanic):
|
||||
strict_slashes,
|
||||
future.stream,
|
||||
future.version or self.version,
|
||||
future.name,
|
||||
name,
|
||||
future.ignore_body,
|
||||
future.websocket,
|
||||
future.subprotocols,
|
||||
|
||||
@@ -29,6 +29,10 @@ class ExceptionMixin:
|
||||
nonlocal apply
|
||||
nonlocal exceptions
|
||||
|
||||
if isinstance(exceptions[0], list):
|
||||
exceptions = tuple(*exceptions)
|
||||
|
||||
print(handler, exceptions)
|
||||
future_exception = FutureException(handler, exceptions)
|
||||
self._future_exceptions.add(future_exception)
|
||||
if apply:
|
||||
|
||||
@@ -539,6 +539,7 @@ class RouteMixin:
|
||||
|
||||
def _generate_name(self, *objects) -> str:
|
||||
name = None
|
||||
|
||||
for obj in objects:
|
||||
if obj:
|
||||
if isinstance(obj, str):
|
||||
@@ -546,9 +547,12 @@ class RouteMixin:
|
||||
break
|
||||
|
||||
try:
|
||||
name = obj.__name__
|
||||
name = obj.name
|
||||
except AttributeError:
|
||||
continue
|
||||
try:
|
||||
name = obj.__name__
|
||||
except AttributeError:
|
||||
continue
|
||||
else:
|
||||
break
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ class Router(BaseRouter):
|
||||
DEFAULT_METHOD = "GET"
|
||||
ALLOWED_METHODS = HTTP_METHODS
|
||||
|
||||
# @lru_cache
|
||||
@lru_cache
|
||||
def get(self, request: Request):
|
||||
"""
|
||||
Retrieve a `Route` object containg the details about how to handle
|
||||
@@ -42,6 +42,12 @@ class Router(BaseRouter):
|
||||
except RoutingNotFound as e:
|
||||
raise NotFound("Requested URL {} not found".format(e.path))
|
||||
except NoMethod as e:
|
||||
print(
|
||||
"Method {} not allowed for URL {}".format(
|
||||
request.method, request.path
|
||||
),
|
||||
e.allowed_methods,
|
||||
)
|
||||
raise MethodNotSupported(
|
||||
"Method {} not allowed for URL {}".format(
|
||||
request.method, request.path
|
||||
@@ -175,8 +181,14 @@ class Router(BaseRouter):
|
||||
if not view_name:
|
||||
return None
|
||||
|
||||
name = self.ctx.app._generate_name(view_name)
|
||||
route = self.name_index.get(name)
|
||||
# TODO:
|
||||
# - Check blueprint naming, we shouldn't need to double check here
|
||||
# but it seems like blueprints are not receiving full names
|
||||
# probably need tocheck the blueprint registration func
|
||||
route = self.name_index.get(view_name)
|
||||
if not route:
|
||||
full_name = self.ctx.app._generate_name(view_name)
|
||||
route = self.name_index.get(full_name)
|
||||
|
||||
if not route:
|
||||
return None
|
||||
@@ -185,7 +197,16 @@ class Router(BaseRouter):
|
||||
|
||||
@property
|
||||
def routes_all(self):
|
||||
return {
|
||||
**self.static_routes,
|
||||
**self.dynamic_routes,
|
||||
}
|
||||
return self.routes
|
||||
|
||||
@property
|
||||
def routes_static(self):
|
||||
return self.static_routes
|
||||
|
||||
@property
|
||||
def routes_dynamic(self):
|
||||
return self.dynamic_routes
|
||||
|
||||
@property
|
||||
def routes_regex(self):
|
||||
return self.regex_routes
|
||||
|
||||
@@ -159,7 +159,7 @@ def register(
|
||||
# If we're not trying to match a file directly,
|
||||
# serve from the folder
|
||||
if not path.isfile(file_or_directory):
|
||||
uri += "/<file_uri:path>"
|
||||
uri += "/<file_uri>"
|
||||
|
||||
# special prefix for static files
|
||||
# if not static.name.startswith("_static_"):
|
||||
|
||||
Reference in New Issue
Block a user