Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/flask_restx/representations.py: 43%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

14 statements  

1try: 

2 from ujson import dumps 

3except ImportError: 

4 from json import dumps 

5 

6from flask import make_response, current_app 

7 

8 

9def output_json(data, code, headers=None): 

10 """Makes a Flask response with a JSON encoded body""" 

11 

12 settings = current_app.config.get("RESTX_JSON", {}) 

13 

14 # If we're in debug mode, and the indent is not set, we set it to a 

15 # reasonable value here. Note that this won't override any existing value 

16 # that was set. 

17 if current_app.debug: 

18 settings.setdefault("indent", 4) 

19 

20 # always end the json dumps with a new line 

21 # see https://github.com/mitsuhiko/flask/pull/1262 

22 dumped = dumps(data, **settings) + "\n" 

23 

24 resp = make_response(dumped, code) 

25 resp.headers.extend(headers or {}) 

26 return resp