simplify some of the msgio class hierarchy via PR feedback

This commit is contained in:
Alex Stokes 2019-09-04 09:57:04 -07:00
parent 2a02f92f77
commit a764fd4e6f
No known key found for this signature in database
GPG Key ID: 51CE1721B245C086

View File

@ -8,14 +8,7 @@ NOTE: currently missing the capability to indicate lengths by "varint" method.
# TODO unify w/ https://github.com/libp2p/py-libp2p/blob/1aed52856f56a4b791696bbcbac31b5f9c2e88c9/libp2p/utils.py#L85-L99 # noqa: E501 # TODO unify w/ https://github.com/libp2p/py-libp2p/blob/1aed52856f56a4b791696bbcbac31b5f9c2e88c9/libp2p/utils.py#L85-L99 # noqa: E501
from typing import Optional, cast from typing import Optional, cast
from libp2p.io.abc import ( from libp2p.io.abc import Closer, ReadCloser, Reader, ReadWriteCloser, WriteCloser
Closer,
ReadCloser,
Reader,
ReadWriteCloser,
WriteCloser,
Writer,
)
from libp2p.io.utils import read_exactly from libp2p.io.utils import read_exactly
SIZE_LEN_BYTES = 4 SIZE_LEN_BYTES = 4
@ -42,11 +35,10 @@ async def read_next_message(reader: Reader) -> bytes:
return await reader.read(length) return await reader.read(length)
class MsgIOWriter(Writer, Closer): class MsgIOWriter(WriteCloser):
write_closer: WriteCloser write_closer: WriteCloser
def __init__(self, write_closer: WriteCloser) -> None: def __init__(self, write_closer: WriteCloser) -> None:
super().__init__()
self.write_closer = write_closer self.write_closer = write_closer
async def write(self, data: bytes) -> int: async def write(self, data: bytes) -> int:
@ -61,7 +53,7 @@ class MsgIOWriter(Writer, Closer):
await self.write_closer.close() await self.write_closer.close()
class MsgIOReader(Reader, Closer): class MsgIOReader(ReadCloser):
read_closer: ReadCloser read_closer: ReadCloser
next_length: Optional[int] next_length: Optional[int]