From 4fa568ce8a867d0aa0ec66f2c03efa588a4b3ddf Mon Sep 17 00:00:00 2001 From: Raphael Deem Date: Wed, 15 Feb 2017 15:20:43 -0800 Subject: [PATCH 1/5] add coverage to tox --- .coveragerc | 6 +++--- tox.ini | 5 ++++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.coveragerc b/.coveragerc index f4c5b83f..f0624d2e 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1,7 +1,7 @@ [run] branch = True -source = sanic, tests -omit = site-packages +source = sanic +omit = site-packages, sanic/utils.py [html] -directory = coverage \ No newline at end of file +directory = coverage diff --git a/tox.ini b/tox.ini index 4155e909..f14e2a1f 100644 --- a/tox.ini +++ b/tox.ini @@ -14,10 +14,13 @@ deps = aiohttp pytest beautifulsoup4 + coverage commands = pytest tests {posargs} - + coverage erase + coverage run -m sanic.sanic + coverage report [testenv:flake8] deps = From 04c8f4a5edc2c534ba4f43cf2867d214b99bd6cf Mon Sep 17 00:00:00 2001 From: Eli Uriegas Date: Thu, 16 Feb 2017 17:49:14 -0600 Subject: [PATCH 2/5] Adds some safety around response types being wrong Before we didn't check if the response object was actually a response object. This PR catches the exception should it happen and reports it to the user. --- sanic/server.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/sanic/server.py b/sanic/server.py index 99652fc9..67aa771e 100644 --- a/sanic/server.py +++ b/sanic/server.py @@ -167,12 +167,18 @@ class HttpProtocol(asyncio.Protocol): # -------------------------------------------- # def write_response(self, response): + keep_alive = ( + self.parser.should_keep_alive() and not self.signal.stopped) try: - keep_alive = ( - self.parser.should_keep_alive() and not self.signal.stopped) self.transport.write( response.output( self.request.version, keep_alive, self.request_timeout)) + except AttributeError: + log.error( + ('Invalid response object for url {}, ' + 'Expected Type: HTTPResponse, Actual Type: {}').format( + self.url, type(response))) + self.write_error(ServerError('Invalid response type')) except RuntimeError: log.error( 'Connection lost before response written @ {}'.format( From b44e8167d7f44bf06c450a2b577d2d82b065762a Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Fri, 10 Feb 2017 18:15:14 +0900 Subject: [PATCH 3/5] Enhance error logging - Prevent to fall into error logging recursion when it doesn't have request info (Print 'Unknown' when the request is still `None` - Print repr(e) rather than str(e) --- sanic/server.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/sanic/server.py b/sanic/server.py index 99652fc9..e58bb181 100644 --- a/sanic/server.py +++ b/sanic/server.py @@ -179,7 +179,8 @@ class HttpProtocol(asyncio.Protocol): self.request.ip)) except Exception as e: self.bail_out( - "Writing response failed, connection closed {}".format(e)) + "Writing response failed, connection closed {}".format( + repr(e))) finally: if not keep_alive: self.transport.close() @@ -196,10 +197,10 @@ class HttpProtocol(asyncio.Protocol): except RuntimeError: log.error( 'Connection lost before error written @ {}'.format( - self.request.ip)) + self.request.ip if self.request else 'Unknown')) except Exception as e: self.bail_out( - "Writing error failed, connection closed {}".format(e), + "Writing error failed, connection closed {}".format(repr(e)), from_error=True) finally: self.transport.close() From f553ca95a5c933ec9178223b2aa22abd3f179c0b Mon Sep 17 00:00:00 2001 From: Lix Xu Date: Fri, 17 Feb 2017 15:12:07 +0800 Subject: [PATCH 4/5] add user_agent to request --- docs/sanic/extensions.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/sanic/extensions.md b/docs/sanic/extensions.md index fe0f223a..efd25d2c 100644 --- a/docs/sanic/extensions.md +++ b/docs/sanic/extensions.md @@ -11,3 +11,4 @@ A list of Sanic extensions created by the community. - [Pagination](https://github.com/lixxu/python-paginate): Simple pagination support. - [Motor](https://github.com/lixxu/sanic-motor): Simple motor wrapper. - [Sanic CRUD](https://github.com/Typhon66/sanic_crud): CRUD REST API generation with peewee models. +- [UserAgent](https://github.com/lixxu/sanic-useragent): Add `user_agent` to request From a73379495fe1f60db3caeb18d651dc7f1e306ad3 Mon Sep 17 00:00:00 2001 From: Eli Uriegas Date: Fri, 17 Feb 2017 07:06:57 -0600 Subject: [PATCH 5/5] Fix coverage build Moved `sanic.py` to `app.py` this change reflects that --- tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index f14e2a1f..05276a43 100644 --- a/tox.ini +++ b/tox.ini @@ -19,7 +19,7 @@ deps = commands = pytest tests {posargs} coverage erase - coverage run -m sanic.sanic + coverage run -m sanic.app coverage report [testenv:flake8]