comparison mercurial/windows.py @ 16807:80142f385af9

win32: move lookupreg() to windows.py lookupreg() doesn't use the win32 API directly any more, it uses the Python standard library module _winreg.
author Adrian Buehlmann <adrian@cadifra.com>
date Sun, 27 May 2012 11:29:52 +0200
parents e34106fa0dc3
children 0cb55b5c19a3
comparison
equal deleted inserted replaced
16806:186049f70026 16807:80142f385af9
4 # 4 #
5 # This software may be used and distributed according to the terms of the 5 # This software may be used and distributed according to the terms of the
6 # GNU General Public License version 2 or any later version. 6 # GNU General Public License version 2 or any later version.
7 7
8 from i18n import _ 8 from i18n import _
9 import osutil 9 import osutil, encoding
10 import errno, msvcrt, os, re, sys 10 import errno, msvcrt, os, re, sys, _winreg
11 11
12 import win32 12 import win32
13 executablepath = win32.executablepath 13 executablepath = win32.executablepath
14 getuser = win32.getuser 14 getuser = win32.getuser
15 hidewindow = win32.hidewindow 15 hidewindow = win32.hidewindow
16 lookupreg = win32.lookupreg
17 makedir = win32.makedir 16 makedir = win32.makedir
18 nlinks = win32.nlinks 17 nlinks = win32.nlinks
19 oslink = win32.oslink 18 oslink = win32.oslink
20 samedevice = win32.samedevice 19 samedevice = win32.samedevice
21 samefile = win32.samefile 20 samefile = win32.samefile
314 pass 313 pass
315 314
316 def cacheable(self): 315 def cacheable(self):
317 return False 316 return False
318 317
318 def lookupreg(key, valname=None, scope=None):
319 ''' Look up a key/value name in the Windows registry.
320
321 valname: value name. If unspecified, the default value for the key
322 is used.
323 scope: optionally specify scope for registry lookup, this can be
324 a sequence of scopes to look up in order. Default (CURRENT_USER,
325 LOCAL_MACHINE).
326 '''
327 if scope is None:
328 scope = (_winreg.HKEY_CURRENT_USER, _winreg.HKEY_LOCAL_MACHINE)
329 elif not isinstance(scope, (list, tuple)):
330 scope = (scope,)
331 for s in scope:
332 try:
333 val = _winreg.QueryValueEx(_winreg.OpenKey(s, key), valname)[0]
334 # never let a Unicode string escape into the wild
335 return encoding.tolocal(val.encode('UTF-8'))
336 except EnvironmentError:
337 pass
338
319 expandglobs = True 339 expandglobs = True