Added docstrings to sanic.response.py for issue 41

This commit is contained in:
Sean Parsons 2016-12-25 01:05:26 -05:00
parent a03f216f42
commit 2b10860c32

View File

@ -139,21 +139,45 @@ class HTTPResponse:
def json(body, status=200, headers=None):
"""
Returns serialized python object to json format.
:param body: Response data to be serialized.
:param status: Response code.
:param headers: Custom Headers.
"""
return HTTPResponse(json_dumps(body), headers=headers, status=status,
content_type="application/json")
def text(body, status=200, headers=None):
"""
Returns body in text format.
:param body: Response data to be encoded.
:param status: Response code.
:param headers: Custom Headers.
"""
return HTTPResponse(body, status=status, headers=headers,
content_type="text/plain; charset=utf-8")
def html(body, status=200, headers=None):
"""
Returns body in html format.
:param body: Response data to be encoded.
:param status: Response code.
:param headers: Custom Headers.
"""
return HTTPResponse(body, status=status, headers=headers,
content_type="text/html; charset=utf-8")
async def file(location, mime_type=None, headers=None):
"""
Returns file with mime_type.
:param location: Location of file on system.
:param mime_type: Specific mime_type.
:param headers: Custom Headers.
"""
filename = path.split(location)[-1]
async with open_async(location, mode='rb') as _file: