quart.wrappers.request module

class quart.wrappers.request.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.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