quart.wrappers 包#
子模块#
- quart.wrappers.base 模块
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 模块
Body
Request
Request.body_class
Request.form_data_parser_class
Request.body_class
Request.close()
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 模块
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 模块
模块内容#
- class quart.wrappers.BaseRequestWebsocket(method: str, scheme: str, path: str, query_string: bytes, headers: Headers, root_path: str, http_version: str, scope: HTTPScope | WebsocketScope)#
基类:
Request
此类是请求和 WebSockets 的基础。
- json_module#
自定义 JSON 解码/编码模块,它应该具有 dump、dumps、load 和 loads 方法
- 类型:
json.provider.JSONProvider
- routing_exception#
如果在路由匹配过程中抛出异常,则将存储在此处。
- 类型:
Exception | None
- view_args#
来自路由匹配的视图关键字参数。
- 类型:
dict[str, Any] | None
- property blueprint: str | None#
返回匹配的端点所属的蓝图。
如果请求未匹配或端点不在蓝图中,则这可能是 None。
- property blueprints: list[str]#
返回当前蓝图的名称。返回的列表按当前蓝图的顺序排序,向上通过父蓝图。
- property endpoint: str | None#
返回与此请求匹配的相应端点。
如果请求未与规则匹配,则这可能是 None。
- json_module: json.provider.JSONProvider = <module 'quart.json' from '/home/docs/checkouts/readthedocs.org/user_builds/quart/envs/latest/lib/python3.12/site-packages/quart/json/__init__.py'>#
- property max_content_length: int | None#
MAX_CONTENT_LENGTH
配置键的只读视图。
- 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)#
基类:
object
请求主体容器。
请求主体可以迭代并部分使用(不会积累内存使用量)或等待。
async for data in body: ... # or simply complete = await body
注意:无法迭代数据然后等待它。
- append(data: bytes) None #
- clear() None #
- set_complete() None #
- set_result(data: bytes) None #
主要用于测试的便捷方法。
- 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
此类代表一个请求。
它可以被子类化,并且子类可以通过用你的子类替换
request_class
来优先使用。- body_class#
用于在其中存储主体数据的类。
- form_data_parser_class#
可以被覆盖以实现不同的表单数据解析。
- async close() None #
- property data: bytes#
- property files: MultiDict#
解析后的文件。
除非请求的 mimetype 为
enctype="multipart/form-data"
并且方法为 POST、PUT 或 PATCH,否则它将返回一个空的 multidict。
- form_data_parser_class#
别名 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
获取请求主体数据。
- 参数:
cache – 如果为 False,主体数据将被清除,导致任何后续调用返回一个空的 AnyStr 并减少内存使用量。
as_text – 如果为 True,数据将以解码后的字符串形式返回,否则将返回原始字节。
parse_form_data – 首先将数据解析为表单数据,返回任何剩余的数据。
- async get_json(force: bool = False, silent: bool = False, cache: bool = True) Any #
将主体数据解析为 JSON 并返回。
- 参数:
force – 即使 mimetype 不是 JSON 也强制解析 JSON。
silent – 如果解析失败,不触发错误处理,没有这个,
on_json_loading_failed()
会在错误时被调用。cache – 在此请求对象上缓存解析后的 JSON。
- property json: Any#
- lock_class#
别名 of
Lock
- make_form_data_parser() FormDataParser #
- on_json_loading_failed(error: Exception) Any #
处理 JSON 解析错误。
- 参数:
error – 解析过程中引发的异常。
- 返回值:
如果覆盖,返回的任何值都将用作任何 get_json 调用的默认值。
- 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)#
继承自:
Response
此类表示响应。
它可以被子类化,并通过用您的子类替换
response_class
来优先使用子类化。- automatically_set_content_length#
如果为 False,则必须提供内容长度标题。
- default_status#
如果未提供,则使用的状态码。
- default_mimetype#
如果未提供,则使用的 mimetype。
- 类型:
str | None
- implicit_sequence_conversion#
在 get_data 方法中隐式将响应转换为可迭代对象,以允许多次迭代。
- async add_etag(overwrite: bool = False, weak: bool = False) None #
- automatically_set_content_length = True#
- property data: bytes#
- default_mimetype: str | None = 'text/html'#
如果未提供,则为默认 mimetype。
- async freeze() None #
冻结此对象以准备腌制。
- async get_data(as_text: Literal[True]) str #
- async get_data(as_text: Literal[False]) bytes
- async get_data(as_text: bool = True) AnyStr
返回主体数据。
- async get_json(force: bool = False, silent: bool = False) Any #
将主体数据解析为 JSON 并返回。
- 参数:
force – 即使 mimetype 不是 JSON 也强制解析 JSON。
silent – 如果解析失败,则不触发错误处理,如果没有此选项,则在错误时将调用
on_json_loading_failed()
。
- implicit_sequence_conversion = True#
- async iter_encode() AsyncGenerator[bytes, None] #
- iterable_body_class#
IterableBody
的别名
- property json: Any#
- json_module = <module 'quart.json' from '/home/docs/checkouts/readthedocs.org/user_builds/quart/envs/latest/lib/python3.12/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
将数字或字符串转换为整数,如果没有参数则返回 0。如果 x 是数字,则返回 x.__int__()。对于浮点数,这将截断为零。
如果 x 不是数字,或者如果给定了 base,那么 x 必须是字符串、字节或字节数组实例,表示给定基数中的整数文字。文字前面可以加上 ' +' 或 ' -' 并用空格包围。基数默认为 10。有效基数为 0 和 2-36。基数 0 表示从字符串解释基数为整数文字。>>> int('0b100', base=0) 4
- set_data(data: AnyStr) None #
设置响应数据。
这将使用
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 #
手动选择接受 websocket 连接。
- 参数:
headers – 与接受响应一起发送的附加标头。
subprotocol – 选择的子协议,可选。
- 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 #