From ac3b8ebfccfc626c19d1ae731df65cd408f9b9c4 Mon Sep 17 00:00:00 2001 From: MirceaDan Date: Sun, 2 Dec 2018 15:24:19 -0800 Subject: [PATCH] winreg compatibility with python3 _winreg has been renamed in winreg in py3 --- src/octoprint/util/comm.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/octoprint/util/comm.py b/src/octoprint/util/comm.py index 4b1a8e474..56554c9be 100644 --- a/src/octoprint/util/comm.py +++ b/src/octoprint/util/comm.py @@ -40,9 +40,12 @@ from octoprint.util import get_exception_string, sanitize_ascii, filter_non_asci to_unicode, bom_aware_open, TypedQueue, PrependableQueue, TypeAlreadyInQueue, chunks, ResettableTimer try: - import _winreg -except: - pass + import winreg +except ImportError: + try: + import _winreg as winreg + except: + pass _logger = logging.getLogger(__name__) @@ -154,10 +157,10 @@ def serialList(): baselist=[] if os.name=="nt": try: - key=_winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,"HARDWARE\\DEVICEMAP\\SERIALCOMM") + key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE,"HARDWARE\\DEVICEMAP\\SERIALCOMM") i=0 while(1): - baselist+=[_winreg.EnumValue(key,i)[1]] + baselist+=[winreg.EnumValue(key,i)[1]] i+=1 except: pass