Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

telnetlib module broken by str to unicode conversion #47975

Closed
hdima mannequin opened this issue Aug 29, 2008 · 7 comments
Closed

telnetlib module broken by str to unicode conversion #47975

hdima mannequin opened this issue Aug 29, 2008 · 7 comments
Assignees
Labels
release-blocker stdlib Python modules in the Lib dir type-crash A hard crash of the interpreter, possibly with a core dump

Comments

@hdima
Copy link
Mannequin

hdima mannequin commented Aug 29, 2008

BPO 3725
Nosy @amauryfa, @vstinner, @benjaminp
Files
  • telnet_bytes.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/benjaminp'
    closed_at = <Date 2008-10-15.20:54:40.089>
    created_at = <Date 2008-08-29.12:43:46.004>
    labels = ['library', 'type-crash', 'release-blocker']
    title = 'telnetlib module broken by str to unicode conversion'
    updated_at = <Date 2008-10-15.20:54:40.087>
    user = 'https://bugs.python.org/hdima'

    bugs.python.org fields:

    activity = <Date 2008-10-15.20:54:40.087>
    actor = 'benjamin.peterson'
    assignee = 'benjamin.peterson'
    closed = True
    closed_date = <Date 2008-10-15.20:54:40.089>
    closer = 'benjamin.peterson'
    components = ['Library (Lib)']
    creation = <Date 2008-08-29.12:43:46.004>
    creator = 'hdima'
    dependencies = []
    files = ['11788']
    hgrepos = []
    issue_num = 3725
    keywords = ['patch']
    message_count = 7.0
    messages = ['72131', '72132', '74735', '74770', '74780', '74794', '74815']
    nosy_count = 4.0
    nosy_names = ['hdima', 'amaury.forgeotdarc', 'vstinner', 'benjamin.peterson']
    pr_nums = []
    priority = 'release blocker'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = 'crash'
    url = 'https://bugs.python.org/issue3725'
    versions = ['Python 3.0']

    @hdima
    Copy link
    Mannequin Author

    hdima mannequin commented Aug 29, 2008

    Simple example:

    >>> from telnetlib import Telnet
    >>> t = Telnet("google.com", 80)
    >>> t.write("GET / HTTP/1.1\r\n")        
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/py3k/Lib/telnetlib.py", line 280, in write
        self.sock.sendall(buffer)
    TypeError: sendall() argument 1 must be string or buffer, not str
    >>> t.write(b"GET / HTTP/1.1\r\n")
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/py3k/Lib/telnetlib.py", line 277, in write
        if IAC in buffer:
    TypeError: Type str doesn't support the buffer API

    @hdima hdima mannequin added stdlib Python modules in the Lib dir type-crash A hard crash of the interpreter, possibly with a core dump labels Aug 29, 2008
    @hdima
    Copy link
    Mannequin Author

    hdima mannequin commented Aug 29, 2008

    I think only bytes need to be allowed for write() and read*() because of
    low-level nature of Telnet. I can create a patch later.

    @vstinner
    Copy link
    Member

    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)

    @benjaminp
    Copy link
    Contributor

    The patch looks pretty straightforward to me. If somebody else gives
    their nod, I'll apply it.

    @benjaminp benjaminp self-assigned this Oct 14, 2008
    @amauryfa
    Copy link
    Member

    Yes, the patch is good.

    I think that documentation (both Doc\library\telnetlib.rst and the
    docstrings in telnetlib.py) should reflect the change, at least the code
    samples.

    @hdima
    Copy link
    Mannequin Author

    hdima mannequin commented Oct 15, 2008

    The patch is good. It's exactly what I told about in msg72132.

    @benjaminp
    Copy link
    Contributor

    Fixed in r66904.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    release-blocker stdlib Python modules in the Lib dir type-crash A hard crash of the interpreter, possibly with a core dump
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants