Open
Conversation
- Add Connection class wrapping asyncio StreamReader/StreamWriter to replace removed TransportSocket.send/recv (Python 3.12+) - Update h_terminal.py to use modern aiohttp WebSocket API: socket.receive() instead of socket.recv(), socket.send_str() instead of socket.send() - Add unit tests for Connection class and WebSocket API usage
This was referenced Mar 16, 2026
There was a problem hiding this comment.
Pull request overview
This PR updates the Manx plugin to avoid deprecated/removed socket APIs in newer Python/aiohttp versions by introducing a small asyncio stream wrapper and modernizing WebSocket calls used by the terminal handler.
Changes:
- Added
Connectionwrapper overasyncioStreamReader/StreamWriterwithsend/recvhelpers. - Updated terminal WebSocket handler to use
socket.receive()andsocket.send_str()instead of deprecated APIs. - Added unit tests covering the new
Connectionwrapper and checking terminal handler WebSocket API usage.
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 8 comments.
| File | Description |
|---|---|
app/c_connection.py |
Introduces Connection wrapper to replace deprecated transport socket methods. |
app/h_terminal.py |
Updates terminal WebSocket handler to modern aiohttp WebSocket APIs. |
tests/test_connection.py |
Adds unit tests for Connection and validates WebSocket API usage in h_terminal.py. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+25
to
+26
| """Close the underlying writer.""" | ||
| self.writer.close() |
Comment on lines
+33
to
+36
| reader = MockReader() | ||
| conn = Connection(reader, MockWriter()) | ||
| result = asyncio.get_event_loop().run_until_complete(conn.recv(1024)) | ||
| self.assertEqual(result, b"hello") |
Comment on lines
+57
to
+61
| writer = MockWriter() | ||
| conn = Connection(MockReader(), writer) | ||
| asyncio.get_event_loop().run_until_complete(conn.send(b"world")) | ||
| self.assertEqual(writer.written, b"world") | ||
| self.assertTrue(writer.drained) |
Comment on lines
+80
to
+83
| writer = MockWriter() | ||
| conn = Connection(MockReader(), writer) | ||
| asyncio.get_event_loop().run_until_complete(conn.send("text")) | ||
| self.assertEqual(writer.written, b"text") |
Comment on lines
+114
to
+124
| # Ensure deprecated methods are not used | ||
| self.assertNotIn("socket.recv()", source, | ||
| "Should use socket.receive() instead of deprecated socket.recv()") | ||
| self.assertNotIn("await socket.send(", source, | ||
| "Should use socket.send_str() instead of deprecated socket.send()") | ||
|
|
||
| # Ensure modern methods are used | ||
| self.assertIn("socket.receive()", source, | ||
| "Should call socket.receive() for reading WebSocket messages") | ||
| self.assertIn("socket.send_str(", source, | ||
| "Should call socket.send_str() for sending WebSocket messages") |
Comment on lines
+111
to
+113
| with open("app/h_terminal.py") as f: | ||
| source = f.read() | ||
|
|
Comment on lines
+114
to
+124
| # Ensure deprecated methods are not used | ||
| self.assertNotIn("socket.recv()", source, | ||
| "Should use socket.receive() instead of deprecated socket.recv()") | ||
| self.assertNotIn("await socket.send(", source, | ||
| "Should use socket.send_str() instead of deprecated socket.send()") | ||
|
|
||
| # Ensure modern methods are used | ||
| self.assertIn("socket.receive()", source, | ||
| "Should call socket.receive() for reading WebSocket messages") | ||
| self.assertIn("socket.send_str(", source, | ||
| "Should call socket.send_str() for sending WebSocket messages") |
Comment on lines
+16
to
+17
| msg = await socket.receive() | ||
| cmd = msg.data if hasattr(msg, 'data') else str(msg) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Connectionclass (app/c_connection.py) that wraps asyncioStreamReader/StreamWriterto replace the removedTransportSocket.send/recvmethods (removed in Python 3.12)h_terminal.pyto use modern aiohttp WebSocket API:socket.receive()instead of deprecatedsocket.recv(),socket.send_str()instead of deprecatedsocket.send()Connectionclass and verifies WebSocket API usageFixes #51
Supersedes #42 — takes the same approach (Connection wrapper) but also fixes the WebSocket API deprecations in
h_terminal.pyand adds tests.Test plan
python3 -m unittest tests.test_connection -vto verify all 6 tests pass