From 2b10860c32a6a96dbb66199027480068b0d9b49a Mon Sep 17 00:00:00 2001 From: Sean Parsons Date: Sun, 25 Dec 2016 01:05:26 -0500 Subject: [PATCH] Added docstrings to sanic.response.py for issue 41 --- sanic/response.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/sanic/response.py b/sanic/response.py index 2c4c7f27..5031b1c8 100644 --- a/sanic/response.py +++ b/sanic/response.py @@ -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: