run black

This commit is contained in:
Chih Cheng Liang 2019-08-05 11:21:20 +08:00
parent 9e0a806218
commit 7a04ebb51f
No known key found for this signature in database
GPG Key ID: C86B5E6612B1487A
7 changed files with 10 additions and 27 deletions

View File

@ -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

View File

@ -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

View File

@ -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:

View File

@ -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))

View File

@ -3,4 +3,3 @@ from typing import NewType, Callable
THandler = Callable[[StreamReader, StreamWriter], None]

View File

@ -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

View File

@ -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_():