changeset 39643:47ac5d93d708

windows: open registry keys using unicode names Python3 complained it must be str. While here, use a context manager to close the key- it wouldn't wrap at 80 characters the old way, and would have had to move anyway.
author Matt Harbison <matt_harbison@yahoo.com>
date Thu, 13 Sep 2018 20:54:53 -0400
parents a407f9009392
children 3b421154d2ca
files mercurial/windows.py
diffstat 1 files changed, 4 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/windows.py	Thu Sep 13 00:39:02 2018 -0400
+++ b/mercurial/windows.py	Thu Sep 13 20:54:53 2018 -0400
@@ -554,9 +554,10 @@
         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.unitolocal(val)
+            with winreg.OpenKey(s, encoding.strfromlocal(key)) as hkey:
+                val = winreg.QueryValueEx(hkey, valname)[0]
+                # never let a Unicode string escape into the wild
+                return encoding.unitolocal(val)
         except EnvironmentError:
             pass