From a493bb86f94543a80d9f12d47fcd722f6d6df083 Mon Sep 17 00:00:00 2001 From: PandaFeeder Date: Sat, 13 May 2017 22:31:06 +0800 Subject: [PATCH] fix flake8 error --- sanic/app.py | 25 +++++++++++++++---------- sanic/exceptions.py | 3 ++- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/sanic/app.py b/sanic/app.py index 5d4b8d20..792b3183 100644 --- a/sanic/app.py +++ b/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, diff --git a/sanic/exceptions.py b/sanic/exceptions.py index 79a522cc..a3477c71 100644 --- a/sanic/exceptions.py +++ b/sanic/exceptions.py @@ -175,5 +175,6 @@ class ContentRangeError(SanicException): class InvalidRangeType(ContentRangeError): pass + class MiddlewareTypeError(Exception): - pass \ No newline at end of file + pass