nonebot2/nonebot/drivers/__init__.py

80 lines
1.6 KiB
Python
Raw Normal View History

2020-07-04 22:51:10 +08:00
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
2020-07-18 18:18:43 +08:00
import abc
2020-07-04 22:51:10 +08:00
from typing import Optional
from ipaddress import IPv4Address
2020-07-11 17:32:03 +08:00
from nonebot.config import Config
2020-07-04 22:51:10 +08:00
2020-07-18 18:18:43 +08:00
class BaseDriver(abc.ABC):
2020-07-04 22:51:10 +08:00
2020-07-18 18:18:43 +08:00
@abc.abstractmethod
2020-07-11 17:32:03 +08:00
def __init__(self, config: Config):
2020-07-05 20:39:34 +08:00
raise NotImplementedError
2020-07-04 22:51:10 +08:00
@property
2020-07-18 18:18:43 +08:00
@abc.abstractmethod
2020-07-04 22:51:10 +08:00
def server_app(self):
raise NotImplementedError
@property
2020-07-18 18:18:43 +08:00
@abc.abstractmethod
2020-07-04 22:51:10 +08:00
def asgi(self):
raise NotImplementedError
@property
2020-07-18 18:18:43 +08:00
@abc.abstractmethod
2020-07-04 22:51:10 +08:00
def logger(self):
raise NotImplementedError
2020-07-18 18:18:43 +08:00
@abc.abstractmethod
2020-07-04 22:51:10 +08:00
def run(self,
host: Optional[IPv4Address] = None,
port: Optional[int] = None,
*args,
**kwargs):
raise NotImplementedError
2020-07-05 20:39:34 +08:00
2020-07-18 18:18:43 +08:00
@abc.abstractmethod
2020-07-05 20:39:34 +08:00
async def _handle_http(self):
raise NotImplementedError
2020-07-18 18:18:43 +08:00
@abc.abstractmethod
2020-07-05 20:39:34 +08:00
async def _handle_ws_reverse(self):
raise NotImplementedError
2020-07-11 17:32:03 +08:00
class BaseWebSocket(object):
2020-07-18 18:18:43 +08:00
@abc.abstractmethod
def __init__(self, websocket):
self._websocket = websocket
@property
2020-07-18 18:18:43 +08:00
@abc.abstractmethod
def websocket(self):
return self._websocket
@property
2020-07-18 18:18:43 +08:00
@abc.abstractmethod
def closed(self):
raise NotImplementedError
2020-07-18 18:18:43 +08:00
@abc.abstractmethod
async def accept(self):
raise NotImplementedError
2020-07-18 18:18:43 +08:00
@abc.abstractmethod
2020-08-01 22:03:40 +08:00
async def close(self, code: int):
raise NotImplementedError
2020-07-18 18:18:43 +08:00
@abc.abstractmethod
async def receive(self) -> dict:
raise NotImplementedError
2020-07-18 18:18:43 +08:00
@abc.abstractmethod
async def send(self, data: dict):
raise NotImplementedError