Use telnetlib3 readline correctly

This commit is contained in:
Jared Miller 2026-02-07 12:20:00 -05:00
parent a81888d0b8
commit 3ebff56017
2 changed files with 5 additions and 6 deletions

View file

@ -4,6 +4,7 @@ import asyncio
from typing import cast from typing import cast
import telnetlib3 import telnetlib3
from telnetlib3.server_shell import readline2
PORT = 6789 PORT = 6789
@ -23,9 +24,7 @@ async def shell(
_writer.write("mud> ") _writer.write("mud> ")
await _writer.drain() await _writer.drain()
# readline_async reads char-by-char, handles echo via writer.echo(), inp = await readline2(reader, writer)
# and supports backspace editing
inp = await telnetlib3.readline_async(reader, writer)
if inp is None: if inp is None:
break break

View file

@ -31,7 +31,7 @@ async def test_shell_greets_and_echoes():
writer.drain = AsyncMock() writer.drain = AsyncMock()
writer.close = MagicMock() writer.close = MagicMock()
readline = "mudlib.server.telnetlib3.readline_async" readline = "mudlib.server.readline2"
with patch(readline, new_callable=AsyncMock) as mock_readline: with patch(readline, new_callable=AsyncMock) as mock_readline:
mock_readline.side_effect = ["hello", "quit"] mock_readline.side_effect = ["hello", "quit"]
await server.shell(reader, writer) await server.shell(reader, writer)
@ -51,7 +51,7 @@ async def test_shell_handles_eof():
writer.drain = AsyncMock() writer.drain = AsyncMock()
writer.close = MagicMock() writer.close = MagicMock()
readline = "mudlib.server.telnetlib3.readline_async" readline = "mudlib.server.readline2"
with patch(readline, new_callable=AsyncMock) as mock_readline: with patch(readline, new_callable=AsyncMock) as mock_readline:
mock_readline.return_value = None mock_readline.return_value = None
await server.shell(reader, writer) await server.shell(reader, writer)
@ -67,7 +67,7 @@ async def test_shell_handles_quit():
writer.drain = AsyncMock() writer.drain = AsyncMock()
writer.close = MagicMock() writer.close = MagicMock()
readline = "mudlib.server.telnetlib3.readline_async" readline = "mudlib.server.readline2"
with patch(readline, new_callable=AsyncMock) as mock_readline: with patch(readline, new_callable=AsyncMock) as mock_readline:
mock_readline.return_value = "quit" mock_readline.return_value = "quit"
await server.shell(reader, writer) await server.shell(reader, writer)