nvda
6ae76f93 - Fix the remote Python console (#20626)

Commit
104 days ago
Fix the remote Python console (#20626) ### Summary of the issue: NVDA has a remote Python console for debugging. It is described in the developer guide. A TCP server runs inside NVDA. A client connects to port 6832 and types console commands. The module predates the move to Python 3. The socket streams of the server carry bytes. The module writes text strings to them and reads text from them. Writing the greeting therefore raises `TypeError` as soon as a client connects. The server thread dies and the connection closes immediately. The remote console has been unusable since NVDA moved to Python 3. ### Description of user facing changes: None. The remote console is only available in source builds and must be enabled manually. ### Description of developer facing changes: The remote Python console works again. ### Description of development approach: A helper method encodes text as UTF-8 before writing it to the socket (`_write`). The greeting, the prompt and all console output now go through this helper. Received lines are decoded from UTF-8 before the line ending is stripped and the line is executed. Characters that cannot be encoded or decoded are replaced instead of raising. Type hints were added throughout the module and it has been modernized further to follow NVDA coding guidelines. ### Testing strategy: Manual testing. The console was enabled from the local Python console as described in the developer guide. A socket client connected on TCP port 6832. The greeting and the prompt appear. Statements execute and their output returns to the client. The `snap()` helper works and the snapshot variables are usable. There are no unit tests. The module needs a running NVDA and a TCP client, which the unit test framework does not provide. ### Known issues with pull request: The remote Python console is considered a security risk. An alternative direction is therefore removing it altogether instead. However, it turned out to be helpful for letting AI agents interact with NVDA. An MCP server would be even better suited for that purpose.
Author
Parents
Loading