quart.wrappers package

Module contents

class quart.wrappers.BaseRequestWebsocket(method: str, scheme: str, path: str, query_string: bytes, headers: werkzeug.datastructures.Headers, root_path: str, http_version: str, scope: Union[hypercorn.typing.HTTPScope, hypercorn.typing.WebsocketScope])

Bases: werkzeug.sansio.request.Request

This class is the basis for Requests and websockets..

routing_exception

If an exception is raised during the route matching it will be stored here.

Type

Optional[Exception]

url_rule

The rule that this request has been matched too.

Type

Optional[‘QuartRule’]

view_args

The keyword arguments for the view from the route matching.

Type

Optional[Dict[str, Any]]

property blueprint: Optional[str]

Returns the blueprint the matched endpoint belongs to.

This can be None if the request has not been matched or the endpoint is not in a blueprint.

property blueprints: List[str]

Return the names of the current blueprints. The returned list is ordered from the current blueprint, upwards through parent blueprints.

property endpoint: Optional[str]

Returns the corresponding endpoint matched for this request.

This can be None if the request has not been matched with a rule.

property max_content_length: Optional[int]

Read-only view of the MAX_CONTENT_LENGTH config key.

routing_exception: Optional[Exception] = None
property script_root: str
property url_root: str
url_rule: Optional[QuartRule] = None
view_args: Optional[Dict[str, Any]] = None
class quart.wrappers.Body(expected_content_length: Optional[int], max_content_length: Optional[int])

Bases: object

A request body container.

The request body can either be iterated over and consumed in parts (without building up memory usage) or awaited.

async for data in body:
    ...
# or simply
complete = await body

Note: It is not possible to iterate over the data and then await it.

append(data: bytes) None
clear() None
set_complete() None
set_result(data: bytes) None

Convenience method, mainly for testing.

class quart.wrappers.Request(method: str, scheme: str, path: str, query_string: bytes, headers: werkzeug.datastructures.Headers, root_path: str, http_version: str, scope: hypercorn.typing.HTTPScope, *, max_content_length: Optional[int] = None, body_timeout: Optional[int] = None, send_push_promise: Callable[[str, werkzeug.datastructures.Headers], Awaitable[None]])

Bases: quart.wrappers.base.BaseRequestWebsocket

This class represents a request.

It can be subclassed and the subclassed used in preference by replacing the request_class with your subclass.

body_class

The class to store the body data within.

form_data_parser_class

Can be overridden to implement a different form data parsing.

json_module

A custom json decoding/encoding module, it should have dump, dumps, load, and loads methods

body_class

alias of quart.wrappers.request.Body

property data: bytes
property files: werkzeug.datastructures.MultiDict

The parsed files.

This will return an empty multidict unless the request mimetype was enctype="multipart/form-data" and the method POST, PUT, or PATCH.

property form: werkzeug.datastructures.MultiDict

The parsed form encoded data.

Note file data is present in the files.

form_data_parser_class

alias of quart.formparser.FormDataParser

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

Get the request body data.

Parameters
  • cache – If False the body data will be cleared, resulting in any subsequent calls returning an empty AnyStr and reducing memory usage.

  • as_text – If True the data is returned as a decoded string, otherwise raw bytes are returned.

  • parse_form_data – Parse the data as form data first, return any remaining data.

async get_json(force: bool = False, silent: bool = False, cache: bool = True) 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.

  • cache – Cache the parsed JSON on this request object.

property json: Any
json_module = <module 'quart.json' from '/usr/local/lib/python3.9/site-packages/Quart-0.15.1-py3.9.egg/quart/json/__init__.py'>
make_form_data_parser() quart.formparser.FormDataParser
on_json_loading_failed(error: Exception) Any

Handle a JSON parsing error.

Parameters

error – The exception raised during parsing.

Returns

Any value returned (if overridden) will be used as the default for any get_json calls.

async send_push_promise(path: str) None
property stream: NoReturn
property values: werkzeug.datastructures.CombinedMultiDict
class quart.wrappers.Response(response: Union[quart.wrappers.response.ResponseBody, AnyStr, Iterable], status: Optional[int] = None, headers: Optional[Union[dict, werkzeug.datastructures.Headers]] = None, mimetype: Optional[str] = None, content_type: Optional[str] = None)

Bases: werkzeug.sansio.response.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.

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 quart.wrappers.response.DataBody

default_mimetype = 'text/html'

the default mimetype if none is provided.

file_body_class

alias of quart.wrappers.response.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: werkzeug.datastructures.Headers
implicit_sequence_conversion = True
io_body_class

alias of quart.wrappers.response.IOBody

iterable_body_class

alias of quart.wrappers.response.IterableBody

property json: Any
json_module = <module 'quart.json' from '/usr/local/lib/python3.9/site-packages/Quart-0.15.1-py3.9.egg/quart/json/__init__.py'>
async make_conditional(request_range: Optional[werkzeug.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.

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

property referrer: Optional[str]
response: quart.wrappers.response.ResponseBody
set_data(data: AnyStr) None

Set the response data.

This will encode using the charset.

timeout: Any
class quart.wrappers.Websocket(path: str, query_string: bytes, scheme: str, headers: werkzeug.datastructures.Headers, root_path: str, http_version: str, subprotocols: List[str], receive: Callable, send: Callable, accept: Callable, close: Callable, scope: hypercorn.typing.WebsocketScope)

Bases: quart.wrappers.base.BaseRequestWebsocket

async accept(headers: Optional[Union[dict, werkzeug.datastructures.Headers]] = None, subprotocol: Optional[str] = None) None

Manually chose to accept the websocket connection.

Parameters
  • headers – Additional headers to send with the acceptance response.

  • subprotocol – The chosen subprotocol, optional.

async close(code: int, reason: str = '') None
async receive() AnyStr
async receive_json() Any
property requested_subprotocols: List[str]
async send(data: AnyStr) None
async send_json(data: Any) None