Fixed flake8 errors
This commit is contained in:
		| @@ -7,7 +7,7 @@ install: | ||||
| - python setup.py install | ||||
| - pip install flake8 | ||||
| - pip install pytest | ||||
| before_script: flake8 sanic | ||||
| before_script: flake8 --max-line-length=120 sanic | ||||
| script: py.test -v tests | ||||
| deploy: | ||||
|   provider: pypi | ||||
|   | ||||
| @@ -1,2 +1,4 @@ | ||||
| from .sanic import Sanic | ||||
| from .blueprints import Blueprint | ||||
|  | ||||
| __all__ = ['Sanic', 'Blueprint'] | ||||
|   | ||||
| @@ -53,7 +53,6 @@ class Blueprint: | ||||
|         """ | ||||
|         self.deferred_functions.append(func) | ||||
|  | ||||
|  | ||||
|     def make_setup_state(self, app, options): | ||||
|         """ | ||||
|         """ | ||||
| @@ -96,4 +95,3 @@ class Blueprint: | ||||
|             self.record(lambda s: s.add_exception(handler, *args, **kwargs)) | ||||
|             return handler | ||||
|         return decorator | ||||
|  | ||||
|   | ||||
| @@ -80,7 +80,7 @@ class Request: | ||||
|     @property | ||||
|     def files(self): | ||||
|         if self.parsed_files is None: | ||||
|             _ = self.form  # compute form to get files | ||||
|             self.form  # compute form to get files | ||||
|  | ||||
|         return self.parsed_files | ||||
|  | ||||
|   | ||||
| @@ -19,16 +19,16 @@ STATUS_CODES = { | ||||
| class HTTPResponse: | ||||
|     __slots__ = ('body', 'status', 'content_type', 'headers') | ||||
|  | ||||
|     def __init__(self, body=None, status=200, headers=[], content_type='text/plain', body_bytes=b''): | ||||
|     def __init__(self, body=None, status=200, headers=None, content_type='text/plain', body_bytes=b''): | ||||
|         self.content_type = content_type | ||||
|  | ||||
|         if not body is None: | ||||
|         if body is not None: | ||||
|             self.body = body.encode('utf-8') | ||||
|         else: | ||||
|             self.body = body_bytes | ||||
|  | ||||
|         self.status = status | ||||
|         self.headers = headers | ||||
|         self.headers = headers or {} | ||||
|  | ||||
|     def output(self, version="1.1", keep_alive=False, keep_alive_timeout=None): | ||||
|         # This is all returned in a kind-of funky way | ||||
| @@ -39,7 +39,10 @@ class HTTPResponse: | ||||
|  | ||||
|         headers = b'' | ||||
|         if self.headers: | ||||
|             headers = b''.join(b'%b: %b\r\n' % (name.encode(), value.encode('utf-8')) for name, value in self.headers.items()) | ||||
|             headers = b''.join( | ||||
|                 b'%b: %b\r\n' % (name.encode(), value.encode('utf-8')) | ||||
|                 for name, value in self.headers.items() | ||||
|             ) | ||||
|         return b'HTTP/%b %d %b\r\nContent-Type: %b\r\nContent-Length: %d\r\nConnection: %b\r\n%b%b\r\n%b' % ( | ||||
|             version.encode(), | ||||
|             self.status, | ||||
| @@ -52,6 +55,7 @@ class HTTPResponse: | ||||
|             self.body | ||||
|         ) | ||||
|  | ||||
|  | ||||
| def json(body, status=200, headers=None): | ||||
|     return HTTPResponse(ujson.dumps(body), headers=headers, status=status, | ||||
|                         content_type="application/json; charset=utf-8") | ||||
|   | ||||
| @@ -94,7 +94,7 @@ class Router: | ||||
|                 break | ||||
|  | ||||
|         if route: | ||||
|             if route.methods and not request.method in route.methods: | ||||
|             if route.methods and request.method not in route.methods: | ||||
|                 raise InvalidUsage("Method {} not allowed for URL {}".format(request.method, request.url), | ||||
|                                    status_code=405) | ||||
|             return route.handler, args, kwargs | ||||
| @@ -120,7 +120,7 @@ class SimpleRouter: | ||||
|     def get(self, request): | ||||
|         route = self.routes.get(request.url) | ||||
|         if route: | ||||
|             if route.methods and not request.method in route.methods: | ||||
|             if route.methods and request.method not in route.methods: | ||||
|                 raise InvalidUsage("Method {} not allowed for URL {}".format(request.method, request.url), | ||||
|                                    status_code=405) | ||||
|             return route.handler, [], {} | ||||
|   | ||||
| @@ -63,7 +63,6 @@ class Sanic: | ||||
|         Decorates and registers middleware to be called before a request | ||||
|         can either be called as @app.middleware or @app.middleware('request') | ||||
|         """ | ||||
|         middleware = None | ||||
|         attach_to = 'request' | ||||
|  | ||||
|         def register_middleware(middleware): | ||||
| @@ -80,11 +79,6 @@ class Sanic: | ||||
|             attach_to = args[0] | ||||
|             return register_middleware | ||||
|  | ||||
|         if isinstance(middleware, FunctionType): | ||||
|             middleware = Middleware(process_request=middleware) | ||||
|  | ||||
|         return middleware | ||||
|  | ||||
|     def register_blueprint(self, blueprint, **options): | ||||
|         """ | ||||
|         Registers a blueprint on the application. | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Channel Cat
					Channel Cat