Exemple #1
0
    def produce_response(self, request: Request, exc: Exception) -> Response:
        tb = traceback.format_exception(exc.__class__, exc, exc.__traceback__)
        info = ""
        for item in tb:
            info += f"<li><pre>{html.escape(item)}</pre></li>"

        content = HtmlContent(
            self._error_page_template.format_map({
                "info":
                info,
                "exctype":
                exc.__class__.__name__,
                "excmessage":
                str(exc),
                "method":
                request.method,
                "path":
                request.url.value.decode(),
                "full_url":
                get_request_url(request),
            }))

        return Response(500, content=content)
Exemple #2
0
def test_html_content_type():
    content = HtmlContent('<html></html>')
    assert content.type == b'text/html; charset=utf-8'
Exemple #3
0
def test_html_content_data(html):
    content = HtmlContent(html)
    assert content.body == html.encode('utf8')
Exemple #4
0
def test_html_content_type():
    content = HtmlContent("<html></html>")
    assert content.type == b"text/html; charset=utf-8"