quart.wrappers.response module
- class quart.wrappers.response.ResponseBody
Bases:
ABC
Base class wrapper for response body data.
This ensures that the following is possible (as Quart assumes so when returning the body to the ASGI server
- async with wrapper as response:
- async for data in response:
send(data)
- class quart.wrappers.response.DataBody(data)
Bases:
ResponseBody
- Parameters:
data (bytes)
- async make_conditional(begin, end)
- Parameters:
begin (int)
end (int | None)
- Return type:
int
- class quart.wrappers.response.IterableBody(iterable)
Bases:
ResponseBody
- Parameters:
iterable (AsyncIterable[Any] | Iterable[Any])
- class quart.wrappers.response.FileBody(file_path, *, buffer_size=None)
Bases:
ResponseBody
Provides an async file accessor with range setting.
The
Response.response
attribute must be async-iterable and yield bytes, which this wrapper does for a file. In addition it allows a range to be set on the file, thereby supporting conditional requests.- Parameters:
file_path (str | PathLike)
buffer_size (int | None)
- buffer_size
Size in bytes to load per iteration.
- buffer_size = 8192
- async make_conditional(begin, end)
- Parameters:
begin (int)
end (int | None)
- Return type:
int
- class quart.wrappers.response.IOBody(io_stream, *, buffer_size=None)
Bases:
ResponseBody
Provides an async file accessor with range setting.
The
Response.response
attribute must be async-iterable and yield bytes, which this wrapper does for a file. In addition it allows a range to be set on the file, thereby supporting conditional requests.- Parameters:
io_stream (BytesIO)
buffer_size (int | None)
- buffer_size
Size in bytes to load per iteration.
- buffer_size = 8192
- async make_conditional(begin, end)
- Parameters:
begin (int)
end (int | None)
- Return type:
int
- class quart.wrappers.response.Response(response=None, status=None, headers=None, mimetype=None, content_type=None)
Bases:
Response
This class represents a response.
It can be subclassed and the subclassed used in preference by replacing the
response_class
with your subclass.- Parameters:
response (ResponseBody)
status (int | None)
headers (Headers)
mimetype (str | None)
content_type (str | None)
- automatically_set_content_length
If False the content length header must be provided.
- default_status
The status code to use if not provided.
- default_mimetype
The mimetype to use if not provided.
- Type:
str | None
- implicit_sequence_conversion
Implicitly convert the response to a iterable in the get_data method, to allow multiple iterations.
- automatically_set_content_length = True
- default_mimetype: str | None = 'text/html'
the default mimetype if none is provided.
- implicit_sequence_conversion = True
- iterable_body_class
alias of
IterableBody
- json_module = <module 'quart.json' from '/build/reproducible-path/quart-0.20.0/.pybuild/cpython3_3.12_quart/build/quart/json/__init__.py'>
- timeout: Any
- response: ResponseBody
- property max_cookie_size: int
int([x]) -> integer int(x, base=10) -> integer
Convert a number or string to an integer, or return 0 if no arguments are given. If x is a number, return x.__int__(). For floating-point numbers, this truncates towards zero.
If x is not a number or if base is given, then x must be a string, bytes, or bytearray instance representing an integer literal in the given base. The literal can be preceded by ‘+’ or ‘-’ and be surrounded by whitespace. The base defaults to 10. Valid bases are 0 and 2-36. Base 0 means to interpret the base from the string as an integer literal. >>> int(‘0b100’, base=0) 4
- async get_data(as_text: Literal[True]) str
- async get_data(as_text: Literal[False]) bytes
- async get_data(as_text: bool = True) str | bytes
Return the body data.
- set_data(data)
Set the response data.
This will encode using the
charset
.- Parameters:
data (str | bytes)
- Return type:
None
- property data: bytes
- property json: Any
- headers: Headers
- async get_json(force=False, silent=False)
Parses the body data as JSON and returns it.
- Parameters:
force (bool) – Force JSON parsing even if the mimetype is not JSON.
silent (bool) – Do not trigger error handling if parsing fails, without this the
on_json_loading_failed()
will be called on error.
- Return type:
Any
- async make_conditional(request, accept_ranges=False, complete_length=None)
- async make_sequence()
- Return type:
None
- async iter_encode()
- Return type:
AsyncGenerator[bytes, None]
- async freeze()
Freeze this object ready for pickling.
- Return type:
None
- async add_etag(overwrite=False, weak=False)
- Parameters:
overwrite (bool)
weak (bool)
- Return type:
None