mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2025-12-31 20:36:24 +00:00
run lint and fix errors, except mypy
This commit is contained in:
@ -1,16 +1,31 @@
|
||||
import anyio
|
||||
from async_exit_stack import AsyncExitStack
|
||||
from p2pclient.datastructures import StreamInfo
|
||||
from p2pclient.utils import get_unused_tcp_port
|
||||
from async_exit_stack import (
|
||||
AsyncExitStack,
|
||||
)
|
||||
from p2pclient.datastructures import (
|
||||
StreamInfo,
|
||||
)
|
||||
from p2pclient.utils import (
|
||||
get_unused_tcp_port,
|
||||
)
|
||||
import pytest
|
||||
import trio
|
||||
|
||||
from libp2p.io.abc import ReadWriteCloser
|
||||
from libp2p.io.abc import (
|
||||
ReadWriteCloser,
|
||||
)
|
||||
from libp2p.security.noise.transport import PROTOCOL_ID as NOISE_PROTOCOL_ID
|
||||
from libp2p.security.secio.transport import ID as SECIO_PROTOCOL_ID
|
||||
from libp2p.tools.factories import HostFactory, PubsubFactory
|
||||
from libp2p.tools.interop.daemon import make_p2pd
|
||||
from libp2p.tools.interop.utils import connect
|
||||
from libp2p.tools.factories import (
|
||||
HostFactory,
|
||||
PubsubFactory,
|
||||
)
|
||||
from libp2p.tools.interop.daemon import (
|
||||
make_p2pd,
|
||||
)
|
||||
from libp2p.tools.interop.utils import (
|
||||
connect,
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(params=[NOISE_PROTOCOL_ID, SECIO_PROTOCOL_ID])
|
||||
@ -130,12 +145,13 @@ async def py_to_daemon_stream_pair(p2pds, security_protocol, is_to_fail_daemon_s
|
||||
|
||||
if is_to_fail_daemon_stream:
|
||||
# FIXME: This is a workaround to make daemon reset the stream.
|
||||
# We intentionally close the listener on the python side, it makes the connection from
|
||||
# daemon to us fail, and therefore the daemon resets the opened stream on their side.
|
||||
# We intentionally close the listener on the python side, it makes the
|
||||
# connection from daemon to us fail, and therefore the daemon resets the
|
||||
# opened stream on their side.
|
||||
# Reference: https://github.com/libp2p/go-libp2p-daemon/blob/b95e77dbfcd186ccf817f51e95f73f9fd5982600/stream.go#L47-L50 # noqa: E501
|
||||
# We need it because we want to test against `stream_py` after the remote side(daemon)
|
||||
# is reset. This should be removed after the API `stream.reset` is exposed in daemon
|
||||
# some day.
|
||||
# We need it because we want to test against `stream_py` after the remote
|
||||
# side(daemon) is reset. This should be removed after the API
|
||||
# `stream.reset` is exposed in daemon some day.
|
||||
await p2pds[0].control.control.close()
|
||||
stream_py = await host.new_stream(p2pd.peer_id, [protocol_id])
|
||||
if not is_to_fail_daemon_stream:
|
||||
|
||||
@ -1,8 +1,12 @@
|
||||
import pytest
|
||||
import trio
|
||||
|
||||
from libp2p.tools.factories import HostFactory
|
||||
from libp2p.tools.interop.utils import connect
|
||||
from libp2p.tools.factories import (
|
||||
HostFactory,
|
||||
)
|
||||
from libp2p.tools.interop.utils import (
|
||||
connect,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.trio
|
||||
|
||||
@ -1,15 +1,30 @@
|
||||
import re
|
||||
|
||||
from multiaddr import Multiaddr
|
||||
from p2pclient.utils import get_unused_tcp_port
|
||||
from multiaddr import (
|
||||
Multiaddr,
|
||||
)
|
||||
from p2pclient.utils import (
|
||||
get_unused_tcp_port,
|
||||
)
|
||||
import pytest
|
||||
import trio
|
||||
|
||||
from libp2p.peer.peerinfo import PeerInfo, info_from_p2p_addr
|
||||
from libp2p.tools.factories import HostFactory
|
||||
from libp2p.tools.interop.envs import GO_BIN_PATH
|
||||
from libp2p.tools.interop.process import BaseInteractiveProcess
|
||||
from libp2p.typing import TProtocol
|
||||
from libp2p.peer.peerinfo import (
|
||||
PeerInfo,
|
||||
info_from_p2p_addr,
|
||||
)
|
||||
from libp2p.tools.factories import (
|
||||
HostFactory,
|
||||
)
|
||||
from libp2p.tools.interop.envs import (
|
||||
GO_BIN_PATH,
|
||||
)
|
||||
from libp2p.tools.interop.process import (
|
||||
BaseInteractiveProcess,
|
||||
)
|
||||
from libp2p.typing import (
|
||||
TProtocol,
|
||||
)
|
||||
|
||||
ECHO_PATH = GO_BIN_PATH / "echo"
|
||||
ECHO_PROTOCOL_ID = TProtocol("/echo/1.0.0")
|
||||
@ -38,7 +53,7 @@ class EchoProcess(BaseInteractiveProcess):
|
||||
|
||||
self.port = port
|
||||
self._peer_info = None
|
||||
self.regex_pat = re.compile(br"I am ([\w\./]+)")
|
||||
self.regex_pat = re.compile(rb"I am ([\w\./]+)")
|
||||
|
||||
@property
|
||||
def peer_info(self) -> None:
|
||||
@ -47,8 +62,8 @@ class EchoProcess(BaseInteractiveProcess):
|
||||
if not self.event_ready.is_set():
|
||||
raise Exception("process is not ready yet. failed to parse the peer info")
|
||||
# Example:
|
||||
# b"I am /ip4/127.0.0.1/tcp/56171/ipfs/QmU41TRPs34WWqa1brJEojBLYZKrrBcJq9nyNfVvSrbZUJ\n"
|
||||
m = re.search(br"I am ([\w\./]+)", self.bytes_read)
|
||||
# b"I am /ip4/127.0.0.1/tcp/56171/ipfs/QmU41TRPs34WWqa1brJEojBLYZKrrBcJq9nyNfVvSrbZUJ\n" # noqa: E501
|
||||
m = re.search(rb"I am ([\w\./]+)", self.bytes_read)
|
||||
if m is None:
|
||||
raise Exception("failed to find the pattern for the listening multiaddr")
|
||||
maddr_bytes_str_ipfs = m.group(1)
|
||||
|
||||
@ -1,8 +1,14 @@
|
||||
import pytest
|
||||
import trio
|
||||
|
||||
from libp2p.network.stream.exceptions import StreamClosed, StreamEOF, StreamReset
|
||||
from libp2p.tools.constants import MAX_READ_LEN
|
||||
from libp2p.network.stream.exceptions import (
|
||||
StreamClosed,
|
||||
StreamEOF,
|
||||
StreamReset,
|
||||
)
|
||||
from libp2p.tools.constants import (
|
||||
MAX_READ_LEN,
|
||||
)
|
||||
|
||||
DATA = b"data"
|
||||
|
||||
|
||||
@ -1,17 +1,33 @@
|
||||
import functools
|
||||
import math
|
||||
|
||||
from p2pclient.pb import p2pd_pb2
|
||||
from p2pclient.pb import (
|
||||
p2pd_pb2,
|
||||
)
|
||||
import pytest
|
||||
import trio
|
||||
|
||||
from libp2p.io.trio import TrioTCPStream
|
||||
from libp2p.peer.id import ID
|
||||
from libp2p.pubsub.pb import rpc_pb2
|
||||
from libp2p.pubsub.subscription import TrioSubscriptionAPI
|
||||
from libp2p.tools.factories import PubsubFactory
|
||||
from libp2p.tools.interop.utils import connect
|
||||
from libp2p.utils import read_varint_prefixed_bytes
|
||||
from libp2p.io.trio import (
|
||||
TrioTCPStream,
|
||||
)
|
||||
from libp2p.peer.id import (
|
||||
ID,
|
||||
)
|
||||
from libp2p.pubsub.pb import (
|
||||
rpc_pb2,
|
||||
)
|
||||
from libp2p.pubsub.subscription import (
|
||||
TrioSubscriptionAPI,
|
||||
)
|
||||
from libp2p.tools.factories import (
|
||||
PubsubFactory,
|
||||
)
|
||||
from libp2p.tools.interop.utils import (
|
||||
connect,
|
||||
)
|
||||
from libp2p.utils import (
|
||||
read_varint_prefixed_bytes,
|
||||
)
|
||||
|
||||
TOPIC_0 = "ABALA"
|
||||
TOPIC_1 = "YOOOO"
|
||||
|
||||
Reference in New Issue
Block a user