From da14f616ef0bb8135562bd105ca60760f3085438 Mon Sep 17 00:00:00 2001 From: Alex Kontos Date: Wed, 30 Oct 2024 14:44:56 +0000 Subject: [PATCH] Remove use of telnetlib. --- .../mozrunner/mozrunner/devices/emulator.py | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/testing/mozbase/mozrunner/mozrunner/devices/emulator.py b/testing/mozbase/mozrunner/mozrunner/devices/emulator.py index 4a2aa81733864..9231fee60fc71 100644 --- a/testing/mozbase/mozrunner/mozrunner/devices/emulator.py +++ b/testing/mozbase/mozrunner/mozrunner/devices/emulator.py @@ -8,7 +8,7 @@ import subprocess import tempfile import time -from telnetlib import Telnet +import socket from mozdevice import ADBHost from mozprocess import ProcessHandler @@ -19,6 +19,25 @@ from .emulator_geo import EmulatorGeo from .emulator_screen import EmulatorScreen +class TelnetConnection: + def __init__(self, host, port): + self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + self.sock.connect((host, port)) + + def write(self, data): + self.sock.sendall(data.encode('ascii')) + + def read_until(self, delimiter): + buffer = [] + while True: + chunk = self.sock.recv(1024).decode('ascii') + buffer.append(chunk) + if delimiter in chunk: + break + return ''.join(buffer) + + def close(self): + self.sock.close() class ArchContext(object): def __init__(self, arch, context, binary=None, avd=None, extra_args=None): @@ -189,14 +208,14 @@ def _get_telnet_response(self, command=None): def _run_telnet(self, command): if not self.telnet: - self.telnet = Telnet("localhost", self.port) + self.telnet = TelnetConnection('localhost', self.port) self._get_telnet_response() return self._get_telnet_response(command) def __del__(self): if self.telnet: self.telnet.write("exit\n") - self.telnet.read_all() + self.telnet.close() class EmulatorAVD(BaseEmulator):