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