2022-01-22 15:23:07 +08:00
|
|
|
|
"""[FastAPI](https://fastapi.tiangolo.com/) 驱动适配
|
2020-10-16 01:10:46 +08:00
|
|
|
|
|
2023-01-06 20:07:28 +08:00
|
|
|
|
```bash
|
|
|
|
|
nb driver install fastapi
|
|
|
|
|
# 或者
|
|
|
|
|
pip install nonebot2[fastapi]
|
|
|
|
|
```
|
|
|
|
|
|
2022-01-22 15:23:07 +08:00
|
|
|
|
:::tip 提示
|
|
|
|
|
本驱动仅支持服务端连接
|
|
|
|
|
:::
|
2021-07-31 12:24:11 +08:00
|
|
|
|
|
2022-01-22 15:23:07 +08:00
|
|
|
|
FrontMatter:
|
|
|
|
|
sidebar_position: 1
|
|
|
|
|
description: nonebot.drivers.fastapi 模块
|
2020-10-16 01:10:46 +08:00
|
|
|
|
"""
|
2020-07-04 22:51:10 +08:00
|
|
|
|
|
2022-08-14 19:41:00 +08:00
|
|
|
|
|
2020-07-04 22:51:10 +08:00
|
|
|
|
import logging
|
2022-08-14 19:41:00 +08:00
|
|
|
|
import contextlib
|
2021-12-30 12:11:31 +08:00
|
|
|
|
from functools import wraps
|
2023-03-29 15:59:54 +08:00
|
|
|
|
from typing import Any, Dict, List, Tuple, Union, Optional
|
2020-07-04 22:51:10 +08:00
|
|
|
|
|
2021-01-12 18:02:05 +08:00
|
|
|
|
from pydantic import BaseSettings
|
2020-07-04 22:51:10 +08:00
|
|
|
|
|
2021-09-25 19:14:16 +08:00
|
|
|
|
from nonebot.config import Env
|
2020-12-06 02:30:19 +08:00
|
|
|
|
from nonebot.typing import overrides
|
2021-12-30 12:11:31 +08:00
|
|
|
|
from nonebot.exception import WebSocketClosed
|
2022-02-06 17:08:11 +08:00
|
|
|
|
from nonebot.internal.driver import FileTypes
|
2021-09-25 19:14:16 +08:00
|
|
|
|
from nonebot.config import Config as NoneBotConfig
|
2021-12-20 15:46:23 +08:00
|
|
|
|
from nonebot.drivers import Request as BaseRequest
|
2021-09-25 19:14:16 +08:00
|
|
|
|
from nonebot.drivers import WebSocket as BaseWebSocket
|
2021-12-23 17:20:26 +08:00
|
|
|
|
from nonebot.drivers import ReverseDriver, HTTPServerSetup, WebSocketServerSetup
|
2021-12-23 14:29:21 +08:00
|
|
|
|
|
2023-03-29 15:59:54 +08:00
|
|
|
|
from ._lifespan import LIFESPAN_FUNC, Lifespan
|
|
|
|
|
|
2023-01-06 20:07:28 +08:00
|
|
|
|
try:
|
|
|
|
|
import uvicorn
|
|
|
|
|
from fastapi.responses import Response
|
|
|
|
|
from fastapi import FastAPI, Request, UploadFile, status
|
|
|
|
|
from starlette.websockets import WebSocket, WebSocketState, WebSocketDisconnect
|
2023-03-29 15:59:54 +08:00
|
|
|
|
except ModuleNotFoundError as e: # pragma: no cover
|
2023-01-06 20:07:28 +08:00
|
|
|
|
raise ImportError(
|
2023-06-24 14:47:35 +08:00
|
|
|
|
"Please install FastAPI first to use this driver. "
|
|
|
|
|
"Install with pip: `pip install nonebot2[fastapi]`"
|
2023-02-09 10:24:27 +08:00
|
|
|
|
) from e
|
2023-01-06 20:07:28 +08:00
|
|
|
|
|
2020-08-20 16:34:07 +08:00
|
|
|
|
|
2021-12-30 12:11:31 +08:00
|
|
|
|
def catch_closed(func):
|
|
|
|
|
@wraps(func)
|
|
|
|
|
async def decorator(*args, **kwargs):
|
|
|
|
|
try:
|
|
|
|
|
return await func(*args, **kwargs)
|
|
|
|
|
except WebSocketDisconnect as e:
|
|
|
|
|
raise WebSocketClosed(e.code)
|
2022-05-14 21:06:57 +08:00
|
|
|
|
except KeyError:
|
|
|
|
|
raise TypeError("WebSocket received unexpected frame type")
|
2021-12-30 12:11:31 +08:00
|
|
|
|
|
|
|
|
|
return decorator
|
|
|
|
|
|
|
|
|
|
|
2021-01-12 18:02:05 +08:00
|
|
|
|
class Config(BaseSettings):
|
2022-01-22 15:23:07 +08:00
|
|
|
|
"""FastAPI 驱动框架设置,详情参考 FastAPI 文档"""
|
2021-11-22 23:21:26 +08:00
|
|
|
|
|
2021-01-12 18:02:05 +08:00
|
|
|
|
fastapi_openapi_url: Optional[str] = None
|
2022-01-22 15:23:07 +08:00
|
|
|
|
"""`openapi.json` 地址,默认为 `None` 即关闭"""
|
2021-01-12 18:02:05 +08:00
|
|
|
|
fastapi_docs_url: Optional[str] = None
|
2022-01-22 15:23:07 +08:00
|
|
|
|
"""`swagger` 地址,默认为 `None` 即关闭"""
|
2021-01-12 18:02:05 +08:00
|
|
|
|
fastapi_redoc_url: Optional[str] = None
|
2022-01-22 15:23:07 +08:00
|
|
|
|
"""`redoc` 地址,默认为 `None` 即关闭"""
|
2022-01-11 15:03:17 +08:00
|
|
|
|
fastapi_include_adapter_schema: bool = True
|
2022-01-22 15:23:07 +08:00
|
|
|
|
"""是否包含适配器路由的 schema,默认为 `True`"""
|
2021-12-28 15:19:53 +08:00
|
|
|
|
fastapi_reload: bool = False
|
2022-01-22 15:23:07 +08:00
|
|
|
|
"""开启/关闭冷重载"""
|
2021-10-02 15:35:15 +08:00
|
|
|
|
fastapi_reload_dirs: Optional[List[str]] = None
|
2022-01-22 15:23:07 +08:00
|
|
|
|
"""重载监控文件夹列表,默认为 uvicorn 默认值"""
|
2022-08-04 14:14:50 +08:00
|
|
|
|
fastapi_reload_delay: float = 0.25
|
2022-01-22 15:23:07 +08:00
|
|
|
|
"""重载延迟,默认为 uvicorn 默认值"""
|
2021-10-02 15:35:15 +08:00
|
|
|
|
fastapi_reload_includes: Optional[List[str]] = None
|
2022-01-22 15:23:07 +08:00
|
|
|
|
"""要监听的文件列表,支持 glob pattern,默认为 uvicorn 默认值"""
|
2021-10-02 15:35:15 +08:00
|
|
|
|
fastapi_reload_excludes: Optional[List[str]] = None
|
2022-01-22 15:23:07 +08:00
|
|
|
|
"""不要监听的文件列表,支持 glob pattern,默认为 uvicorn 默认值"""
|
2023-01-04 12:58:26 +08:00
|
|
|
|
fastapi_extra: Dict[str, Any] = {}
|
|
|
|
|
"""传递给 `FastAPI` 的其他参数。"""
|
2021-01-12 18:02:05 +08:00
|
|
|
|
|
|
|
|
|
class Config:
|
|
|
|
|
extra = "ignore"
|
|
|
|
|
|
|
|
|
|
|
2021-11-27 12:16:31 +08:00
|
|
|
|
class Driver(ReverseDriver):
|
2022-01-22 15:23:07 +08:00
|
|
|
|
"""FastAPI 驱动框架。"""
|
2020-07-04 22:51:10 +08:00
|
|
|
|
|
2021-01-12 18:02:05 +08:00
|
|
|
|
def __init__(self, env: Env, config: NoneBotConfig):
|
2023-06-24 14:47:35 +08:00
|
|
|
|
super().__init__(env, config)
|
2020-08-07 17:51:57 +08:00
|
|
|
|
|
2021-07-23 00:51:19 +08:00
|
|
|
|
self.fastapi_config: Config = Config(**config.dict())
|
2021-01-12 18:02:05 +08:00
|
|
|
|
|
2023-03-29 15:59:54 +08:00
|
|
|
|
self._lifespan = Lifespan()
|
|
|
|
|
|
2020-07-04 22:51:10 +08:00
|
|
|
|
self._server_app = FastAPI(
|
2023-03-29 15:59:54 +08:00
|
|
|
|
lifespan=self._lifespan_manager,
|
2021-01-12 18:02:05 +08:00
|
|
|
|
openapi_url=self.fastapi_config.fastapi_openapi_url,
|
|
|
|
|
docs_url=self.fastapi_config.fastapi_docs_url,
|
|
|
|
|
redoc_url=self.fastapi_config.fastapi_redoc_url,
|
2023-01-04 12:58:26 +08:00
|
|
|
|
**self.fastapi_config.fastapi_extra,
|
2020-07-04 22:51:10 +08:00
|
|
|
|
)
|
|
|
|
|
|
2020-08-13 15:56:09 +08:00
|
|
|
|
@property
|
2021-05-21 17:06:20 +08:00
|
|
|
|
@overrides(ReverseDriver)
|
2020-08-13 15:56:09 +08:00
|
|
|
|
def type(self) -> str:
|
2022-01-12 18:19:21 +08:00
|
|
|
|
"""驱动名称: `fastapi`"""
|
2020-08-13 15:56:09 +08:00
|
|
|
|
return "fastapi"
|
|
|
|
|
|
2020-07-04 22:51:10 +08:00
|
|
|
|
@property
|
2021-05-21 17:06:20 +08:00
|
|
|
|
@overrides(ReverseDriver)
|
2020-08-11 10:44:05 +08:00
|
|
|
|
def server_app(self) -> FastAPI:
|
2022-01-12 18:19:21 +08:00
|
|
|
|
"""`FastAPI APP` 对象"""
|
2020-07-04 22:51:10 +08:00
|
|
|
|
return self._server_app
|
|
|
|
|
|
|
|
|
|
@property
|
2021-05-21 17:06:20 +08:00
|
|
|
|
@overrides(ReverseDriver)
|
2021-06-15 01:23:12 +08:00
|
|
|
|
def asgi(self) -> FastAPI:
|
2022-01-12 18:19:21 +08:00
|
|
|
|
"""`FastAPI APP` 对象"""
|
2020-07-04 22:51:10 +08:00
|
|
|
|
return self._server_app
|
|
|
|
|
|
|
|
|
|
@property
|
2021-05-21 17:06:20 +08:00
|
|
|
|
@overrides(ReverseDriver)
|
2020-08-01 22:03:40 +08:00
|
|
|
|
def logger(self) -> logging.Logger:
|
2020-10-16 01:10:46 +08:00
|
|
|
|
"""fastapi 使用的 logger"""
|
2020-07-04 22:51:10 +08:00
|
|
|
|
return logging.getLogger("fastapi")
|
|
|
|
|
|
2021-12-06 22:19:05 +08:00
|
|
|
|
@overrides(ReverseDriver)
|
|
|
|
|
def setup_http_server(self, setup: HTTPServerSetup):
|
2021-12-18 23:19:37 +08:00
|
|
|
|
async def _handle(request: Request) -> Response:
|
|
|
|
|
return await self._handle_http(request, setup)
|
2021-12-06 22:19:05 +08:00
|
|
|
|
|
|
|
|
|
self._server_app.add_api_route(
|
2021-12-18 23:19:37 +08:00
|
|
|
|
setup.path.path,
|
|
|
|
|
_handle,
|
2021-12-22 18:50:03 +08:00
|
|
|
|
name=setup.name,
|
2021-12-06 22:19:05 +08:00
|
|
|
|
methods=[setup.method],
|
2022-01-11 15:03:17 +08:00
|
|
|
|
include_in_schema=self.fastapi_config.fastapi_include_adapter_schema,
|
2021-12-06 22:19:05 +08:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
@overrides(ReverseDriver)
|
|
|
|
|
def setup_websocket_server(self, setup: WebSocketServerSetup) -> None:
|
2021-12-22 18:50:03 +08:00
|
|
|
|
async def _handle(websocket: WebSocket) -> None:
|
2021-12-18 23:19:37 +08:00
|
|
|
|
await self._handle_ws(websocket, setup)
|
2021-12-06 22:19:05 +08:00
|
|
|
|
|
|
|
|
|
self._server_app.add_api_websocket_route(
|
2021-12-18 23:19:37 +08:00
|
|
|
|
setup.path.path,
|
|
|
|
|
_handle,
|
2021-12-22 18:50:03 +08:00
|
|
|
|
name=setup.name,
|
2021-12-06 22:19:05 +08:00
|
|
|
|
)
|
|
|
|
|
|
2021-05-21 17:06:20 +08:00
|
|
|
|
@overrides(ReverseDriver)
|
2023-03-29 15:59:54 +08:00
|
|
|
|
def on_startup(self, func: LIFESPAN_FUNC) -> LIFESPAN_FUNC:
|
|
|
|
|
return self._lifespan.on_startup(func)
|
2020-08-11 10:44:05 +08:00
|
|
|
|
|
2021-05-21 17:06:20 +08:00
|
|
|
|
@overrides(ReverseDriver)
|
2023-03-29 15:59:54 +08:00
|
|
|
|
def on_shutdown(self, func: LIFESPAN_FUNC) -> LIFESPAN_FUNC:
|
|
|
|
|
return self._lifespan.on_shutdown(func)
|
|
|
|
|
|
|
|
|
|
@contextlib.asynccontextmanager
|
|
|
|
|
async def _lifespan_manager(self, app: FastAPI):
|
|
|
|
|
await self._lifespan.startup()
|
|
|
|
|
try:
|
|
|
|
|
yield
|
|
|
|
|
finally:
|
|
|
|
|
await self._lifespan.shutdown()
|
2020-08-11 10:44:05 +08:00
|
|
|
|
|
2021-05-21 17:06:20 +08:00
|
|
|
|
@overrides(ReverseDriver)
|
2021-11-22 23:21:26 +08:00
|
|
|
|
def run(
|
|
|
|
|
self,
|
|
|
|
|
host: Optional[str] = None,
|
|
|
|
|
port: Optional[int] = None,
|
|
|
|
|
*,
|
|
|
|
|
app: Optional[str] = None,
|
|
|
|
|
**kwargs,
|
|
|
|
|
):
|
2022-01-12 18:19:21 +08:00
|
|
|
|
"""使用 `uvicorn` 启动 FastAPI"""
|
2020-12-02 13:17:27 +08:00
|
|
|
|
super().run(host, port, app, **kwargs)
|
2020-07-04 22:51:10 +08:00
|
|
|
|
LOGGING_CONFIG = {
|
|
|
|
|
"version": 1,
|
|
|
|
|
"disable_existing_loggers": False,
|
|
|
|
|
"handlers": {
|
|
|
|
|
"default": {
|
2020-08-27 13:27:42 +08:00
|
|
|
|
"class": "nonebot.log.LoguruHandler",
|
2020-07-04 22:51:10 +08:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
"loggers": {
|
2021-11-22 23:21:26 +08:00
|
|
|
|
"uvicorn.error": {"handlers": ["default"], "level": "INFO"},
|
2020-07-04 22:51:10 +08:00
|
|
|
|
"uvicorn.access": {
|
|
|
|
|
"handlers": ["default"],
|
|
|
|
|
"level": "INFO",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
2021-07-23 00:51:19 +08:00
|
|
|
|
uvicorn.run(
|
|
|
|
|
app or self.server_app, # type: ignore
|
|
|
|
|
host=host or str(self.config.host),
|
|
|
|
|
port=port or self.config.port,
|
2021-12-28 15:19:53 +08:00
|
|
|
|
reload=self.fastapi_config.fastapi_reload,
|
2021-10-02 15:35:15 +08:00
|
|
|
|
reload_dirs=self.fastapi_config.fastapi_reload_dirs,
|
2021-09-28 21:20:29 +08:00
|
|
|
|
reload_delay=self.fastapi_config.fastapi_reload_delay,
|
2021-10-02 15:35:15 +08:00
|
|
|
|
reload_includes=self.fastapi_config.fastapi_reload_includes,
|
|
|
|
|
reload_excludes=self.fastapi_config.fastapi_reload_excludes,
|
2021-07-23 00:51:19 +08:00
|
|
|
|
log_config=LOGGING_CONFIG,
|
2021-11-22 23:21:26 +08:00
|
|
|
|
**kwargs,
|
|
|
|
|
)
|
2021-07-23 00:51:19 +08:00
|
|
|
|
|
2021-12-06 22:19:05 +08:00
|
|
|
|
async def _handle_http(
|
|
|
|
|
self,
|
|
|
|
|
request: Request,
|
2021-12-18 23:19:37 +08:00
|
|
|
|
setup: HTTPServerSetup,
|
2021-12-22 16:53:55 +08:00
|
|
|
|
) -> Response:
|
2021-12-24 23:15:28 +08:00
|
|
|
|
json: Any = None
|
2022-08-14 19:41:00 +08:00
|
|
|
|
with contextlib.suppress(Exception):
|
2021-12-24 23:15:28 +08:00
|
|
|
|
json = await request.json()
|
|
|
|
|
|
|
|
|
|
data: Optional[dict] = None
|
|
|
|
|
files: Optional[List[Tuple[str, FileTypes]]] = None
|
2022-08-14 19:41:00 +08:00
|
|
|
|
with contextlib.suppress(Exception):
|
2021-12-24 23:15:28 +08:00
|
|
|
|
form = await request.form()
|
|
|
|
|
data = {}
|
|
|
|
|
files = []
|
|
|
|
|
for key, value in form.multi_items():
|
|
|
|
|
if isinstance(value, UploadFile):
|
|
|
|
|
files.append(
|
|
|
|
|
(key, (value.filename, value.file, value.content_type))
|
|
|
|
|
)
|
|
|
|
|
else:
|
|
|
|
|
data[key] = value
|
2022-08-14 19:41:00 +08:00
|
|
|
|
|
2021-12-20 15:46:23 +08:00
|
|
|
|
http_request = BaseRequest(
|
2021-11-22 23:21:26 +08:00
|
|
|
|
request.method,
|
2021-12-18 23:19:37 +08:00
|
|
|
|
str(request.url),
|
|
|
|
|
headers=request.headers.items(),
|
|
|
|
|
cookies=request.cookies,
|
|
|
|
|
content=await request.body(),
|
2021-12-24 23:15:28 +08:00
|
|
|
|
data=data,
|
|
|
|
|
json=json,
|
|
|
|
|
files=files,
|
2021-12-18 23:19:37 +08:00
|
|
|
|
version=request.scope["http_version"],
|
2021-11-22 23:21:26 +08:00
|
|
|
|
)
|
2020-08-25 18:02:18 +08:00
|
|
|
|
|
2021-12-18 23:19:37 +08:00
|
|
|
|
response = await setup.handle_func(http_request)
|
2022-08-14 19:41:00 +08:00
|
|
|
|
return Response(
|
|
|
|
|
response.content, response.status_code, dict(response.headers.items())
|
|
|
|
|
)
|
2020-08-10 13:06:02 +08:00
|
|
|
|
|
2021-12-18 23:19:37 +08:00
|
|
|
|
async def _handle_ws(self, websocket: WebSocket, setup: WebSocketServerSetup):
|
2021-12-20 15:46:23 +08:00
|
|
|
|
request = BaseRequest(
|
2021-12-18 23:19:37 +08:00
|
|
|
|
"GET",
|
|
|
|
|
str(websocket.url),
|
|
|
|
|
headers=websocket.headers.items(),
|
|
|
|
|
cookies=websocket.cookies,
|
2021-12-22 16:53:55 +08:00
|
|
|
|
version=websocket.scope.get("http_version", "1.1"),
|
2021-12-18 23:19:37 +08:00
|
|
|
|
)
|
|
|
|
|
ws = FastAPIWebSocket(
|
|
|
|
|
request=request,
|
|
|
|
|
websocket=websocket,
|
2021-11-22 23:21:26 +08:00
|
|
|
|
)
|
2020-08-25 18:02:18 +08:00
|
|
|
|
|
2021-12-18 23:19:37 +08:00
|
|
|
|
await setup.handle_func(ws)
|
2020-07-15 20:39:59 +08:00
|
|
|
|
|
2021-11-27 12:16:31 +08:00
|
|
|
|
|
2021-12-18 23:19:37 +08:00
|
|
|
|
class FastAPIWebSocket(BaseWebSocket):
|
2022-01-22 15:23:07 +08:00
|
|
|
|
"""FastAPI WebSocket Wrapper"""
|
|
|
|
|
|
2021-12-18 23:19:37 +08:00
|
|
|
|
@overrides(BaseWebSocket)
|
2021-12-20 15:46:23 +08:00
|
|
|
|
def __init__(self, *, request: BaseRequest, websocket: WebSocket):
|
2021-12-18 23:19:37 +08:00
|
|
|
|
super().__init__(request=request)
|
|
|
|
|
self.websocket = websocket
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
@overrides(BaseWebSocket)
|
|
|
|
|
def closed(self) -> bool:
|
|
|
|
|
return (
|
|
|
|
|
self.websocket.client_state == WebSocketState.DISCONNECTED
|
|
|
|
|
or self.websocket.application_state == WebSocketState.DISCONNECTED
|
|
|
|
|
)
|
2020-07-15 20:39:59 +08:00
|
|
|
|
|
2020-08-07 17:51:57 +08:00
|
|
|
|
@overrides(BaseWebSocket)
|
2021-12-21 18:22:14 +08:00
|
|
|
|
async def accept(self) -> None:
|
2021-12-18 23:19:37 +08:00
|
|
|
|
await self.websocket.accept()
|
2020-07-15 20:39:59 +08:00
|
|
|
|
|
2020-08-07 17:51:57 +08:00
|
|
|
|
@overrides(BaseWebSocket)
|
2021-12-21 18:22:14 +08:00
|
|
|
|
async def close(
|
|
|
|
|
self, code: int = status.WS_1000_NORMAL_CLOSURE, reason: str = ""
|
|
|
|
|
) -> None:
|
2022-11-24 11:35:31 +08:00
|
|
|
|
await self.websocket.close(code, reason)
|
2020-07-15 20:39:59 +08:00
|
|
|
|
|
2022-05-14 21:06:57 +08:00
|
|
|
|
@overrides(BaseWebSocket)
|
|
|
|
|
async def receive(self) -> Union[str, bytes]:
|
|
|
|
|
# assert self.websocket.application_state == WebSocketState.CONNECTED
|
|
|
|
|
msg = await self.websocket.receive()
|
|
|
|
|
if msg["type"] == "websocket.disconnect":
|
|
|
|
|
raise WebSocketClosed(msg["code"])
|
|
|
|
|
return msg["text"] if "text" in msg else msg["bytes"]
|
|
|
|
|
|
2020-08-07 17:51:57 +08:00
|
|
|
|
@overrides(BaseWebSocket)
|
2021-12-30 12:11:31 +08:00
|
|
|
|
@catch_closed
|
2022-05-14 21:06:57 +08:00
|
|
|
|
async def receive_text(self) -> str:
|
2021-12-18 23:19:37 +08:00
|
|
|
|
return await self.websocket.receive_text()
|
2021-06-10 21:52:20 +08:00
|
|
|
|
|
|
|
|
|
@overrides(BaseWebSocket)
|
2021-12-30 12:11:31 +08:00
|
|
|
|
@catch_closed
|
2021-06-10 21:52:20 +08:00
|
|
|
|
async def receive_bytes(self) -> bytes:
|
2021-12-18 23:19:37 +08:00
|
|
|
|
return await self.websocket.receive_bytes()
|
2021-06-10 21:52:20 +08:00
|
|
|
|
|
|
|
|
|
@overrides(BaseWebSocket)
|
2022-05-14 21:06:57 +08:00
|
|
|
|
async def send_text(self, data: str) -> None:
|
2021-12-18 23:19:37 +08:00
|
|
|
|
await self.websocket.send({"type": "websocket.send", "text": data})
|
2020-07-15 20:39:59 +08:00
|
|
|
|
|
2020-08-07 17:51:57 +08:00
|
|
|
|
@overrides(BaseWebSocket)
|
2021-06-10 21:52:20 +08:00
|
|
|
|
async def send_bytes(self, data: bytes) -> None:
|
2021-12-18 23:19:37 +08:00
|
|
|
|
await self.websocket.send({"type": "websocket.send", "bytes": data})
|
2022-01-22 15:23:07 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
__autodoc__ = {"catch_closed": False}
|