Plain is headed towards 1.0! Subscribe for development updates →

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