mercurial/windows.py
changeset 29760 3df9f780c90e
parent 29530 3239e2fdd2e2
child 30309 4b1af1c867fa
equal deleted inserted replaced
29759:e584c6235500 29760:3df9f780c90e
     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 __future__ import absolute_import
     8 from __future__ import absolute_import
     9 
     9 
    10 import _winreg
       
    11 import errno
    10 import errno
    12 import msvcrt
    11 import msvcrt
    13 import os
    12 import os
    14 import re
    13 import re
    15 import stat
    14 import stat
    19 from . import (
    18 from . import (
    20     encoding,
    19     encoding,
    21     osutil,
    20     osutil,
    22     win32,
    21     win32,
    23 )
    22 )
       
    23 
       
    24 try:
       
    25     import _winreg as winreg
       
    26     winreg.CloseKey
       
    27 except ImportError:
       
    28     import winreg
    24 
    29 
    25 executablepath = win32.executablepath
    30 executablepath = win32.executablepath
    26 getuser = win32.getuser
    31 getuser = win32.getuser
    27 hidewindow = win32.hidewindow
    32 hidewindow = win32.hidewindow
    28 makedir = win32.makedir
    33 makedir = win32.makedir
   430     scope: optionally specify scope for registry lookup, this can be
   435     scope: optionally specify scope for registry lookup, this can be
   431     a sequence of scopes to look up in order. Default (CURRENT_USER,
   436     a sequence of scopes to look up in order. Default (CURRENT_USER,
   432     LOCAL_MACHINE).
   437     LOCAL_MACHINE).
   433     '''
   438     '''
   434     if scope is None:
   439     if scope is None:
   435         scope = (_winreg.HKEY_CURRENT_USER, _winreg.HKEY_LOCAL_MACHINE)
   440         scope = (winreg.HKEY_CURRENT_USER, winreg.HKEY_LOCAL_MACHINE)
   436     elif not isinstance(scope, (list, tuple)):
   441     elif not isinstance(scope, (list, tuple)):
   437         scope = (scope,)
   442         scope = (scope,)
   438     for s in scope:
   443     for s in scope:
   439         try:
   444         try:
   440             val = _winreg.QueryValueEx(_winreg.OpenKey(s, key), valname)[0]
   445             val = winreg.QueryValueEx(winreg.OpenKey(s, key), valname)[0]
   441             # never let a Unicode string escape into the wild
   446             # never let a Unicode string escape into the wild
   442             return encoding.tolocal(val.encode('UTF-8'))
   447             return encoding.tolocal(val.encode('UTF-8'))
   443         except EnvironmentError:
   448         except EnvironmentError:
   444             pass
   449             pass
   445 
   450