fix flake8 error
This commit is contained in:
parent
e9369b3381
commit
a493bb86f9
25
sanic/app.py
25
sanic/app.py
|
@ -12,7 +12,8 @@ from ssl import create_default_context, Purpose
|
|||
|
||||
from sanic.config import Config, LOGGING
|
||||
from sanic.constants import HTTP_METHODS
|
||||
from sanic.exceptions import ServerError, URLBuildError, SanicException, MiddlewareTypeError
|
||||
from sanic.exceptions import ServerError, URLBuildError, SanicException,\
|
||||
MiddlewareTypeError
|
||||
from sanic.handlers import ErrorHandler
|
||||
from sanic.log import log
|
||||
from sanic.response import HTTPResponse, StreamingHTTPResponse
|
||||
|
@ -136,7 +137,7 @@ class Sanic:
|
|||
vars(handler)['_'+r+'_middleware'] = tuple(mid)
|
||||
else:
|
||||
raise MiddlewareTypeError(
|
||||
"Middleware mounted on a handler should "
|
||||
"Middleware mounted on a handler should "
|
||||
"be a function or a sequence of functions"
|
||||
)
|
||||
|
||||
|
@ -481,8 +482,10 @@ class Sanic:
|
|||
if hasattr(handler, "_request_middleware"):
|
||||
mounted_request_middleware = handler._request_middleware
|
||||
if mounted_request_middleware:
|
||||
response = await self._handle_mounted_request_middleware(
|
||||
mounted_request_middleware, request, *args, **kwargs
|
||||
response = \
|
||||
await self._handle_mounted_request_middleware(
|
||||
mounted_request_middleware, request,
|
||||
*args, **kwargs
|
||||
)
|
||||
# No mounted request middleware result
|
||||
if not response:
|
||||
|
@ -498,11 +501,12 @@ class Sanic:
|
|||
if hasattr(handler, "_response_middleware"):
|
||||
mounted_response_middleware = handler._response_middleware
|
||||
if mounted_response_middleware:
|
||||
response = await self._handle_mounted_response_middleware(
|
||||
mounted_response_middleware, request, response, *args, **kwargs
|
||||
response = \
|
||||
await self._handle_mounted_response_middleware(
|
||||
mounted_response_middleware, request, response,
|
||||
*args, **kwargs
|
||||
)
|
||||
|
||||
|
||||
except Exception as e:
|
||||
# -------------------------------------------- #
|
||||
# Response Generation Failed
|
||||
|
@ -658,7 +662,8 @@ class Sanic:
|
|||
break
|
||||
return response
|
||||
|
||||
async def _handle_mounted_request_middleware(self, middleware, request, *args, **kwargs):
|
||||
async def _handle_mounted_request_middleware(self, middleware, request,
|
||||
*args, **kwargs):
|
||||
for mid in middleware:
|
||||
response = mid(request, *args, **kwargs)
|
||||
if isawaitable(response):
|
||||
|
@ -667,7 +672,8 @@ class Sanic:
|
|||
break
|
||||
return response
|
||||
|
||||
async def _handle_mounted_response_middleware(self, middleware, request, response, *args, **kwargs):
|
||||
async def _handle_mounted_response_middleware(self, middleware, request,
|
||||
response, *args, **kwargs):
|
||||
for mid in middleware:
|
||||
_response = mid(request, response, *args, **kwargs)
|
||||
if isawaitable(_response):
|
||||
|
@ -677,7 +683,6 @@ class Sanic:
|
|||
break
|
||||
return response
|
||||
|
||||
|
||||
def _helper(self, host="127.0.0.1", port=8000, debug=False,
|
||||
ssl=None, sock=None, workers=1, loop=None,
|
||||
protocol=HttpProtocol, backlog=100, stop_event=None,
|
||||
|
|
|
@ -175,5 +175,6 @@ class ContentRangeError(SanicException):
|
|||
class InvalidRangeType(ContentRangeError):
|
||||
pass
|
||||
|
||||
|
||||
class MiddlewareTypeError(Exception):
|
||||
pass
|
||||
pass
|
||||
|
|
Loading…
Reference in New Issue
Block a user