Bug 1942259 - Move telnetlib import to BaseEmulator a=dmeehan

emulator.py currently has an unconditional telnetlib import, but the
file can also be imported when the functionality is not needed.

Because telnetlib was removed from Python 3.13, this unconditional
import breaks use cases that do not even care about telnet. As a stopgap
measure until a better fix is available, move the import to the function
that relies on telnet.

Original Revision: https://phabricator.services.mozilla.com/D227995

Differential Revision: https://phabricator.services.mozilla.com/D236164
This commit is contained in:
Rob Wu 2025-02-07 18:08:44 +00:00
parent c3b0d15ca3
commit a03dc5f488

View file

@ -8,7 +8,6 @@ import shutil
import subprocess
import tempfile
import time
from telnetlib import Telnet
from mozdevice import ADBHost
from mozprocess import ProcessHandler
@ -189,6 +188,11 @@ class BaseEmulator(Device):
def _run_telnet(self, command):
if not self.telnet:
# telnetlib is dropped in Python 3.13 (bug 1925198).
# Import here instead of the top level to avoid breaking users of
# this file that are independent of telnet.
from telnetlib import Telnet
self.telnet = Telnet("localhost", self.port)
self._get_telnet_response()
return self._get_telnet_response(command)