Merge branch 'master' of github.com:channelcat/sanic into add_app_loop_safety

This commit is contained in:
Eli Uriegas 2017-02-17 07:10:59 -06:00
commit c75d484f23
4 changed files with 20 additions and 9 deletions

View File

@ -1,7 +1,7 @@
[run] [run]
branch = True branch = True
source = sanic, tests source = sanic
omit = site-packages omit = site-packages, sanic/utils.py
[html] [html]
directory = coverage directory = coverage

View File

@ -11,3 +11,4 @@ A list of Sanic extensions created by the community.
- [Pagination](https://github.com/lixxu/python-paginate): Simple pagination support. - [Pagination](https://github.com/lixxu/python-paginate): Simple pagination support.
- [Motor](https://github.com/lixxu/sanic-motor): Simple motor wrapper. - [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. - [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

View File

@ -167,19 +167,26 @@ class HttpProtocol(asyncio.Protocol):
# -------------------------------------------- # # -------------------------------------------- #
def write_response(self, response): def write_response(self, response):
try:
keep_alive = ( keep_alive = (
self.parser.should_keep_alive() and not self.signal.stopped) self.parser.should_keep_alive() and not self.signal.stopped)
try:
self.transport.write( self.transport.write(
response.output( response.output(
self.request.version, keep_alive, self.request_timeout)) 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: except RuntimeError:
log.error( log.error(
'Connection lost before response written @ {}'.format( 'Connection lost before response written @ {}'.format(
self.request.ip)) self.request.ip))
except Exception as e: except Exception as e:
self.bail_out( self.bail_out(
"Writing response failed, connection closed {}".format(e)) "Writing response failed, connection closed {}".format(
repr(e)))
finally: finally:
if not keep_alive: if not keep_alive:
self.transport.close() self.transport.close()
@ -196,10 +203,10 @@ class HttpProtocol(asyncio.Protocol):
except RuntimeError: except RuntimeError:
log.error( log.error(
'Connection lost before error written @ {}'.format( 'Connection lost before error written @ {}'.format(
self.request.ip)) self.request.ip if self.request else 'Unknown'))
except Exception as e: except Exception as e:
self.bail_out( self.bail_out(
"Writing error failed, connection closed {}".format(e), "Writing error failed, connection closed {}".format(repr(e)),
from_error=True) from_error=True)
finally: finally:
self.transport.close() self.transport.close()

View File

@ -14,10 +14,13 @@ deps =
aiohttp aiohttp
pytest pytest
beautifulsoup4 beautifulsoup4
coverage
commands = commands =
pytest tests {posargs} pytest tests {posargs}
coverage erase
coverage run -m sanic.app
coverage report
[testenv:flake8] [testenv:flake8]
deps = deps =