summarylogtreecommitdiffstats
path: root/50d41051085b8d1201443a09faeff9207f5152af.patch
blob: b9ef8da9c60709e8d4f2dd796f4159ef37e75197 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62

# HG changeset patch
# User Rob Wu <rob@robwu.nl>
# Date 1730828835 0
# Node ID 50d41051085b8d1201443a09faeff9207f5152af
# Parent  025c089998e3b05f0a71fd03c9c9c9ac4c4abf17
Bug 1925198 - Move telnetlib import to BaseEmulator r=jmaher

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.

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

diff --git a/testing/mozbase/mozrunner/mozrunner/devices/emulator.py b/testing/mozbase/mozrunner/mozrunner/devices/emulator.py
--- a/testing/mozbase/mozrunner/mozrunner/devices/emulator.py
+++ b/testing/mozbase/mozrunner/mozrunner/devices/emulator.py
@@ -3,17 +3,16 @@
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 import datetime
 import os
 import shutil
 import subprocess
 import tempfile
 import time
-from telnetlib import Telnet
 
 from mozdevice import ADBHost
 from mozprocess import ProcessHandler
 
 from ..errors import TimeoutException
 from .base import Device
 from .emulator_battery import EmulatorBattery
 from .emulator_geo import EmulatorGeo
@@ -184,16 +183,21 @@ class BaseEmulator(Device):
             output.append(line.rstrip())
             if line.startswith("OK"):
                 return output
             elif line.startswith("KO:"):
                 raise Exception("bad telnet response: %s" % line)
 
     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)
 
     def __del__(self):
         if self.telnet:
             self.telnet.write("exit\n")
             self.telnet.read_all()