mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2025-12-31 20:36:24 +00:00
Add automatic docstring formatter and apply
This commit is contained in:
@ -24,9 +24,7 @@ class RawConnection(IRawConnection):
|
||||
self._drain_lock = asyncio.Lock()
|
||||
|
||||
async def write(self, data: bytes) -> None:
|
||||
"""
|
||||
Raise `RawConnError` if the underlying connection breaks
|
||||
"""
|
||||
"""Raise `RawConnError` if the underlying connection breaks."""
|
||||
try:
|
||||
self.writer.write(data)
|
||||
except ConnectionResetError as error:
|
||||
@ -41,9 +39,8 @@ class RawConnection(IRawConnection):
|
||||
raise RawConnError(error)
|
||||
|
||||
async def read(self, n: int = -1) -> bytes:
|
||||
"""
|
||||
Read up to ``n`` bytes from the underlying stream.
|
||||
This call is delegated directly to the underlying ``self.reader``.
|
||||
"""Read up to ``n`` bytes from the underlying stream. This call is
|
||||
delegated directly to the underlying ``self.reader``.
|
||||
|
||||
Raise `RawConnError` if the underlying connection breaks
|
||||
"""
|
||||
|
||||
@ -2,8 +2,6 @@ from libp2p.io.abc import ReadWriteCloser
|
||||
|
||||
|
||||
class IRawConnection(ReadWriteCloser):
|
||||
"""
|
||||
A Raw Connection provides a Reader and a Writer
|
||||
"""
|
||||
"""A Raw Connection provides a Reader and a Writer."""
|
||||
|
||||
initiator: bool
|
||||
|
||||
@ -29,8 +29,7 @@ class INetwork(ABC):
|
||||
|
||||
@abstractmethod
|
||||
async def dial_peer(self, peer_id: ID) -> INetConn:
|
||||
"""
|
||||
dial_peer try to create a connection to peer_id
|
||||
"""dial_peer try to create a connection to peer_id.
|
||||
|
||||
:param peer_id: peer if we want to dial
|
||||
:raises SwarmException: raised when an error occurs
|
||||
@ -47,9 +46,7 @@ class INetwork(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def set_stream_handler(self, stream_handler: StreamHandlerFn) -> None:
|
||||
"""
|
||||
Set the stream handler for all incoming streams.
|
||||
"""
|
||||
"""Set the stream handler for all incoming streams."""
|
||||
|
||||
@abstractmethod
|
||||
async def listen(self, *multiaddrs: Sequence[Multiaddr]) -> bool:
|
||||
|
||||
@ -38,8 +38,8 @@ class NetStream(INetStream):
|
||||
self.protocol_id = protocol_id
|
||||
|
||||
async def read(self, n: int = -1) -> bytes:
|
||||
"""
|
||||
reads from stream
|
||||
"""reads from stream.
|
||||
|
||||
:param n: number of bytes to read
|
||||
:return: bytes of input
|
||||
"""
|
||||
@ -51,8 +51,8 @@ class NetStream(INetStream):
|
||||
raise StreamReset from error
|
||||
|
||||
async def write(self, data: bytes) -> int:
|
||||
"""
|
||||
write to stream
|
||||
"""write to stream.
|
||||
|
||||
:return: number of bytes written
|
||||
"""
|
||||
try:
|
||||
@ -61,9 +61,7 @@ class NetStream(INetStream):
|
||||
raise StreamClosed from error
|
||||
|
||||
async def close(self) -> None:
|
||||
"""
|
||||
close stream
|
||||
"""
|
||||
"""close stream."""
|
||||
await self.muxed_stream.close()
|
||||
|
||||
async def reset(self) -> None:
|
||||
|
||||
@ -23,6 +23,4 @@ class INetStream(ReadWriteCloser):
|
||||
|
||||
@abstractmethod
|
||||
async def reset(self) -> None:
|
||||
"""
|
||||
Close both ends of the stream.
|
||||
"""
|
||||
"""Close both ends of the stream."""
|
||||
|
||||
@ -69,8 +69,8 @@ class Swarm(INetwork):
|
||||
self.common_stream_handler = stream_handler
|
||||
|
||||
async def dial_peer(self, peer_id: ID) -> INetConn:
|
||||
"""
|
||||
dial_peer try to create a connection to peer_id
|
||||
"""dial_peer try to create a connection to peer_id.
|
||||
|
||||
:param peer_id: peer if we want to dial
|
||||
:raises SwarmException: raised when an error occurs
|
||||
:return: muxed connection
|
||||
@ -254,10 +254,9 @@ class Swarm(INetwork):
|
||||
logger.debug("successfully close the connection to peer %s", peer_id)
|
||||
|
||||
async def add_conn(self, muxed_conn: IMuxedConn) -> SwarmConn:
|
||||
"""
|
||||
Add a `IMuxedConn` to `Swarm` as a `SwarmConn`, notify "connected",
|
||||
and start to monitor the connection for its new streams and disconnection.
|
||||
"""
|
||||
"""Add a `IMuxedConn` to `Swarm` as a `SwarmConn`, notify "connected",
|
||||
and start to monitor the connection for its new streams and
|
||||
disconnection."""
|
||||
swarm_conn = SwarmConn(muxed_conn, self)
|
||||
# Store muxed_conn with peer id
|
||||
self.connections[muxed_conn.peer_id] = swarm_conn
|
||||
@ -267,9 +266,8 @@ class Swarm(INetwork):
|
||||
return swarm_conn
|
||||
|
||||
def remove_conn(self, swarm_conn: SwarmConn) -> None:
|
||||
"""
|
||||
Simply remove the connection from Swarm's records, without closing the connection.
|
||||
"""
|
||||
"""Simply remove the connection from Swarm's records, without closing
|
||||
the connection."""
|
||||
peer_id = swarm_conn.muxed_conn.peer_id
|
||||
if peer_id not in self.connections:
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user