fix flake8 error

This commit is contained in:
PandaFeeder 2017-05-13 22:31:06 +08:00
parent e9369b3381
commit a493bb86f9
2 changed files with 17 additions and 11 deletions

View File

@ -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
@ -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,

View File

@ -175,5 +175,6 @@ class ContentRangeError(SanicException):
class InvalidRangeType(ContentRangeError):
pass
class MiddlewareTypeError(Exception):
pass