From patchwork Sat Sep 15 02:39:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [2,of,3,V2] windows: open registry keys using unicode names From: Matt Harbison X-Patchwork-Id: 34669 Message-Id: <8490cde7d20031c0c629.1536979166@Envy> To: mercurial-devel@mercurial-scm.org Date: Fri, 14 Sep 2018 22:39:26 -0400 # HG changeset patch # User Matt Harbison # 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