Skip to content

Commit

Permalink
gyp: _winreg module was renamed to winreg in Python 3.
Browse files Browse the repository at this point in the history
#1150
Reviewed-By: Refael Ackermann <refack@gmail.com>
  • Loading branch information
rodrigc authored and rvagg committed Apr 24, 2019
1 parent 98226d1 commit 588d333
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions gyp/pylib/gyp/MSVSVersion.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 588d333

Please sign in to comment.