Return encoded JSON if data is a dict, list, or tuple and content_type is application/json.
(self, data, content_type)
| 448 | return force_bytes(data, encoding=charset) |
| 449 | |
| 450 | def _encode_json(self, data, content_type): |
| 451 | """ |
| 452 | Return encoded JSON if data is a dict, list, or tuple and content_type |
| 453 | is application/json. |
| 454 | """ |
| 455 | should_encode = JSON_CONTENT_TYPE_RE.match(content_type) and isinstance( |
| 456 | data, (dict, list, tuple) |
| 457 | ) |
| 458 | return json.dumps(data, cls=self.json_encoder) if should_encode else data |
| 459 | |
| 460 | def _get_path(self, parsed): |
| 461 | path = unquote_to_bytes(parsed.path) |