quart.wrappers package#
Submodules#
- quart.wrappers.base module
BaseRequestWebsocket
BaseRequestWebsocket.json_module
BaseRequestWebsocket.routing_exception
BaseRequestWebsocket.url_rule
BaseRequestWebsocket.view_args
BaseRequestWebsocket.blueprint
BaseRequestWebsocket.blueprints
BaseRequestWebsocket.endpoint
BaseRequestWebsocket.json_module
BaseRequestWebsocket.max_content_length
BaseRequestWebsocket.routing_exception
BaseRequestWebsocket.script_root
BaseRequestWebsocket.url_root
BaseRequestWebsocket.url_rule
BaseRequestWebsocket.view_args
- quart.wrappers.request module
Body
Request
Request.body_class
Request.form_data_parser_class
Request.body_class
Request.data
Request.files
Request.form
Request.form_data_parser_class
Request.get_data()
Request.get_json()
Request.json
Request.lock_class
Request.make_form_data_parser()
Request.on_json_loading_failed()
Request.send_push_promise()
Request.stream
Request.values
- quart.wrappers.response module
DataBody
FileBody
IOBody
IterableBody
Response
Response.automatically_set_content_length
Response.default_status
Response.default_mimetype
Response.implicit_sequence_conversion
Response.add_etag()
Response.automatically_set_content_length
Response.data
Response.data_body_class
Response.default_mimetype
Response.file_body_class
Response.freeze()
Response.get_data()
Response.get_json()
Response.headers
Response.implicit_sequence_conversion
Response.io_body_class
Response.iter_encode()
Response.iterable_body_class
Response.json
Response.json_module
Response.make_conditional()
Response.make_sequence()
Response.max_cookie_size
Response.response
Response.set_data()
Response.timeout
ResponseBody
- quart.wrappers.websocket module
Module contents#
- class quart.wrappers.BaseRequestWebsocket(method: str, scheme: str, path: str, query_string: bytes, headers: Headers, root_path: str, http_version: str, scope: HTTPScope | WebsocketScope)#
Bases:
Request
This class is the basis for Requests and websockets..
- json_module#
A custom json decoding/encoding module, it should have dump, dumps, load, and loads methods
- Type:
json.provider.JSONProvider
- routing_exception#
If an exception is raised during the route matching it will be stored here.
- Type:
Exception | None
- view_args#
The keyword arguments for the view from the route matching.
- Type:
dict[str, Any] | None
- property blueprint: str | None#
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: str | None#
Returns the corresponding endpoint matched for this request.
This can be None if the request has not been matched with a rule.
- json_module: json.provider.JSONProvider = <module 'quart.json' from '/home/user/documentation/docs/quart/venv/lib/python3.11/site-packages/quart/json/__init__.py'>#
- property max_content_length: int | None#
Read-only view of the
MAX_CONTENT_LENGTH
config key.
- routing_exception: Exception | None = None#
- property script_root: str#
- property url_root: str#
- view_args: dict[str, Any] | None = None#
- class quart.wrappers.Body(expected_content_length: int | None, max_content_length: int | None)#
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: Headers, root_path: str, http_version: str, scope: HTTPScope, *, max_content_length: int | None = None, body_timeout: int | None = None, send_push_promise: Callable[[str, Headers], Awaitable[None]])#
Bases:
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.
- property data: bytes#
- property files: 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.
- form_data_parser_class#
alias of
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#
- lock_class#
alias of
Lock
- make_form_data_parser() 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: CombinedMultiDict#
- class quart.wrappers.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#
- default_mimetype: str | None = 'text/html'#
the default mimetype if none is provided.
- 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.
- implicit_sequence_conversion = True#
- 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 #
- 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
- set_data(data: AnyStr) None #
Set the response data.
This will encode using the
charset
.
- class quart.wrappers.Websocket(path: str, query_string: bytes, scheme: str, headers: Headers, root_path: str, http_version: str, subprotocols: list[str], receive: Callable, send: Callable, accept: Callable, close: Callable, scope: WebsocketScope)#
Bases:
BaseRequestWebsocket
- async accept(headers: dict | Headers | None = None, subprotocol: str | None = 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(*args: Any, **kwargs: Any) None #