Fix type errors and linting issues

- Fix type annotation errors in transport_registry.py and __init__.py
- Fix line length violations in test files (E501 errors)
- Fix missing return type annotations
- Fix cryptography NameAttribute type errors with type: ignore
- Fix ExceptionGroup import for cross-version compatibility
- Fix test failure in test_wss_listen_without_tls_config by handling ExceptionGroup
- Fix len() calls with None arguments in test_tcp_data_transfer.py
- Fix missing attribute access errors on interface types
- Fix boolean type expectation errors in test_js_ws_ping.py
- Fix nursery context manager type errors

All tests now pass and linting is clean.
This commit is contained in:
acul71
2025-09-08 04:18:10 +02:00
parent afe6da5db2
commit f4d5a44521
15 changed files with 1028 additions and 531 deletions

View File

@ -1,65 +0,0 @@
#!/usr/bin/env python3
"""
Debug script to test WebSocket URL construction and basic connection.
"""
import logging
from multiaddr import Multiaddr
from libp2p.transport.websocket.multiaddr_utils import parse_websocket_multiaddr
# Configure logging
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
async def test_websocket_url():
"""Test WebSocket URL construction."""
# Test multiaddr from your JS node
maddr_str = "/ip4/127.0.0.1/tcp/35391/ws/p2p/12D3KooWQh7p5xP2ppr3CrhUFsawmsKNe9jgDbacQdWCYpuGfMVN"
maddr = Multiaddr(maddr_str)
logger.info(f"Testing multiaddr: {maddr}")
# Parse WebSocket multiaddr
parsed = parse_websocket_multiaddr(maddr)
logger.info(
f"Parsed: is_wss={parsed.is_wss}, sni={parsed.sni}, rest_multiaddr={parsed.rest_multiaddr}"
)
# Construct WebSocket URL
if parsed.is_wss:
protocol = "wss"
else:
protocol = "ws"
# Extract host and port from rest_multiaddr
host = parsed.rest_multiaddr.value_for_protocol("ip4")
port = parsed.rest_multiaddr.value_for_protocol("tcp")
websocket_url = f"{protocol}://{host}:{port}/"
logger.info(f"WebSocket URL: {websocket_url}")
# Test basic WebSocket connection
try:
from trio_websocket import open_websocket_url
logger.info("Testing basic WebSocket connection...")
async with open_websocket_url(websocket_url) as ws:
logger.info("✅ WebSocket connection successful!")
# Send a simple message
await ws.send_message(b"test")
logger.info("✅ Message sent successfully!")
except Exception as e:
logger.error(f"❌ WebSocket connection failed: {e}")
import traceback
logger.error(f"Traceback: {traceback.format_exc()}")
if __name__ == "__main__":
import trio
trio.run(test_websocket_url)