mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2026-03-22 21:21:27 +00:00
Merge pull request #331 from dmuhs/fix/docs-format
Add automatic docstring formatting
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:
|
||||
@ -42,8 +40,8 @@ class RawConnection(IRawConnection):
|
||||
|
||||
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."""
|
||||
|
||||
is_initiator: bool
|
||||
|
||||
@ -30,7 +30,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 +47,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:
|
||||
|
||||
@ -39,7 +39,8 @@ class NetStream(INetStream):
|
||||
|
||||
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
|
||||
"""
|
||||
@ -52,7 +53,8 @@ class NetStream(INetStream):
|
||||
|
||||
async def write(self, data: bytes) -> int:
|
||||
"""
|
||||
write to stream
|
||||
write to stream.
|
||||
|
||||
:return: number of bytes written
|
||||
"""
|
||||
try:
|
||||
@ -61,9 +63,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."""
|
||||
|
||||
@ -70,7 +70,8 @@ class Swarm(INetwork):
|
||||
|
||||
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 +255,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 +267,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