mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2026-02-08 14:10:54 +00:00
run lint and fix errors, except mypy
This commit is contained in:
@ -1,4 +1,6 @@
|
||||
from libp2p.exceptions import BaseLibp2pError
|
||||
from libp2p.exceptions import (
|
||||
BaseLibp2pError,
|
||||
)
|
||||
|
||||
|
||||
class MultiselectCommunicatorError(BaseLibp2pError):
|
||||
|
||||
@ -1,19 +1,34 @@
|
||||
from typing import Dict, Tuple
|
||||
from typing import (
|
||||
Dict,
|
||||
Tuple,
|
||||
)
|
||||
|
||||
from libp2p.typing import StreamHandlerFn, TProtocol
|
||||
from libp2p.typing import (
|
||||
StreamHandlerFn,
|
||||
TProtocol,
|
||||
)
|
||||
|
||||
from .exceptions import MultiselectCommunicatorError, MultiselectError
|
||||
from .multiselect_communicator_interface import IMultiselectCommunicator
|
||||
from .multiselect_muxer_interface import IMultiselectMuxer
|
||||
from .exceptions import (
|
||||
MultiselectCommunicatorError,
|
||||
MultiselectError,
|
||||
)
|
||||
from .multiselect_communicator_interface import (
|
||||
IMultiselectCommunicator,
|
||||
)
|
||||
from .multiselect_muxer_interface import (
|
||||
IMultiselectMuxer,
|
||||
)
|
||||
|
||||
MULTISELECT_PROTOCOL_ID = "/multistream/1.0.0"
|
||||
PROTOCOL_NOT_FOUND_MSG = "na"
|
||||
|
||||
|
||||
class Multiselect(IMultiselectMuxer):
|
||||
"""Multiselect module that is responsible for responding to a multiselect
|
||||
"""
|
||||
Multiselect module that is responsible for responding to a multiselect
|
||||
client and deciding on a specific protocol and handler pair to use for
|
||||
communication."""
|
||||
communication.
|
||||
"""
|
||||
|
||||
handlers: Dict[TProtocol, StreamHandlerFn]
|
||||
|
||||
|
||||
@ -1,18 +1,31 @@
|
||||
from typing import Sequence
|
||||
from typing import (
|
||||
Sequence,
|
||||
)
|
||||
|
||||
from libp2p.typing import TProtocol
|
||||
from libp2p.typing import (
|
||||
TProtocol,
|
||||
)
|
||||
|
||||
from .exceptions import MultiselectClientError, MultiselectCommunicatorError
|
||||
from .multiselect_client_interface import IMultiselectClient
|
||||
from .multiselect_communicator_interface import IMultiselectCommunicator
|
||||
from .exceptions import (
|
||||
MultiselectClientError,
|
||||
MultiselectCommunicatorError,
|
||||
)
|
||||
from .multiselect_client_interface import (
|
||||
IMultiselectClient,
|
||||
)
|
||||
from .multiselect_communicator_interface import (
|
||||
IMultiselectCommunicator,
|
||||
)
|
||||
|
||||
MULTISELECT_PROTOCOL_ID = "/multistream/1.0.0"
|
||||
PROTOCOL_NOT_FOUND_MSG = "na"
|
||||
|
||||
|
||||
class MultiselectClient(IMultiselectClient):
|
||||
"""Client for communicating with receiver's multiselect module in order to
|
||||
select a protocol id to communicate over."""
|
||||
"""
|
||||
Client for communicating with receiver's multiselect module in order to
|
||||
select a protocol id to communicate over.
|
||||
"""
|
||||
|
||||
async def handshake(self, communicator: IMultiselectCommunicator) -> None:
|
||||
"""
|
||||
|
||||
@ -1,16 +1,26 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import Sequence
|
||||
from abc import (
|
||||
ABC,
|
||||
abstractmethod,
|
||||
)
|
||||
from typing import (
|
||||
Sequence,
|
||||
)
|
||||
|
||||
from libp2p.protocol_muxer.multiselect_communicator_interface import (
|
||||
IMultiselectCommunicator,
|
||||
)
|
||||
from libp2p.typing import TProtocol
|
||||
from libp2p.typing import (
|
||||
TProtocol,
|
||||
)
|
||||
|
||||
|
||||
class IMultiselectClient(ABC):
|
||||
"""Client for communicating with receiver's multiselect module in order to
|
||||
select a protocol id to communicate over."""
|
||||
"""
|
||||
Client for communicating with receiver's multiselect module in order to
|
||||
select a protocol id to communicate over.
|
||||
"""
|
||||
|
||||
@abstractmethod
|
||||
async def handshake(self, communicator: IMultiselectCommunicator) -> None:
|
||||
"""
|
||||
Ensure that the client and multiselect are both using the same
|
||||
@ -34,6 +44,7 @@ class IMultiselectClient(ABC):
|
||||
:return: selected protocol
|
||||
"""
|
||||
|
||||
@abstractmethod
|
||||
async def try_select(
|
||||
self, communicator: IMultiselectCommunicator, protocol: TProtocol
|
||||
) -> TProtocol:
|
||||
|
||||
@ -1,10 +1,23 @@
|
||||
from libp2p.exceptions import ParseError
|
||||
from libp2p.io.abc import ReadWriteCloser
|
||||
from libp2p.io.exceptions import IOException
|
||||
from libp2p.utils import encode_delim, read_delim
|
||||
from libp2p.exceptions import (
|
||||
ParseError,
|
||||
)
|
||||
from libp2p.io.abc import (
|
||||
ReadWriteCloser,
|
||||
)
|
||||
from libp2p.io.exceptions import (
|
||||
IOException,
|
||||
)
|
||||
from libp2p.utils import (
|
||||
encode_delim,
|
||||
read_delim,
|
||||
)
|
||||
|
||||
from .exceptions import MultiselectCommunicatorError
|
||||
from .multiselect_communicator_interface import IMultiselectCommunicator
|
||||
from .exceptions import (
|
||||
MultiselectCommunicatorError,
|
||||
)
|
||||
from .multiselect_communicator_interface import (
|
||||
IMultiselectCommunicator,
|
||||
)
|
||||
|
||||
|
||||
class MultiselectCommunicator(IMultiselectCommunicator):
|
||||
@ -16,7 +29,7 @@ class MultiselectCommunicator(IMultiselectCommunicator):
|
||||
async def write(self, msg_str: str) -> None:
|
||||
"""
|
||||
:raise MultiselectCommunicatorError: raised when failed to write to underlying reader
|
||||
"""
|
||||
""" # noqa: E501
|
||||
msg_bytes = encode_delim(msg_str.encode())
|
||||
try:
|
||||
await self.read_writer.write(msg_bytes)
|
||||
@ -28,7 +41,7 @@ class MultiselectCommunicator(IMultiselectCommunicator):
|
||||
async def read(self) -> str:
|
||||
"""
|
||||
:raise MultiselectCommunicatorError: raised when failed to read from underlying reader
|
||||
"""
|
||||
""" # noqa: E501
|
||||
try:
|
||||
data = await read_delim(self.read_writer)
|
||||
# `IOException` includes `IncompleteReadError` and `StreamError`
|
||||
|
||||
@ -1,10 +1,15 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from abc import (
|
||||
ABC,
|
||||
abstractmethod,
|
||||
)
|
||||
|
||||
|
||||
class IMultiselectCommunicator(ABC):
|
||||
"""Communicator helper class that ensures both the client and multistream
|
||||
"""
|
||||
Communicator helper class that ensures both the client and multistream
|
||||
module will follow the same multistream protocol, which is necessary for
|
||||
them to work."""
|
||||
them to work.
|
||||
"""
|
||||
|
||||
@abstractmethod
|
||||
async def write(self, msg_str: str) -> None:
|
||||
|
||||
@ -1,15 +1,28 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import Dict, Tuple
|
||||
from abc import (
|
||||
ABC,
|
||||
abstractmethod,
|
||||
)
|
||||
from typing import (
|
||||
Dict,
|
||||
Tuple,
|
||||
)
|
||||
|
||||
from libp2p.typing import StreamHandlerFn, TProtocol
|
||||
from libp2p.typing import (
|
||||
StreamHandlerFn,
|
||||
TProtocol,
|
||||
)
|
||||
|
||||
from .multiselect_communicator_interface import IMultiselectCommunicator
|
||||
from .multiselect_communicator_interface import (
|
||||
IMultiselectCommunicator,
|
||||
)
|
||||
|
||||
|
||||
class IMultiselectMuxer(ABC):
|
||||
"""Multiselect module that is responsible for responding to a multiselect
|
||||
"""
|
||||
Multiselect module that is responsible for responding to a multiselect
|
||||
client and deciding on a specific protocol and handler pair to use for
|
||||
communication."""
|
||||
communication.
|
||||
"""
|
||||
|
||||
handlers: Dict[TProtocol, StreamHandlerFn]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user