示例#1
0
文件: html.py 项目: srittau/rouver
 def message_and_html_message(self) -> None:
     with assert_raises(ValueError):
         http_status_page(
             HTTPStatus.NOT_ACCEPTABLE,
             message="Test",
             html_message="HTML Test",
         )
示例#2
0
def _respond_not_found(
    environment: WSGIEnvironment, start_response: StartResponse
) -> Iterable[bytes]:
    path = cast(str, environment.get("PATH_INFO", ""))
    message = "Path '{}' not found.".format(path)
    page = http_status_page(HTTPStatus.NOT_FOUND, message=message)
    return respond_with_html(start_response, page, status=HTTPStatus.NOT_FOUND)
示例#3
0
def _respond_internal_server_error(
    start_response: StartResponse,
) -> Iterable[bytes]:
    html = http_status_page(
        HTTPStatus.INTERNAL_SERVER_ERROR, message="Internal server error."
    )
    return respond_with_html(
        start_response, html, status=HTTPStatus.INTERNAL_SERVER_ERROR
    )
示例#4
0
文件: html.py 项目: srittau/rouver
    def default(self) -> None:
        html = http_status_page(HTTPStatus.NOT_ACCEPTABLE)
        assert_equal(
            """<!DOCTYPE html>
<html>
    <head>
        <title>406 &#x2014; Not Acceptable</title>
    </head>
    <body>
        <h1>406 &#x2014; Not Acceptable</h1>
    </body>
</html>
""",
            html,
        )
示例#5
0
def _respond_http_exception(
    start_response: StartResponse, exception: HTTPException
) -> Iterable[bytes]:
    assert exception.code is not None
    status = HTTPStatus(exception.code)
    html = http_status_page(status, message=exception.description or "")
    headers = [
        h for h in exception.get_headers() if h[0].lower() != "content-type"
    ]
    return respond_with_html(
        start_response,
        html,
        status=status,
        extra_headers=headers,
    )
示例#6
0
def _respond_method_not_allowed(
    start_response: StartResponse,
    method: str,
    allowed_methods: Iterable[str] | None,
) -> Iterable[bytes]:
    method_string = " or ".join(allowed_methods or [])
    message = "Method '{}' not allowed. Please try {}.".format(
        method, method_string
    )
    html = http_status_page(HTTPStatus.METHOD_NOT_ALLOWED, message=message)
    return respond_with_html(
        start_response,
        html,
        status=HTTPStatus.METHOD_NOT_ALLOWED,
        extra_headers=[("Allow", ", ".join(allowed_methods or []))],
    )
示例#7
0
文件: html.py 项目: srittau/rouver
    def html_content(self) -> None:
        html = http_status_page(HTTPStatus.NOT_ACCEPTABLE,
                                html_content="<div>Test content.</div>")
        assert_equal(
            """<!DOCTYPE html>
<html>
    <head>
        <title>406 &#x2014; Not Acceptable</title>
    </head>
    <body>
        <h1>406 &#x2014; Not Acceptable</h1>
<div>Test content.</div>
    </body>
</html>
""",
            html,
        )
示例#8
0
文件: html.py 项目: srittau/rouver
    def html_message(self) -> None:
        html = http_status_page(HTTPStatus.NOT_ACCEPTABLE,
                                html_message="Test <em>message</em>.")
        assert_equal(
            """<!DOCTYPE html>
<html>
    <head>
        <title>406 &#x2014; Not Acceptable</title>
    </head>
    <body>
        <h1>406 &#x2014; Not Acceptable</h1>
        <p>Test <em>message</em>.</p>
    </body>
</html>
""",
            html,
        )