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

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

Open
engineerjoe440 opened this issue Apr 28, 2022 · 0 comments

Comments

@engineerjoe440
Copy link
Owner

engineerjoe440 commented Apr 28, 2022

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant