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

login
register
mail settings
Submitter Matt Harbison
Date Sept. 15, 2018, 2:39 a.m.
Message ID <8490cde7d20031c0c629.1536979166@Envy>
Download mbox | patch
Permalink /patch/34669/
State Accepted
Headers show

Comments

Matt Harbison - Sept. 15, 2018, 2:39 a.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@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.

Patch

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