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
+24 -5
View File
@@ -220,7 +220,9 @@ def process_multipart(entity):
def process_multipart_form_data(entity):
"""Read all multipart/form-data parts into entity.parts or entity.params.
"""Read ``multipart/form-data`` parts.
This function saves them into ``entity.parts`` or ``entity.params``.
"""
process_multipart(entity)
@@ -248,7 +250,7 @@ def process_multipart_form_data(entity):
def _old_process_multipart(entity):
"""The behavior of 3.2 and lower.
"""Behavior of 3.2 and lower.
Deprecated and will be changed in 3.3.
"""
@@ -411,6 +413,7 @@ class Entity(object):
"""
def __init__(self, fp, headers, params=None, parts=None):
"""Initialize an HTTP entity."""
# Make an instance-specific copy of the class processors
# so Tools, etc. can replace them per-request.
self.processors = self.processors.copy()
@@ -479,24 +482,30 @@ class Entity(object):
self.filename = unquote(str(filename), encoding)
def read(self, size=None, fp_out=None):
"""Read bytes from the connection."""
return self.fp.read(size, fp_out)
def readline(self, size=None):
"""Read a line of bytes from the connection."""
return self.fp.readline(size)
def readlines(self, sizehint=None):
"""Read some byte lines from the connection."""
return self.fp.readlines(sizehint)
def __iter__(self):
"""Set up the iterator."""
return self
def __next__(self):
"""Return the next line of bytes."""
line = self.readline()
if not line:
raise StopIteration
return line
def next(self):
"""Return the next line of bytes.""" # FIXME: python 2?
return self.__next__()
def read_into_file(self, fp_out=None):
@@ -564,7 +573,9 @@ class Entity(object):
proc(self)
def default_proc(self):
"""Called if a more-specific processor is not found for the
"""Process unknown data as a fallback.
Called if a more-specific processor is not found for the
``Content-Type``.
"""
# Leave the fp alone for someone else to read. This works fine
@@ -614,6 +625,7 @@ class Part(Entity):
"""
def __init__(self, fp, headers, boundary):
"""Initialize an entity part."""
Entity.__init__(self, fp, headers)
self.boundary = boundary
self.file = None
@@ -621,11 +633,13 @@ class Part(Entity):
@classmethod
def from_fp(cls, fp, boundary):
"""Initialize an entity part from a file handle."""
headers = cls.read_headers(fp)
return cls(fp, headers, boundary)
@classmethod
def read_headers(cls, fp):
"""Read HTTP headers from a file handle."""
headers = httputil.HeaderMap()
while True:
line = fp.readline()
@@ -713,7 +727,9 @@ class Part(Entity):
return fp_out
def default_proc(self):
"""Called if a more-specific processor is not found for the
"""Process unknown data as a fallback.
Called if a more-specific processor is not found for the
``Content-Type``.
"""
if self.filename:
@@ -743,9 +759,11 @@ inf = float('inf')
class SizedReader:
"""A buffered/sized reader."""
def __init__(self, fp, length, maxbytes, bufsize=DEFAULT_BUFFER_SIZE,
has_trailers=False):
"""Initialize buffered file handle reader."""
# Wrap our fp in a buffer so peek() works
self.fp = fp
self.length = length
@@ -773,7 +791,6 @@ class SizedReader:
object that supports the 'write' method; all bytes read will be
written to the fp, and None is returned.
"""
if self.length is None:
if size is None:
remaining = inf
@@ -889,6 +906,7 @@ class SizedReader:
return lines
def finish(self):
"""Finalize reading the HTTP trailer headers."""
self.done = True
if self.has_trailers and hasattr(self.fp, 'read_trailer_lines'):
self.trailers = {}
@@ -946,6 +964,7 @@ class RequestBody(Entity):
"""
def __init__(self, fp, headers, params=None, request_params=None):
"""Initialize a request body entity."""
Entity.__init__(self, fp, headers, params)
# http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.7.1