From 6889dde7f5bc8c4f615c4c079fba73ead594a965 Mon Sep 17 00:00:00 2001 From: Victor Malai <78157734+vikmal-sw@users.noreply.github.com> Date: Mon, 4 Apr 2022 11:12:36 +0200 Subject: [PATCH] tools/pyboard.py: Keep ProcessToSerial class in global scope Considering ProcessToSerial is a part of the public API of this file, it is defined in the global scope. This leaves the Pyboard class code unchanged. --- tools/pyboard.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/tools/pyboard.py b/tools/pyboard.py index 27192a28f5..c752557d0c 100755 --- a/tools/pyboard.py +++ b/tools/pyboard.py @@ -263,6 +263,12 @@ class ProcessToSerialPosix: return 1 return 0 +# Class selector based on select module platform dependancy (available on Unix, but not on Windows) +import select +if hasattr(select, "poll"): + ProcessToSerial = ProcessToSerialPosix +else: + ProcessToSerial = ProcessToSerialThreading class ProcessPtyToTerminal: """Execute a process which creates a PTY and prints slave PTY as @@ -316,12 +322,7 @@ class Pyboard: self.in_raw_repl = False self.use_raw_paste = True if device.startswith("exec:"): - # Class selector based on select module platform dependancy (available on Unix, but not on Windows) - import select - if hasattr(select, "poll"): - self.serial = ProcessToSerialPosix(device[len("exec:") :]) - else: - self.serial = ProcessToSerialThreading(device[len("exec:") :]) + self.serial = ProcessToSerial(device[len("exec:") :]) elif device.startswith("execpty:"): self.serial = ProcessPtyToTerminal(device[len("qemupty:") :]) elif device and device[0].isdigit() and device[-1].isdigit() and device.count(".") == 3: