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
+33 -5
View File
@@ -42,6 +42,7 @@ class Hook(object):
callable on each call."""
def __init__(self, callback, failsafe=None, priority=None, **kwargs):
"""Initialize the hook instance."""
self.callback = callback
if failsafe is None:
@@ -55,7 +56,14 @@ class Hook(object):
self.kwargs = kwargs
def __lt__(self, other):
"""
"""Check if this hook's priority is lower than the other's.
:param other: Another object to compare priority with.
:type other: Hook
:returns: Whether the other Hook's priority is higher than this one's.
:rtype: bool
Hooks sort by priority, ascending, such that
hooks of lower priority are run first.
"""
@@ -66,6 +74,7 @@ class Hook(object):
return self.callback(**self.kwargs)
def __repr__(self):
"""Render a string representation of :class:`Hook` instance."""
cls = self.__class__
return ('%s.%s(callback=%r, failsafe=%r, priority=%r, %s)'
% (cls.__module__, cls.__name__, self.callback,
@@ -78,12 +87,14 @@ class HookMap(dict):
"""A map of call points to lists of callbacks (Hook objects)."""
def __new__(cls, points=None):
"""Construct a fresh hook map instance."""
d = dict.__new__(cls)
for p in points or []:
d[p] = []
return d
def __init__(self, *a, **kw):
"""Initialize a hook map instance post-construction."""
pass
def attach(self, point, callback, failsafe=None, priority=None, **kwargs):
@@ -124,6 +135,7 @@ class HookMap(dict):
raise
def __copy__(self):
"""Duplicate object per the copy protocol."""
newmap = self.__class__()
# We can't just use 'update' because we want copies of the
# mutable values (each is a list) as well.
@@ -133,6 +145,7 @@ class HookMap(dict):
copy = __copy__
def __repr__(self):
"""Render a string representation of :class:`HookMap`."""
cls = self.__class__
return '%s.%s(points=%r)' % (
cls.__module__,
@@ -541,7 +554,9 @@ class Request(object):
self.stage = 'close'
def run(self, method, path, query_string, req_protocol, headers, rfile):
r"""Process the Request. (Core)
r"""Process the request.
*(core)*
method, path, query_string, and req_protocol should be pulled directly
from the Request-Line (e.g. "GET /path?key=val HTTP/1.0").
@@ -815,6 +830,7 @@ class ResponseBody(object):
'if you wish to return unicode.')
def __get__(self, obj, objclass=None):
"""Return a response body through the descriptor protocol."""
if obj is None:
# When calling on the class instead of an instance...
return self
@@ -822,7 +838,10 @@ class ResponseBody(object):
return obj._body
def __set__(self, obj, value):
# Convert the given value to an iterable object.
"""Set a response body through the descriptor protocol.
Convert the given value to an iterable object.
"""
if isinstance(value, str):
raise ValueError(self.unicode_err)
elif isinstance(value, list):
@@ -874,6 +893,7 @@ class Response(object):
"""If False, buffer the response body."""
def __init__(self):
"""Intialize the HTTP response instance."""
self.status = None
self.header_list = None
self._body = []
@@ -896,8 +916,14 @@ class Response(object):
return new_body
def _flush_body(self):
"""Discard self.body but consume any generator such that any
finalization can occur, such as is required by caching.tee_output()."""
"""Exhaust the body iterator.
:rtype: None
Discard ``self.body`` but consume any generator such that any
finalization can occur, such as is required by
``caching.tee_output()``.
"""
consume(iter(self.body))
def finalize(self):
@@ -951,6 +977,8 @@ class Response(object):
class LazyUUID4(object):
"""A delayed UUID4 string maker."""
def __str__(self):
"""Return UUID4 and keep it for future calls."""
return str(self.uuid4)