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)¶ Bases:
quart.wrappers.base._BaseRequestResponse
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.
-
url_rule
¶ The rule that this request has been matched too.
-
view_args
¶ The keyword arguments for the view from the route matching.
-
property
accept_charsets
¶
-
property
accept_encodings
¶
-
property
accept_languages
¶
-
property
accept_mimetypes
¶
-
property
access_control_request_headers
¶
-
property
access_control_request_method
¶
-
property
access_route
¶
-
property
base_url
¶ Returns the base url without query string or fragments.
-
property
blueprint
¶ 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
cache_control
¶
The parsed cookies attached to this request.
-
property
date
¶
-
dict_storage_class
¶ alias of
werkzeug.datastructures.ImmutableMultiDict
-
encoding_errors
= 'replace'¶
-
property
endpoint
¶ Returns the corresponding endpoint matched for this request.
This can be None if the request has not been matched with a rule.
-
property
full_path
¶
-
property
host
¶
-
property
host_url
¶
-
property
if_match
¶
-
property
if_modified_since
¶
-
property
if_none_match
¶
-
property
if_range
¶
-
property
if_unmodified_since
¶
-
property
is_secure
¶
-
list_storage_class
¶ alias of
werkzeug.datastructures.ImmutableList
-
property
max_forwards
¶
-
property
origin
¶
-
parameter_storage_class
¶ alias of
werkzeug.datastructures.ImmutableMultiDict
-
property
pragma
¶
-
property
range
¶
-
property
referrer
¶
-
property
remote_addr
¶ Returns the remote address of the request, faked into the headers.
-
routing_exception
: Optional[Exception] = None
-
property
url
¶ Returns the full url requested.
-
property
url_root
¶
-
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¶
-
set_complete
() → None¶
-
set_result
(data: bytes) → None¶ Convienience method, mainly for testing.
-
-
class
quart.wrappers.
JSONMixin
¶ Bases:
object
Mixin to provide get_json methods from objects.
The class must support _load_data_json and have a mimetype attribute.
-
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
is_json
¶ Returns True if the content_type is json like.
-
property
json
¶
-
property
mimetype
¶ Return the mimetype of the associated data.
-
on_json_loading_failed
(error: Exception) → None¶ Handle a JSON parsing error.
- Parameters
error – The exception raised during parsing.
-
async
-
class
quart.wrappers.
Request
(method: str, scheme: str, path: str, query_string: bytes, headers: werkzeug.datastructures.Headers, root_path: str, http_version: str, *, 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
,quart.wrappers.base.JSONMixin
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.
-
body_class
alias of
Body
-
property
content_encoding
¶
-
property
content_length
¶
-
property
content_md5
¶
-
property
content_type
¶
-
property
data
¶
-
property
files
¶ 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.
-
async
get_data
(raw: bool = True) → AnyStr¶ The request body data.
-
async
send_push_promise
(path: str) → None¶
-
property
values
¶
-
-
class
quart.wrappers.
Response
(response: Union[quart.wrappers.response.ResponseBody, AnyStr, Iterable], status: Optional[int] = None, headers: Union[dict, werkzeug.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_allow_credentials
¶ Whether credentials can be shared by the browser to JavaScript code. As part of the preflight request it indicates whether credentials can be used on the cross origin request.
-
property
access_control_allow_headers
¶
-
property
access_control_allow_methods
¶
-
property
access_control_allow_origin
¶
-
property
access_control_expose_headers
¶
-
property
access_control_max_age
¶
-
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: 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.
-
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.
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)¶ Bases:
quart.wrappers.base.BaseRequestWebsocket
-
async
accept
(headers: Union[dict, werkzeug.datastructures.Headers, None] = 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
receive
() → AnyStr¶
-
property
requested_subprotocols
¶
-
async
send
(data: AnyStr) → None¶
-
async