Skip to content

Add Support for telnetlib3 as telnetlib is Deprecated from Python 3.11+ #1

@engineerjoe440

Description

@engineerjoe440

Python's built-in telnetlib is being deprecated in Python 3.11 (see PEP 594), and should be migrated towards telnetlib3.

telnetlib3 is an asyncio-capable library, and some modifications will need to be made, accordingly. Still, they've got a nice example of a client in their README:

import asyncio, telnetlib3

@asyncio.coroutine
def shell(reader, writer):
    while True:
        # read stream until '?' mark is found
        outp = yield from reader.read(1024)
        if not outp:
            # End of File
            break
        elif '?' in outp:
            # reply all questions with 'y'.
            writer.write('y')

        # display all server output
        print(outp, flush=True)

    # EOF
    print()

loop = asyncio.get_event_loop()
coro = telnetlib3.open_connection('localhost', 6023, shell=shell)
reader, writer = loop.run_until_complete(coro)
loop.run_until_complete(writer.protocol.waiter_closed)

Furthermore, it appears that the client.open_connection method will return a tuple of the reader/writer objects that can be used with other logic. Perhaps they could be sent as a tuple to the SELClient object?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions