Retro Bulletin Board Systems on atproto. Web app and TUI. lazy mirror of alyraffauf/atbbs atbbs.xyz
forums python tui atproto bbs
3
fork

Configure Feed

Select the types of activity you want to include in your feed.

telnet: strip IAC command sequences

+28 -1
+28 -1
telnet/server.py
··· 48 48 return "\r\n".join(out) 49 49 50 50 51 + def strip_iac(data: bytes) -> bytes: 52 + """Strip telnet IAC command sequences from raw bytes.""" 53 + out = bytearray() 54 + i = 0 55 + while i < len(data): 56 + if data[i] == 0xFF and i + 1 < len(data): 57 + cmd = data[i + 1] 58 + if cmd == 0xFF: 59 + out.append(0xFF) 60 + i += 2 61 + elif cmd in (0xFB, 0xFC, 0xFD, 0xFE): 62 + i += 3 # WILL/WONT/DO/DONT + option 63 + elif cmd == 0xFA: 64 + i += 2 # sub-negotiation: skip until IAC SE 65 + while i < len(data): 66 + if data[i] == 0xFF and i + 1 < len(data) and data[i + 1] == 0xF0: 67 + i += 2 68 + break 69 + i += 1 70 + else: 71 + i += 2 72 + else: 73 + out.append(data[i]) 74 + i += 1 75 + return bytes(out) 76 + 77 + 51 78 async def write(writer: asyncio.StreamWriter, text: str): 52 79 writer.write(wrap(text).encode()) 53 80 await writer.drain() ··· 65 92 return "" 66 93 if not data: 67 94 return "" 68 - text = data.decode(errors="ignore").strip() 95 + text = strip_iac(data).decode(errors="ignore").strip() 69 96 return re.sub(r"[^\x20-\x7e]", "", text) 70 97 71 98