1from pprint import pformat
2from typing import Any, NoReturn
3
4from markupsafe import Markup, escape
5from plain.http import Response
6from plain.views.exceptions import ResponseException
7
8
9def dd(*objs: Any) -> NoReturn:
10 """
11 Dump and die.
12
13 Dump the object and raise a ResponseException with the dump as the response content.
14 """
15
16 print_objs = "\n".join([pformat(obj) for obj in objs])
17 print(f"Dumping objects:\n{print_objs}")
18
19 html_objs = [
20 Markup("<pre><code>") + escape(pformat(obj)) + Markup("</code></pre>")
21 for obj in objs
22 ]
23 combined_dump_str = Markup("\n\n").join(html_objs)
24
25 response = Response(combined_dump_str, status_code=500, content_type="text/html")
26 raise ResponseException(response)