Merge pull request #331 from dmuhs/fix/docs-format

Add automatic docstring formatting
This commit is contained in:
Piper Merriam
2019-10-28 09:39:52 -06:00
committed by GitHub
73 changed files with 519 additions and 561 deletions

View File

@ -2,12 +2,12 @@ from libp2p.exceptions import BaseLibp2pError
class MultiselectCommunicatorError(BaseLibp2pError):
"""Raised when an error occurs during read/write via communicator"""
"""Raised when an error occurs during read/write via communicator."""
class MultiselectError(BaseLibp2pError):
"""Raised when an error occurs in multiselect process"""
"""Raised when an error occurs in multiselect process."""
class MultiselectClientError(BaseLibp2pError):
"""Raised when an error occurs in protocol selection process"""
"""Raised when an error occurs in protocol selection process."""

View File

@ -11,11 +11,9 @@ PROTOCOL_NOT_FOUND_MSG = "na"
class Multiselect(IMultiselectMuxer):
"""
Multiselect module that is responsible for responding to
a multiselect client and deciding on
a specific protocol and handler pair to use for communication
"""
"""Multiselect module that is responsible for responding to a multiselect
client and deciding on a specific protocol and handler pair to use for
communication."""
handlers: Dict[TProtocol, StreamHandlerFn]
@ -28,7 +26,8 @@ class Multiselect(IMultiselectMuxer):
def add_handler(self, protocol: TProtocol, handler: StreamHandlerFn) -> None:
"""
Store the handler with the given protocol
Store the handler with the given protocol.
:param protocol: protocol name
:param handler: handler function
"""
@ -38,7 +37,8 @@ class Multiselect(IMultiselectMuxer):
self, communicator: IMultiselectCommunicator
) -> Tuple[TProtocol, StreamHandlerFn]:
"""
Negotiate performs protocol selection
Negotiate performs protocol selection.
:param stream: stream to negotiate on
:return: selected protocol name, handler function
:raise MultiselectError: raised when negotiation failed
@ -70,7 +70,8 @@ class Multiselect(IMultiselectMuxer):
async def handshake(self, communicator: IMultiselectCommunicator) -> None:
"""
Perform handshake to agree on multiselect protocol
Perform handshake to agree on multiselect protocol.
:param communicator: communicator to use
:raise MultiselectError: raised when handshake failed
"""
@ -93,7 +94,8 @@ class Multiselect(IMultiselectMuxer):
def is_valid_handshake(handshake_contents: str) -> bool:
"""
Determine if handshake is valid and should be confirmed
Determine if handshake is valid and should be confirmed.
:param handshake_contents: contents of handshake message
:return: true if handshake is complete, false otherwise
"""

View File

@ -11,15 +11,14 @@ 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:
"""
Ensure that the client and multiselect
are both using the same multiselect protocol
Ensure that the client and multiselect are both using the same
multiselect protocol.
:param stream: stream to communicate with multiselect over
:raise MultiselectClientError: raised when handshake failed
"""
@ -40,9 +39,10 @@ class MultiselectClient(IMultiselectClient):
self, protocols: Sequence[TProtocol], communicator: IMultiselectCommunicator
) -> TProtocol:
"""
For each protocol, send message to multiselect selecting protocol
and fail if multiselect does not return same protocol. Returns first
For each protocol, send message to multiselect selecting protocol and
fail if multiselect does not return same protocol. Returns first
protocol that multiselect agrees on (i.e. that multiselect selects)
:param protocol: protocol to select
:param stream: stream to communicate with multiselect over
:return: selected protocol
@ -63,7 +63,8 @@ class MultiselectClient(IMultiselectClient):
self, communicator: IMultiselectCommunicator, protocol: TProtocol
) -> TProtocol:
"""
Try to select the given protocol or raise exception if fails
Try to select the given protocol or raise exception if fails.
:param communicator: communicator to use to communicate with counterparty
:param protocol: protocol to select
:raise MultiselectClientError: raised when protocol negotiation failed
@ -88,7 +89,8 @@ class MultiselectClient(IMultiselectClient):
def is_valid_handshake(handshake_contents: str) -> bool:
"""
Determine if handshake is valid and should be confirmed
Determine if handshake is valid and should be confirmed.
:param handshake_contents: contents of handshake message
:return: true if handshake is complete, false otherwise
"""

View File

@ -8,15 +8,14 @@ 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."""
async def handshake(self, communicator: IMultiselectCommunicator) -> None:
"""
Ensure that the client and multiselect
are both using the same multiselect protocol
Ensure that the client and multiselect are both using the same
multiselect protocol.
:param stream: stream to communicate with multiselect over
:raise Exception: multiselect protocol ID mismatch
"""
@ -26,9 +25,10 @@ class IMultiselectClient(ABC):
self, protocols: Sequence[TProtocol], communicator: IMultiselectCommunicator
) -> TProtocol:
"""
For each protocol, send message to multiselect selecting protocol
and fail if multiselect does not return same protocol. Returns first
For each protocol, send message to multiselect selecting protocol and
fail if multiselect does not return same protocol. Returns first
protocol that multiselect agrees on (i.e. that multiselect selects)
:param protocol: protocol to select
:param stream: stream to communicate with multiselect over
:return: selected protocol
@ -38,7 +38,8 @@ class IMultiselectClient(ABC):
self, communicator: IMultiselectCommunicator, protocol: TProtocol
) -> TProtocol:
"""
Try to select the given protocol or raise exception if fails
Try to select the given protocol or raise exception if fails.
:param communicator: communicator to use to communicate with counterparty
:param protocol: protocol to select
:raise Exception: error in protocol selection

View File

@ -2,21 +2,18 @@ from abc import ABC, abstractmethod
class IMultiselectCommunicator(ABC):
"""
Communicator helper class that ensures both the client
and multistream module will follow the same multistream protocol,
which is necessary for them to work
"""
"""Communicator helper class that ensures both the client and multistream
module will follow the same multistream protocol, which is necessary for
them to work."""
@abstractmethod
async def write(self, msg_str: str) -> None:
"""
Write message to stream
Write message to stream.
:param msg_str: message to write
"""
@abstractmethod
async def read(self) -> str:
"""
Reads message from stream until EOF
"""
"""Reads message from stream until EOF."""

View File

@ -7,18 +7,17 @@ from .multiselect_communicator_interface import IMultiselectCommunicator
class IMultiselectMuxer(ABC):
"""
Multiselect module that is responsible for responding to
a multiselect client and deciding on
a specific protocol and handler pair to use for communication
"""
"""Multiselect module that is responsible for responding to a multiselect
client and deciding on a specific protocol and handler pair to use for
communication."""
handlers: Dict[TProtocol, StreamHandlerFn]
@abstractmethod
def add_handler(self, protocol: TProtocol, handler: StreamHandlerFn) -> None:
"""
Store the handler with the given protocol
Store the handler with the given protocol.
:param protocol: protocol name
:param handler: handler function
"""
@ -28,7 +27,8 @@ class IMultiselectMuxer(ABC):
self, communicator: IMultiselectCommunicator
) -> Tuple[TProtocol, StreamHandlerFn]:
"""
Negotiate performs protocol selection
Negotiate performs protocol selection.
:param stream: stream to negotiate on
:return: selected protocol name, handler function
:raise Exception: negotiation failed exception