quart.wrappers package
Submodules
- quart.wrappers.base module
BaseRequestWebsocket
BaseRequestWebsocket.json_module
BaseRequestWebsocket.routing_exception
BaseRequestWebsocket.url_rule
BaseRequestWebsocket.view_args
BaseRequestWebsocket.json_module
BaseRequestWebsocket.routing_exception
BaseRequestWebsocket.url_rule
BaseRequestWebsocket.view_args
BaseRequestWebsocket.endpoint
BaseRequestWebsocket.blueprint
BaseRequestWebsocket.blueprints
BaseRequestWebsocket.script_root
BaseRequestWebsocket.url_root
- quart.wrappers.request module
Body
Request
Request.body_class
Request.form_data_parser_class
Request.body_class
Request.form_data_parser_class
Request.lock_class
Request.max_content_length
Request.max_form_memory_size
Request.max_form_parts
Request.stream
Request.data
Request.get_data()
Request.values
Request.form
Request.files
Request.make_form_data_parser()
Request.json
Request.get_json()
Request.on_json_loading_failed()
Request.send_push_promise()
Request.close()
- quart.wrappers.response module
ResponseBody
DataBody
IterableBody
FileBody
IOBody
Response
Response.automatically_set_content_length
Response.default_status
Response.default_mimetype
Response.implicit_sequence_conversion
Response.automatically_set_content_length
Response.default_mimetype
Response.data_body_class
Response.file_body_class
Response.implicit_sequence_conversion
Response.io_body_class
Response.iterable_body_class
Response.json_module
Response.timeout
Response.response
Response.max_cookie_size
Response.get_data()
Response.set_data()
Response.data
Response.json
Response.headers
Response.get_json()
Response.make_conditional()
Response.make_sequence()
Response.iter_encode()
Response.freeze()
Response.add_etag()
- quart.wrappers.websocket module
Module contents
- class quart.wrappers.BaseRequestWebsocket(method, scheme, path, query_string, headers, root_path, http_version, scope)
Bases:
Request
This class is the basis for Requests and websockets..
- Parameters:
method (str)
scheme (str)
path (str)
query_string (bytes)
headers (Headers)
root_path (str)
http_version (str)
scope (WWWScope)
- json_module
A custom json decoding/encoding module, it should have
dump
,dumps
,load
, andloads
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
- json_module: json.provider.JSONProvider = <module 'quart.json' from '/build/reproducible-path/quart-0.20.0/.pybuild/cpython3_3.12_quart/build/quart/json/__init__.py'>
- routing_exception: Exception | None = None
- view_args: dict[str, Any] | None = None
- 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.
- 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 script_root: str
- property url_root: str
- class quart.wrappers.Body(expected_content_length, max_content_length)
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.
- Parameters:
expected_content_length (int | None)
max_content_length (int | None)
- append(data)
- Parameters:
data (bytes)
- Return type:
None
- set_complete()
- Return type:
None
- set_result(data)
Convenience method, mainly for testing.
- Parameters:
data (bytes)
- Return type:
None
- clear()
- Return type:
None
- class quart.wrappers.Request(method, scheme, path, query_string, headers, root_path, http_version, scope, *, max_content_length=None, body_timeout=None, send_push_promise)
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.- Parameters:
method (str)
scheme (str)
path (str)
query_string (bytes)
headers (Headers)
root_path (str)
http_version (str)
scope (HTTPScope)
max_content_length (int | None)
body_timeout (int | None)
send_push_promise (Callable[[str, Headers], Awaitable[None]])
- body_class
The class to store the body data within.
- form_data_parser_class
Can be overridden to implement a different form data parsing.
- form_data_parser_class
alias of
FormDataParser
- lock_class
alias of
Lock
- property max_content_length: int | None
- property max_form_memory_size: int | None
- property max_form_parts: int | None
- property stream: NoReturn
- property data: bytes
- 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) str | bytes
Get the request body data.
- Parameters:
cache – If False the body data will be cleared, resulting in any subsequent calls returning an empty str | bytes 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.
- property values: CombinedMultiDict
- 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.
- make_form_data_parser()
- Return type:
- property json: Any
- async get_json(force=False, silent=False, cache=True)
Parses the body data as JSON and returns it.
- Parameters:
force (bool) – Force JSON parsing even if the mimetype is not JSON.
silent (bool) – Do not trigger error handling if parsing fails, without this the
on_json_loading_failed()
will be called on error.cache (bool) – Cache the parsed JSON on this request object.
- Return type:
Any
- on_json_loading_failed(error)
Handle a JSON parsing error.
- Parameters:
error (Exception) – The exception raised during parsing.
- Returns:
Any value returned (if overridden) will be used as the default for any get_json calls.
- Return type:
Any
- async send_push_promise(path)
- Parameters:
path (str)
- Return type:
None
- async close()
- Return type:
None
- class quart.wrappers.Response(response=None, status=None, headers=None, mimetype=None, content_type=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.- Parameters:
response (ResponseBody | str | bytes | Iterable | AsyncIterable | None)
status (int | None)
headers (Headers)
mimetype (str | None)
content_type (str | None)
- 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.
- automatically_set_content_length = True
- default_mimetype: str | None = 'text/html'
the default mimetype if none is provided.
- implicit_sequence_conversion = True
- iterable_body_class
alias of
IterableBody
- json_module = <module 'quart.json' from '/build/reproducible-path/quart-0.20.0/.pybuild/cpython3_3.12_quart/build/quart/json/__init__.py'>
- 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
- async get_data(as_text: Literal[True]) str
- async get_data(as_text: Literal[False]) bytes
- async get_data(as_text: bool = True) str | bytes
Return the body data.
- set_data(data)
Set the response data.
This will encode using the
charset
.- Parameters:
data (str | bytes)
- Return type:
None
- property data: bytes
- property json: Any
- async get_json(force=False, silent=False)
Parses the body data as JSON and returns it.
- Parameters:
force (bool) – Force JSON parsing even if the mimetype is not JSON.
silent (bool) – Do not trigger error handling if parsing fails, without this the
on_json_loading_failed()
will be called on error.
- Return type:
Any
- async make_conditional(request, accept_ranges=False, complete_length=None)
- async make_sequence()
- Return type:
None
- async iter_encode()
- Return type:
AsyncGenerator[bytes, None]
- async freeze()
Freeze this object ready for pickling.
- Return type:
None
- async add_etag(overwrite=False, weak=False)
- Parameters:
overwrite (bool)
weak (bool)
- Return type:
None
- class quart.wrappers.Websocket(path, query_string, scheme, headers, root_path, http_version, subprotocols, receive, send, accept, close, scope)
Bases:
BaseRequestWebsocket
- Parameters:
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)
- property requested_subprotocols: list[str]
- async receive()
- Return type:
AnyStr
- async send(data)
- Parameters:
data (AnyStr)
- Return type:
None
- async receive_json()
- Return type:
Any
- async send_json(*args, **kwargs)
- Parameters:
args (Any)
kwargs (Any)
- Return type:
None
- async accept(headers=None, subprotocol=None)
Manually chose to accept the websocket connection.
- Parameters:
headers (dict | Headers | None) – Additional headers to send with the acceptance response.
subprotocol (str | None) – The chosen subprotocol, optional.
- Return type:
None
- async close(code, reason='')
- Parameters:
code (int)
reason (str)
- Return type:
None