cherrypy update

fixes #3348
This commit is contained in:
AdeHub
2024-12-07 19:56:21 +13:00
parent 94d62430a0
commit a09e91ff8a
28 changed files with 512 additions and 108 deletions
+14 -7
View File
@@ -137,7 +137,6 @@ from cherrypy.lib import httputil as _httputil
class CherryPyException(Exception):
"""A base class for CherryPy exceptions."""
pass
class InternalRedirect(CherryPyException):
@@ -150,6 +149,7 @@ class InternalRedirect(CherryPyException):
"""
def __init__(self, path, query_string=''):
"""Initialize the internal redirect exception."""
self.request = cherrypy.serving.request
self.query_string = query_string
@@ -202,6 +202,7 @@ class HTTPRedirect(CherryPyException):
"""The encoding when passed urls are not native strings."""
def __init__(self, urls, status=None, encoding=None):
"""Initialize the HTTP redirect exception."""
self.urls = abs_urls = [
# Note that urljoin will "do the right thing" whether url is:
# 1. a complete URL with host (e.g. "http://www.example.com/test")
@@ -227,7 +228,9 @@ class HTTPRedirect(CherryPyException):
@classproperty
def default_status(cls):
"""The default redirect status for the request.
"""Redirect status for the request.
This is the default handler.
RFC 2616 indicates a 301 response code fits our goal; however,
browser support for 301 is quite messy. Use 302/303 instead. See
@@ -242,8 +245,9 @@ class HTTPRedirect(CherryPyException):
return status
def set_response(self):
"""Modify cherrypy.response status, headers, and body to represent
self.
"""Modify ``cherrypy.response`` to represent ``self``.
Modifies status, headers, and body.
CherryPy uses this internally, but you can also use it to create
an HTTPRedirect object and set its output without *raising* the
@@ -366,6 +370,7 @@ class HTTPError(CherryPyException):
"""The HTTP Reason-Phrase string."""
def __init__(self, status=500, message=None):
"""Initialize an HTTP error."""
self.status = status
try:
self.code, self.reason, defaultmsg = _httputil.valid_status(status)
@@ -381,8 +386,9 @@ class HTTPError(CherryPyException):
CherryPyException.__init__(self, status, message)
def set_response(self):
"""Modify cherrypy.response status, headers, and body to represent
self.
"""Modify ``cherrypy.response`` to represent ``self``.
Modifies status, headers, and body.
CherryPy uses this internally, but you can also use it to create
an HTTPError object and set its output without *raising* the
@@ -408,6 +414,7 @@ class HTTPError(CherryPyException):
_be_ie_unfriendly(self.code)
def get_error_page(self, *args, **kwargs):
"""Compose an HTML page with error information."""
return get_error_page(*args, **kwargs)
def __call__(self):
@@ -432,6 +439,7 @@ class NotFound(HTTPError):
"""
def __init__(self, path=None):
"""Initialize an HTTP Not Found error."""
if path is None:
request = cherrypy.serving.request
path = request.script_name + request.path_info
@@ -600,7 +608,6 @@ def bare_error(extrabody=None):
is set in the body. If extrabody is a string, it will be appended
as-is to the body.
"""
# The whole point of this function is to be a last line-of-defense
# in handling errors. That is, it must not raise any errors itself;
# it cannot be allowed to fail. Therefore, don't add to it!