File telnetlib.py of Package failed_python-napalm
"""
Compatibility stub for the stdlib 'telnetlib' module.
Python 3.13+ on some platforms may not include the 'telnetlib' module or it may
be removed/deprecated. Some projects (like napalm) import telnetlib at module
import time even when Telnet functionality is optional. To avoid ImportError
during test collection or import-time, provide a minimal stub module here.
This stub does NOT provide a full telnet implementation. If code actually
attempts to use Telnet functionality under Python versions without stdlib
telnetlib, an informative RuntimeError will be raised.
This file is intentionally small and conservative to cause minimal behavior
change while fixing import-time errors.
"""
class Telnet:
def __init__(self, host=None, port=0, timeout=None):
raise RuntimeError(
"telnetlib is not available in this Python build. "
"Telnet support is disabled. If you need Telnet, run on a Python "
"that provides telnetlib or modify the code to avoid importing "
"telnetlib at import-time."
)
def open(host=None, port=0, timeout=None):
"""
Compatibility function similar to telnetlib.open().
Calling this will raise a RuntimeError indicating telnet support is not
available in this environment.
"""
raise RuntimeError(
"telnetlib.open() is not available: telnetlib is not present in "
"this Python environment."
)
# Provide commonly expected names to avoid attribute errors on import.
__all__ = ["Telnet", "open"]