mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2026-03-24 06:01:26 +00:00
Add automatic docstring formatter and apply
This commit is contained in:
@ -41,8 +41,8 @@ class Mplex(IMuxedConn):
|
||||
_tasks: List["asyncio.Future[Any]"]
|
||||
|
||||
def __init__(self, secured_conn: ISecureConn, peer_id: ID) -> None:
|
||||
"""
|
||||
create a new muxed connection
|
||||
"""create a new muxed connection.
|
||||
|
||||
:param secured_conn: an instance of ``ISecureConn``
|
||||
:param generic_protocol_handler: generic protocol handler
|
||||
for new muxed streams
|
||||
@ -72,9 +72,7 @@ class Mplex(IMuxedConn):
|
||||
return self.secured_conn.initiator
|
||||
|
||||
async def close(self) -> None:
|
||||
"""
|
||||
close the stream muxer and underlying secured connection
|
||||
"""
|
||||
"""close the stream muxer and underlying secured connection."""
|
||||
if self.event_shutting_down.is_set():
|
||||
return
|
||||
# Set the `event_shutting_down`, to allow graceful shutdown.
|
||||
@ -84,15 +82,15 @@ class Mplex(IMuxedConn):
|
||||
await self.event_closed.wait()
|
||||
|
||||
def is_closed(self) -> bool:
|
||||
"""
|
||||
check connection is fully closed
|
||||
"""check connection is fully closed.
|
||||
|
||||
:return: true if successful
|
||||
"""
|
||||
return self.event_closed.is_set()
|
||||
|
||||
def _get_next_channel_id(self) -> int:
|
||||
"""
|
||||
Get next available stream id
|
||||
"""Get next available stream id.
|
||||
|
||||
:return: next available stream id for the connection
|
||||
"""
|
||||
next_id = self.next_channel_id
|
||||
@ -106,8 +104,8 @@ class Mplex(IMuxedConn):
|
||||
return stream
|
||||
|
||||
async def open_stream(self) -> IMuxedStream:
|
||||
"""
|
||||
creates a new muxed_stream
|
||||
"""creates a new muxed_stream.
|
||||
|
||||
:return: a new ``MplexStream``
|
||||
"""
|
||||
channel_id = self._get_next_channel_id()
|
||||
@ -135,9 +133,7 @@ class Mplex(IMuxedConn):
|
||||
return task_coro.result()
|
||||
|
||||
async def accept_stream(self) -> IMuxedStream:
|
||||
"""
|
||||
accepts a muxed stream opened by the other end
|
||||
"""
|
||||
"""accepts a muxed stream opened by the other end."""
|
||||
return await self._wait_until_shutting_down_or_closed(
|
||||
self.new_stream_queue.get()
|
||||
)
|
||||
@ -145,8 +141,8 @@ class Mplex(IMuxedConn):
|
||||
async def send_message(
|
||||
self, flag: HeaderTags, data: Optional[bytes], stream_id: StreamID
|
||||
) -> int:
|
||||
"""
|
||||
sends a message over the connection
|
||||
"""sends a message over the connection.
|
||||
|
||||
:param header: header to use
|
||||
:param data: data to send in the message
|
||||
:param stream_id: stream the message is in
|
||||
@ -164,8 +160,8 @@ class Mplex(IMuxedConn):
|
||||
)
|
||||
|
||||
async def write_to_stream(self, _bytes: bytes) -> int:
|
||||
"""
|
||||
writes a byte array to a secured connection
|
||||
"""writes a byte array to a secured connection.
|
||||
|
||||
:param _bytes: byte array to write
|
||||
:return: length written
|
||||
"""
|
||||
@ -173,9 +169,8 @@ class Mplex(IMuxedConn):
|
||||
return len(_bytes)
|
||||
|
||||
async def handle_incoming(self) -> None:
|
||||
"""
|
||||
Read a message off of the secured connection and add it to the corresponding message buffer
|
||||
"""
|
||||
"""Read a message off of the secured connection and add it to the
|
||||
corresponding message buffer."""
|
||||
|
||||
while True:
|
||||
try:
|
||||
@ -189,8 +184,8 @@ class Mplex(IMuxedConn):
|
||||
await self._cleanup()
|
||||
|
||||
async def read_message(self) -> Tuple[int, int, bytes]:
|
||||
"""
|
||||
Read a single message off of the secured connection
|
||||
"""Read a single message off of the secured connection.
|
||||
|
||||
:return: stream_id, flag, message contents
|
||||
"""
|
||||
|
||||
@ -215,8 +210,8 @@ class Mplex(IMuxedConn):
|
||||
return channel_id, flag, message
|
||||
|
||||
async def _handle_incoming_message(self) -> None:
|
||||
"""
|
||||
Read and handle a new incoming message.
|
||||
"""Read and handle a new incoming message.
|
||||
|
||||
:raise MplexUnavailable: `Mplex` encounters fatal error or is shutting down.
|
||||
"""
|
||||
channel_id, flag, message = await self._wait_until_shutting_down_or_closed(
|
||||
|
||||
Reference in New Issue
Block a user