From 7a04ebb51f1f1af68815b1edd45a172beeecc255 Mon Sep 17 00:00:00 2001 From: Chih Cheng Liang Date: Mon, 5 Aug 2019 11:21:20 +0800 Subject: [PATCH] run black --- libp2p/stream_muxer/mplex/mplex.py | 4 +--- libp2p/stream_muxer/mplex/mplex_stream.py | 12 ++---------- libp2p/stream_muxer/mplex/utils.py | 4 +--- libp2p/transport/tcp/tcp.py | 4 +--- libp2p/transport/typing.py | 1 - libp2p/transport/upgrader.py | 8 ++------ tests/peer/test_peerinfo.py | 4 +++- 7 files changed, 10 insertions(+), 27 deletions(-) diff --git a/libp2p/stream_muxer/mplex/mplex.py b/libp2p/stream_muxer/mplex/mplex.py index f113de1..54a9e89 100644 --- a/libp2p/stream_muxer/mplex/mplex.py +++ b/libp2p/stream_muxer/mplex/mplex.py @@ -90,9 +90,7 @@ class Mplex(IMuxedConn): # Stream not created yet return None - async def open_stream( - self, protocol_id: str, multi_addr: Multiaddr - ) -> IMuxedStream: + async def open_stream(self, protocol_id: str, multi_addr: Multiaddr) -> IMuxedStream: """ creates a new muxed_stream :param protocol_id: protocol_id of stream diff --git a/libp2p/stream_muxer/mplex/mplex_stream.py b/libp2p/stream_muxer/mplex/mplex_stream.py index 3b8ceda..05a8707 100644 --- a/libp2p/stream_muxer/mplex/mplex_stream.py +++ b/libp2p/stream_muxer/mplex/mplex_stream.py @@ -47,11 +47,7 @@ class MplexStream(IMuxedStream): write to stream :return: number of bytes written """ - flag = ( - HeaderTags.MessageInitiator - if self.initiator - else HeaderTags.MessageReceiver - ) + flag = HeaderTags.MessageInitiator if self.initiator else HeaderTags.MessageReceiver return await self.mplex_conn.send_message(flag, data, self.stream_id) async def close(self) -> bool: @@ -93,11 +89,7 @@ class MplexStream(IMuxedStream): return True if not self.remote_closed: - flag = ( - HeaderTags.ResetInitiator - if self.initiator - else HeaderTags.ResetInitiator - ) + flag = HeaderTags.ResetInitiator if self.initiator else HeaderTags.ResetInitiator await self.mplex_conn.send_message(flag, None, self.stream_id) self.local_closed = True diff --git a/libp2p/stream_muxer/mplex/utils.py b/libp2p/stream_muxer/mplex/utils.py index 0de1f7d..52cf0ff 100644 --- a/libp2p/stream_muxer/mplex/utils.py +++ b/libp2p/stream_muxer/mplex/utils.py @@ -32,9 +32,7 @@ def decode_uvarint(buff: bytes, index: int) -> Tuple[int, int]: return result, index + 1 -async def decode_uvarint_from_stream( - reader: asyncio.StreamReader, timeout: float -) -> int: +async def decode_uvarint_from_stream(reader: asyncio.StreamReader, timeout: float) -> int: shift = 0 result = 0 while True: diff --git a/libp2p/transport/tcp/tcp.py b/libp2p/transport/tcp/tcp.py index 60a1e6e..2682c2b 100644 --- a/libp2p/transport/tcp/tcp.py +++ b/libp2p/transport/tcp/tcp.py @@ -30,9 +30,7 @@ class TCPListener(IListener): :return: return True if successful """ self.server = await asyncio.start_server( - self.handler, - maddr.value_for_protocol("ip4"), - maddr.value_for_protocol("tcp"), + self.handler, maddr.value_for_protocol("ip4"), maddr.value_for_protocol("tcp") ) socket = self.server.sockets[0] self.multiaddrs.append(_multiaddr_from_socket(socket)) diff --git a/libp2p/transport/typing.py b/libp2p/transport/typing.py index 9fd36b9..0f5eabb 100644 --- a/libp2p/transport/typing.py +++ b/libp2p/transport/typing.py @@ -3,4 +3,3 @@ from typing import NewType, Callable THandler = Callable[[StreamReader, StreamWriter], None] - diff --git a/libp2p/transport/upgrader.py b/libp2p/transport/upgrader.py index 6809fbb..2d4dc63 100644 --- a/libp2p/transport/upgrader.py +++ b/libp2p/transport/upgrader.py @@ -16,9 +16,7 @@ class TransportUpgrader: security_multistream: SecurityMultistream muxer: Sequence[str] - def __init__( - self, secOpt: Dict[TProtocol, ISecureTransport], muxerOpt: Sequence[str] - ) -> None: + def __init__(self, secOpt: Dict[TProtocol, ISecureTransport], muxerOpt: Sequence[str]) -> None: # Store security option self.security_multistream = SecurityMultistream() for key in secOpt: @@ -46,9 +44,7 @@ class TransportUpgrader: @staticmethod def upgrade_connection( - conn: IRawConnection, - generic_protocol_handler: GenericProtocolHandlerFn, - peer_id: ID, + conn: IRawConnection, generic_protocol_handler: GenericProtocolHandlerFn, peer_id: ID ) -> Mplex: """ Upgrade raw connection to muxed connection diff --git a/tests/peer/test_peerinfo.py b/tests/peer/test_peerinfo.py index d8690f5..a25cb80 100644 --- a/tests/peer/test_peerinfo.py +++ b/tests/peer/test_peerinfo.py @@ -8,7 +8,9 @@ from libp2p.peer.peerdata import PeerData from libp2p.peer.peerinfo import InvalidAddrError, PeerInfo, info_from_p2p_addr ALPHABETS = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz" -VALID_MULTI_ADDR_STR = "/ip4/127.0.0.1/tcp/8000/p2p/3YgLAeMKSAPcGqZkAt8mREqhQXmJT8SN8VCMN4T6ih4GNX9wvK8mWJnWZ1qA2mLdCQ" # noqa: E501 +VALID_MULTI_ADDR_STR = ( + "/ip4/127.0.0.1/tcp/8000/p2p/3YgLAeMKSAPcGqZkAt8mREqhQXmJT8SN8VCMN4T6ih4GNX9wvK8mWJnWZ1qA2mLdCQ" +) # noqa: E501 def test_init_():