[PATCH 2 of 3 V2] windows: open registry keys using unicode names

Matt Harbison mharbison72 at gmail.com
Sat Sep 15 02:39:26 UTC 2018


# HG changeset patch
# User Matt Harbison <matt_harbison at yahoo.com>
# Date 1536886493 14400
#      Thu Sep 13 20:54:53 2018 -0400
# Node ID 8490cde7d20031c0c6295f5df531db02bca1a6a9
# Parent  26795e6d586896a0449ea8e7e78fc6ba33a04d68
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.

diff --git a/mercurial/windows.py b/mercurial/windows.py
--- a/mercurial/windows.py
+++ b/mercurial/windows.py
@@ -554,9 +554,10 @@ def lookupreg(key, valname=None, scope=N
         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
 



More information about the Mercurial-devel mailing list