Skip to content

Commit 588d333

Browse files
rodrigcrvagg
authored andcommitted
gyp: _winreg module was renamed to winreg in Python 3.
#1150 Reviewed-By: Refael Ackermann <refack@gmail.com>
1 parent 98226d1 commit 588d333

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

gyp/pylib/gyp/MSVSVersion.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,18 @@ def _RegistryGetValueUsingWinReg(key, value):
176176
contents of the registry key's value, or None on failure. Throws
177177
ImportError if _winreg is unavailable.
178178
"""
179-
import _winreg
179+
try:
180+
# Python 2
181+
from _winreg import OpenKey, QueryValueEx
182+
except ImportError:
183+
# Python 3
184+
from winreg import OpenKey, QueryValueEx
185+
180186
try:
181187
root, subkey = key.split('\\', 1)
182188
assert root == 'HKLM' # Only need HKLM for now.
183-
with _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, subkey) as hkey:
184-
return _winreg.QueryValueEx(hkey, value)[0]
189+
with OpenKey(_winreg.HKEY_LOCAL_MACHINE, subkey) as hkey:
190+
return QueryValueEx(hkey, value)[0]
185191
except WindowsError:
186192
return None
187193

0 commit comments

Comments
 (0)