Message 74735 - Python tracker

Message74735

Author vstinner
Recipients hdima, vstinner
Date 2008-10-14.12:08:31
SpamBayes Score 6.047808e-08
Marked as misclassified No
Message-id <1223986116.59.0.567151355655.issue3725@psf.upfronthosting.co.za>
In-reply-to
Content
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)
History
Date User Action Args
2008-10-14 12:08:36vstinnersetrecipients: + vstinner, hdima
2008-10-14 12:08:36vstinnersetmessageid: <1223986116.59.0.567151355655.issue3725@psf.upfronthosting.co.za>
2008-10-14 12:08:35vstinnerlinkissue3725 messages
2008-10-14 12:08:35vstinnercreate