199 from _winreg import HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE, \ |
199 from _winreg import HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE, \ |
200 QueryValueEx, OpenKey |
200 QueryValueEx, OpenKey |
201 except ImportError: |
201 except ImportError: |
202 return None |
202 return None |
203 |
203 |
204 def query_val(scope, key, valname): |
|
205 try: |
|
206 keyhandle = OpenKey(scope, key) |
|
207 return QueryValueEx(keyhandle, valname)[0] |
|
208 except EnvironmentError: |
|
209 return None |
|
210 |
|
211 if scope is None: |
204 if scope is None: |
212 scope = (HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE) |
205 scope = (HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE) |
213 elif not isinstance(scope, (list, tuple)): |
206 elif not isinstance(scope, (list, tuple)): |
214 scope = (scope,) |
207 scope = (scope,) |
215 for s in scope: |
208 for s in scope: |
216 val = query_val(s, key, valname) |
209 try: |
217 if val is not None: |
210 val = QueryValueEx(OpenKey(scope, key), valname)[0] |
218 return val |
211 # never let a Unicode string escape into the wild |
|
212 return util.tolocal(val.encode('UTF-8')) |
|
213 except EnvironmentError: |
|
214 pass |
219 |
215 |
220 def system_rcpath_win32(): |
216 def system_rcpath_win32(): |
221 '''return default os-specific hgrc search path''' |
217 '''return default os-specific hgrc search path''' |
222 proc = win32api.GetCurrentProcess() |
218 proc = win32api.GetCurrentProcess() |
223 try: |
219 try: |