Brad Bishop | f32f3c8 | 2015-11-09 14:43:12 -0500 | [diff] [blame^] | 1 | Index: bottle-0.12.9/bottle.py |
| 2 | =================================================================== |
| 3 | --- bottle-0.12.9.orig/bottle.py |
| 4 | +++ bottle-0.12.9/bottle.py |
| 5 | @@ -1721,8 +1721,10 @@ class JSONPlugin(object): |
| 6 | name = 'json' |
| 7 | api = 2 |
| 8 | |
| 9 | - def __init__(self, json_dumps=json_dumps): |
| 10 | + def __init__(self, json_dumps=json_dumps, **kw): |
| 11 | self.json_dumps = json_dumps |
| 12 | + self.json_kw = { x:y for x,y in kw.iteritems() \ |
| 13 | + if x in ['indent','sort_keys'] } |
| 14 | |
| 15 | def apply(self, callback, route): |
| 16 | dumps = self.json_dumps |
| 17 | @@ -1735,12 +1737,12 @@ class JSONPlugin(object): |
| 18 | |
| 19 | if isinstance(rv, dict): |
| 20 | #Attempt to serialize, raises exception on failure |
| 21 | - json_response = dumps(rv) |
| 22 | + json_response = dumps(rv, **self.json_kw) |
| 23 | #Set content type only if serialization succesful |
| 24 | response.content_type = 'application/json' |
| 25 | return json_response |
| 26 | elif isinstance(rv, HTTPResponse) and isinstance(rv.body, dict): |
| 27 | - rv.body = dumps(rv.body) |
| 28 | + rv.body = dumps(rv.body, **self.json_kw) |
| 29 | rv.content_type = 'application/json' |
| 30 | return rv |
| 31 | |