◐ Shell
clean mode source ↗

Message 74735 - Python tracker

I think that telnet should only use bytes (and not characters). For an 
HTTP connection, the charset is only known after parsing the HTTP 
headers. So telnet should use bytes, and your HTTP browser will 
convert bytes to characters using the charset from the HTTP headers. 
My patch only uses bytes for internal buffering and special codes 
(IAC, DONT, ENCRYPT, etc.).

Example to test the library (Starwars, telnet, ISO-8859-1):
    from telnetlib import Telnet
    from sys import stdout
    ipv4 = "towel.blinkenlights.nl"
    ipv6 = "2001:980:ffe:1::42"
    t = Telnet(ipv6, 23)
    while True:
        command = t.read_some()
        command = str(command, "ISO-8859-1")
        stdout.write(command)

Example to test the library (Google, HTTP, ASCII):
    from telnetlib import Telnet
    t = Telnet("www.google.com", 80)
    t.write(b'GET / HTTP/1.0\r\n\r\n')
    answer = t.read_all()
    answer = str(answer, "ASCII")
    print(answer)