mercurial/windows.py
changeset 29760 3df9f780c90e
parent 29530 3239e2fdd2e2
child 30309 4b1af1c867fa
--- 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: