quart.wrappers.response module

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

Bases: quart.wrappers.response.ResponseBody

async convert_to_sequence() → bytes
async make_conditional(begin: int, end: Optional[int], max_partial_size: Optional[int] = None) → int
class quart.wrappers.response.FileBody(file_path: Union[str, os.PathLike], *, buffer_size: Optional[int] = None)

Bases: quart.wrappers.response.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 convert_to_sequence() → bytes
async make_conditional(begin: int, end: Optional[int], max_partial_size: Optional[int] = None) → int
class quart.wrappers.response.IOBody(io_stream: _io.BytesIO, *, buffer_size: Optional[int] = None)

Bases: quart.wrappers.response.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 convert_to_sequence() → bytes
async make_conditional(begin: int, end: Optional[int], max_partial_size: Optional[int] = None) → int
class quart.wrappers.response.IterableBody(iterable: Union[AsyncGenerator[bytes, None], Iterable])

Bases: quart.wrappers.response.ResponseBody

async convert_to_sequence() → bytes
class quart.wrappers.response.Response(response: Union[quart.wrappers.response.ResponseBody, AnyStr, Iterable], status: Optional[int] = None, headers: Union[dict, quart.datastructures.CIMultiDict, quart.datastructures.Headers, None] = None, mimetype: Optional[str] = None, content_type: Optional[str] = None)

Bases: quart.wrappers._base._BaseRequestResponse, quart.wrappers._base.JSONMixin

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.

implicit_sequence_conversion

Implicitly convert the response to a iterable in the get_data method, to allow multiple iterations.

property accept_ranges
property access_control
async add_etag(overwrite: bool = False, weak: bool = False) → None
property age
property allow
automatically_set_content_length = True
property cache_control
property content_encoding
property content_language
property content_length
property content_location
property content_md5
property content_range
property content_security_policy
property content_security_policy_report_only
property content_type
data_body_class

alias of DataBody

property date
default_mimetype = 'text/html'
default_status = 200

Delete a cookie (set to expire immediately).

property expires
file_body_class

alias of FileBody

async freeze() → None

Freeze this object ready for pickling.

async get_data(raw: bool = True) → AnyStr

Return the body data.

get_etag() → Tuple[Optional[str], Optional[bool]]
implicit_sequence_conversion = True
io_body_class

alias of IOBody

iterable_body_class

alias of IterableBody

property last_modified
property location
async make_conditional(request_range: quart.datastructures.Range, max_partial_size: Optional[int] = None) → None

Make the response conditional to the

Parameters
  • request_range – The range as requested by the request.

  • max_partial_size – The maximum length the server is willing to serve in a single response. Defaults to unlimited.

property referrer
property retry_after

Set a cookie in the response headers.

The arguments are the standard cookie morsels and this is a wrapper around the stdlib SimpleCookie code.

set_data(data: AnyStr) → None

Set the response data.

This will encode using the charset.

set_etag(etag: str, weak: bool = False) → None
property vary
class quart.wrappers.response.ResponseBody

Bases: abc.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)

abstract async convert_to_sequence() → bytes