From f34226425e3a2b50749e52f17e74b1bf40246043 Mon Sep 17 00:00:00 2001 From: Yun Xu Date: Sat, 22 Jul 2017 18:41:53 -0700 Subject: [PATCH 1/4] add jinja2-sanic --- docs/sanic/extensions.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/sanic/extensions.md b/docs/sanic/extensions.md index 92b61f8c..5643f4fc 100644 --- a/docs/sanic/extensions.md +++ b/docs/sanic/extensions.md @@ -24,3 +24,4 @@ A list of Sanic extensions created by the community. - [Sanic-RestPlus](https://github.com/ashleysommer/sanic-restplus): A port of Flask-RestPlus for Sanic. Full-featured REST API with SwaggerUI generation. - [sanic-transmute](https://github.com/yunstanford/sanic-transmute): A Sanic extension that generates APIs from python function and classes, and also generates Swagger UI/documentation automatically. - [pytest-sanic](https://github.com/yunstanford/pytest-sanic): A pytest plugin for Sanic. It helps you to test your code asynchronously. +- [jinja2-sanic](https://github.com/yunstanford/jinja2-sanic): a jinja2 template renderer for Sanic.([Documentation](http://jinja2-sanic.readthedocs.io/en/latest/)) From f50dc83829596110acf21c1057d22f3b2de63239 Mon Sep 17 00:00:00 2001 From: zyguan Date: Mon, 24 Jul 2017 01:37:36 +0800 Subject: [PATCH 2/4] handle keep-alive timeout gracefully --- sanic/server.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/sanic/server.py b/sanic/server.py index 2ee48688..f62ba654 100644 --- a/sanic/server.py +++ b/sanic/server.py @@ -139,8 +139,10 @@ class HttpProtocol(asyncio.Protocol): self._request_stream_task.cancel() if self._request_handler_task: self._request_handler_task.cancel() - exception = RequestTimeout('Request Timeout') - self.write_error(exception) + try: + raise RequestTimeout('Request Timeout') + except RequestTimeout as exception: + self.write_error(exception) # -------------------------------------------- # # Parsing @@ -317,6 +319,7 @@ class HttpProtocol(asyncio.Protocol): self.cleanup() def write_error(self, exception): + response = None try: response = self.error_handler.response(self.request, exception) version = self.request.version if self.request else '1.1' @@ -331,20 +334,23 @@ class HttpProtocol(asyncio.Protocol): from_error=True) finally: if self.has_log: - extra = { - 'status': response.status, - 'host': '', - 'request': str(self.request) + str(self.url) - } - if response and isinstance(response, HTTPResponse): + extra = dict() + if isinstance(response, HTTPResponse): + extra['status'] = response.status extra['byte'] = len(response.body) else: + extra['status'] = 0 extra['byte'] = -1 if self.request: extra['host'] = '%s:%d' % self.request.ip, extra['request'] = '%s %s' % (self.request.method, self.url) - netlog.info('', extra=extra) + else: + extra['host'] = 'UNKNOWN' + extra['request'] = 'nil' + if self.parser and not (self.keep_alive + and extra['status'] == 408): + netlog.info('', extra=extra) self.transport.close() def bail_out(self, message, from_error=False): From 621343112d13010a228b39766c3b805ae8bd8993 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karolis=20Ma=C5=BEukna?= Date: Tue, 25 Jul 2017 13:29:17 +0300 Subject: [PATCH 3/4] Fix typo in documentation --- docs/sanic/versioning.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/sanic/versioning.md b/docs/sanic/versioning.md index 85cbd278..ab6dab22 100644 --- a/docs/sanic/versioning.md +++ b/docs/sanic/versioning.md @@ -10,11 +10,11 @@ You can pass a version number to the routes directly. from sanic import response -@app.route('/text', verion=1) +@app.route('/text', version=1) def handle_request(request): return response.text('Hello world! Version 1') -@app.route('/text', verion=2) +@app.route('/text', version=2) def handle_request(request): return response.text('Hello world! Version 2') From 40776e5324f3d880e8b3c94cd0c5ebe786d41701 Mon Sep 17 00:00:00 2001 From: cclauss Date: Wed, 26 Jul 2017 12:44:30 +0200 Subject: [PATCH 4/4] Comment: F821 undefined name is done on purpose Comment helps readers and `# noqa` silences linters --- tests/test_exceptions_handler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_exceptions_handler.py b/tests/test_exceptions_handler.py index 006c2cc4..6a959382 100644 --- a/tests/test_exceptions_handler.py +++ b/tests/test_exceptions_handler.py @@ -24,7 +24,7 @@ def handler_3(request): @exception_handler_app.route('/4') def handler_4(request): - foo = bar + foo = bar # noqa -- F821 undefined name 'bar' is done to throw exception return text(foo)