From a811c84e9947a731bb54f55c90f5d0a10cb5886b Mon Sep 17 00:00:00 2001 From: ctlaltdefeat Date: Sat, 21 Jan 2017 22:40:34 +0200 Subject: [PATCH 1/2] allowed passing arguments to json response encoder --- sanic/response.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sanic/response.py b/sanic/response.py index 244bc1b3..9fc1b598 100644 --- a/sanic/response.py +++ b/sanic/response.py @@ -142,14 +142,15 @@ class HTTPResponse: return self._cookies -def json(body, status=200, headers=None): +def json(body, status=200, headers=None, **kwargs): """ Returns response object with body in json format. :param body: Response data to be serialized. :param status: Response code. :param headers: Custom Headers. + :param \**kwargs: Remaining arguments that are passed to the json encoder. """ - return HTTPResponse(json_dumps(body), headers=headers, status=status, + return HTTPResponse(json_dumps(body, **kwargs), headers=headers, status=status, content_type="application/json") From 592ee5f8394b27318573fd17fd084d4b39bb6421 Mon Sep 17 00:00:00 2001 From: ctlaltdefeat Date: Sat, 21 Jan 2017 23:02:02 +0200 Subject: [PATCH 2/2] fixed line length to satisfy travis --- sanic/response.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sanic/response.py b/sanic/response.py index 9fc1b598..c29a473e 100644 --- a/sanic/response.py +++ b/sanic/response.py @@ -150,8 +150,8 @@ def json(body, status=200, headers=None, **kwargs): :param headers: Custom Headers. :param \**kwargs: Remaining arguments that are passed to the json encoder. """ - return HTTPResponse(json_dumps(body, **kwargs), headers=headers, status=status, - content_type="application/json") + return HTTPResponse(json_dumps(body, **kwargs), headers=headers, + status=status, content_type="application/json") def text(body, status=200, headers=None):