def message_and_html_message(self) -> None: with assert_raises(ValueError): http_status_page( HTTPStatus.NOT_ACCEPTABLE, message="Test", html_message="HTML Test", )
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)
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 )
def default(self) -> None: html = http_status_page(HTTPStatus.NOT_ACCEPTABLE) assert_equal( """<!DOCTYPE html> <html> <head> <title>406 — Not Acceptable</title> </head> <body> <h1>406 — Not Acceptable</h1> </body> </html> """, html, )
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, )
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 []))], )
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 — Not Acceptable</title> </head> <body> <h1>406 — Not Acceptable</h1> <div>Test content.</div> </body> </html> """, html, )
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 — Not Acceptable</title> </head> <body> <h1>406 — Not Acceptable</h1> <p>Test <em>message</em>.</p> </body> </html> """, html, )