quart.wrappers.response module#

class quart.wrappers.response.DataBody(data: bytes)#

Bases: ResponseBody

async make_conditional(begin: int, end: int | None) int#
class quart.wrappers.response.FileBody(file_path: str | PathLike, *, buffer_size: int | None = 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.

buffer_size#

Size in bytes to load per iteration.

buffer_size = 8192#
async make_conditional(begin: int, end: int | None) int#
class quart.wrappers.response.IOBody(io_stream: BytesIO, *, buffer_size: int | None = 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.

buffer_size#

Size in bytes to load per iteration.

buffer_size = 8192#
async make_conditional(begin: int, end: int | None) int#
class quart.wrappers.response.IterableBody(iterable: AsyncGenerator[bytes, None] | Iterable)#

Bases: ResponseBody

class quart.wrappers.response.Response(response: ResponseBody | AnyStr | Iterable | None = None, status: int | None = None, headers: dict | Headers | None = None, mimetype: str | None = None, content_type: str | None = 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.

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.

async add_etag(overwrite: bool = False, weak: bool = False) None#
automatically_set_content_length = True#
property data: bytes#
data_body_class#

alias of DataBody

default_mimetype: str | None = 'text/html'#

the default mimetype if none is provided.

file_body_class#

alias of FileBody

async freeze() None#

Freeze this object ready for pickling.

async get_data(as_text: Literal[True]) str#
async get_data(as_text: Literal[False]) bytes
async get_data(as_text: bool = True) AnyStr

Return the body data.

async get_json(force: bool = False, silent: bool = False) Any#

Parses the body data as JSON and returns it.

Parameters:
  • force – Force JSON parsing even if the mimetype is not JSON.

  • silent – Do not trigger error handling if parsing fails, without this the on_json_loading_failed() will be called on error.

headers: Headers#
implicit_sequence_conversion = True#
io_body_class#

alias of IOBody

async iter_encode() AsyncGenerator[bytes, None]#
iterable_body_class#

alias of IterableBody

property json: Any#
json_module = <module 'quart.json' from '/home/user/documentation/docs/quart/venv/lib/python3.11/site-packages/quart/json/__init__.py'>#
async make_conditional(request: Request, accept_ranges: bool | str = False, complete_length: int | None = None) Response#
async make_sequence() None#

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

response: ResponseBody#
set_data(data: AnyStr) None#

Set the response data.

This will encode using the charset.

timeout: Any#
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)