From ef8b60aff5b5b06d33f8b47e89a845ddde7090ef Mon Sep 17 00:00:00 2001 From: Craig Rodrigues Date: Sun, 19 Mar 2017 14:04:36 -0700 Subject: [PATCH] gyp: _winreg module was renamed to winreg in Python 3. https://github.com/nodejs/node-gyp/pull/1150 Reviewed-By: Refael Ackermann --- gyp/pylib/gyp/MSVSVersion.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/gyp/pylib/gyp/MSVSVersion.py b/gyp/pylib/gyp/MSVSVersion.py index c31ff3e114..293b4145c1 100644 --- a/gyp/pylib/gyp/MSVSVersion.py +++ b/gyp/pylib/gyp/MSVSVersion.py @@ -176,12 +176,18 @@ def _RegistryGetValueUsingWinReg(key, value): contents of the registry key's value, or None on failure. Throws ImportError if _winreg is unavailable. """ - import _winreg + try: + # Python 2 + from _winreg import OpenKey, QueryValueEx + except ImportError: + # Python 3 + from winreg import OpenKey, QueryValueEx + try: root, subkey = key.split('\\', 1) assert root == 'HKLM' # Only need HKLM for now. - with _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, subkey) as hkey: - return _winreg.QueryValueEx(hkey, value)[0] + with OpenKey(_winreg.HKEY_LOCAL_MACHINE, subkey) as hkey: + return QueryValueEx(hkey, value)[0] except WindowsError: return None