2019-09-04 12:42:45 +08:00
|
|
|
from abc import ABC, abstractmethod
|
|
|
|
|
|
|
|
|
|
|
|
class Closer(ABC):
|
|
|
|
async def close(self) -> None:
|
|
|
|
...
|
|
|
|
|
|
|
|
|
|
|
|
class Reader(ABC):
|
|
|
|
@abstractmethod
|
2020-01-26 23:03:38 +08:00
|
|
|
async def read(self, n: int = None) -> bytes:
|
2019-09-04 12:42:45 +08:00
|
|
|
...
|
|
|
|
|
|
|
|
|
|
|
|
class Writer(ABC):
|
|
|
|
@abstractmethod
|
2020-02-07 18:33:15 +08:00
|
|
|
async def write(self, data: bytes) -> None:
|
2019-09-04 12:42:45 +08:00
|
|
|
...
|
|
|
|
|
|
|
|
|
|
|
|
class WriteCloser(Writer, Closer):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class ReadCloser(Reader, Closer):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class ReadWriter(Reader, Writer):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class ReadWriteCloser(Reader, Writer, Closer):
|
|
|
|
pass
|
2020-02-17 17:30:29 +08:00
|
|
|
|
|
|
|
|
|
|
|
class MsgReader(ABC):
|
|
|
|
@abstractmethod
|
|
|
|
async def read_msg(self) -> bytes:
|
|
|
|
...
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
async def next_msg_len(self) -> int:
|
|
|
|
...
|
|
|
|
|
|
|
|
|
|
|
|
class MsgWriter(ABC):
|
|
|
|
@abstractmethod
|
|
|
|
async def write_msg(self, msg: bytes) -> None:
|
|
|
|
...
|
|
|
|
|
|
|
|
|
|
|
|
class MsgReadWriter(MsgReader, MsgWriter):
|
|
|
|
pass
|