(self, body: str, mime: str)
| 10 | self.enabled = self.format_options['json']['format'] |
| 11 | |
| 12 | def format_body(self, body: str, mime: str) -> str: |
| 13 | maybe_json = [ |
| 14 | 'json', |
| 15 | 'javascript', |
| 16 | 'text', |
| 17 | ] |
| 18 | if (self.kwargs['explicit_json'] |
| 19 | or any(token in mime for token in maybe_json)): |
| 20 | from ..utils import load_prefixed_json |
| 21 | try: |
| 22 | data_prefix, json_obj = load_prefixed_json(body) |
| 23 | except ValueError: |
| 24 | pass # Invalid JSON, ignore. |
| 25 | else: |
| 26 | # Indent, sort keys by name, and avoid |
| 27 | # unicode escapes to improve readability. |
| 28 | body = data_prefix + json.dumps( |
| 29 | obj=json_obj, |
| 30 | sort_keys=self.format_options['json']['sort_keys'], |
| 31 | ensure_ascii=False, |
| 32 | indent=self.format_options['json']['indent'] |
| 33 | ) |
| 34 | return body |
nothing calls this directly
no test coverage detected