Mercurial > hg-stable
diff mercurial/windows.py @ 29772:3df9f780c90e
py3: conditionalize _winreg import
_winreg module is renamed to winreg in python 3. Added the conditionalize
statements in the respective file because adding this in pycompat will result
in pycompat throwing error as this is a windows registry module and we have
buildbots and most of the contributors on linux.
author | Pulkit Goyal <7895pulkit@gmail.com> |
---|---|
date | Wed, 10 Aug 2016 04:35:44 +0530 |
parents | 3239e2fdd2e2 |
children | 4b1af1c867fa |
line wrap: on
line diff
--- a/mercurial/windows.py Mon Aug 08 23:51:11 2016 +0530 +++ b/mercurial/windows.py Wed Aug 10 04:35:44 2016 +0530 @@ -7,7 +7,6 @@ from __future__ import absolute_import -import _winreg import errno import msvcrt import os @@ -22,6 +21,12 @@ win32, ) +try: + import _winreg as winreg + winreg.CloseKey +except ImportError: + import winreg + executablepath = win32.executablepath getuser = win32.getuser hidewindow = win32.hidewindow @@ -432,12 +437,12 @@ LOCAL_MACHINE). ''' if scope is None: - scope = (_winreg.HKEY_CURRENT_USER, _winreg.HKEY_LOCAL_MACHINE) + scope = (winreg.HKEY_CURRENT_USER, winreg.HKEY_LOCAL_MACHINE) elif not isinstance(scope, (list, tuple)): scope = (scope,) for s in scope: try: - val = _winreg.QueryValueEx(_winreg.OpenKey(s, key), valname)[0] + val = winreg.QueryValueEx(winreg.OpenKey(s, key), valname)[0] # never let a Unicode string escape into the wild return encoding.tolocal(val.encode('UTF-8')) except EnvironmentError: