summaryrefslogtreecommitdiffstats
path: root/meta-phosphor/common/recipes-devtools/python/bottle/json-format.patch
blob: 9e754a996e526cdf0a78199ad512257490d2c1fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
Index: bottle-0.12.9/bottle.py
===================================================================
--- bottle-0.12.9.orig/bottle.py
+++ bottle-0.12.9/bottle.py
@@ -1721,8 +1721,10 @@ class JSONPlugin(object):
     name = 'json'
     api  = 2
 
-    def __init__(self, json_dumps=json_dumps):
+    def __init__(self, json_dumps=json_dumps, **kw):
         self.json_dumps = json_dumps
+        self.json_kw = { x:y for x,y in kw.iteritems() \
+                     if x in ['indent','sort_keys'] }
 
     def apply(self, callback, route):
         dumps = self.json_dumps
@@ -1735,12 +1737,12 @@ class JSONPlugin(object):
 
             if isinstance(rv, dict):
                 #Attempt to serialize, raises exception on failure
-                json_response = dumps(rv)
+                json_response = dumps(rv, **self.json_kw)
                 #Set content type only if serialization succesful
                 response.content_type = 'application/json'
                 return json_response
             elif isinstance(rv, HTTPResponse) and isinstance(rv.body, dict):
-                rv.body = dumps(rv.body)
+                rv.body = dumps(rv.body, **self.json_kw)
                 rv.content_type = 'application/json'
             return rv
 
OpenPOWER on IntegriCloud