win32: move lookupreg() to windows.py
lookupreg() doesn't use the win32 API directly any more, it uses the Python
standard library module _winreg.
--- a/mercurial/win32.py Sun May 27 11:29:45 2012 +0200
+++ b/mercurial/win32.py Sun May 27 11:29:52 2012 +0200
@@ -5,8 +5,7 @@
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
-import encoding
-import ctypes, errno, os, subprocess, random, _winreg
+import ctypes, errno, os, subprocess, random
_kernel32 = ctypes.windll.kernel32
_advapi32 = ctypes.windll.advapi32
@@ -244,27 +243,6 @@
_kernel32.CloseHandle(h)
return _kernel32.GetLastError() != _ERROR_INVALID_PARAMETER
-def lookupreg(key, valname=None, scope=None):
- ''' Look up a key/value name in the Windows registry.
-
- valname: value name. If unspecified, the default value for the key
- is used.
- scope: optionally specify scope for registry lookup, this can be
- a sequence of scopes to look up in order. Default (CURRENT_USER,
- LOCAL_MACHINE).
- '''
- if scope is None:
- 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]
- # never let a Unicode string escape into the wild
- return encoding.tolocal(val.encode('UTF-8'))
- except EnvironmentError:
- pass
-
def executablepath():
'''return full path of hg.exe'''
size = 600
--- a/mercurial/windows.py Sun May 27 11:29:45 2012 +0200
+++ b/mercurial/windows.py Sun May 27 11:29:52 2012 +0200
@@ -6,14 +6,13 @@
# GNU General Public License version 2 or any later version.
from i18n import _
-import osutil
-import errno, msvcrt, os, re, sys
+import osutil, encoding
+import errno, msvcrt, os, re, sys, _winreg
import win32
executablepath = win32.executablepath
getuser = win32.getuser
hidewindow = win32.hidewindow
-lookupreg = win32.lookupreg
makedir = win32.makedir
nlinks = win32.nlinks
oslink = win32.oslink
@@ -316,4 +315,25 @@
def cacheable(self):
return False
+def lookupreg(key, valname=None, scope=None):
+ ''' Look up a key/value name in the Windows registry.
+
+ valname: value name. If unspecified, the default value for the key
+ is used.
+ scope: optionally specify scope for registry lookup, this can be
+ a sequence of scopes to look up in order. Default (CURRENT_USER,
+ LOCAL_MACHINE).
+ '''
+ if scope is None:
+ 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]
+ # never let a Unicode string escape into the wild
+ return encoding.tolocal(val.encode('UTF-8'))
+ except EnvironmentError:
+ pass
+
expandglobs = True