Skip to content

Commit

Permalink
Make winreg import compatible to modern Python
Browse files Browse the repository at this point in the history
  • Loading branch information
uranusjr committed Dec 19, 2019
1 parent 2472a6e commit 7ab0a48
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/pip/_internal/utils/appdirs.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,19 +204,22 @@ def _get_win_folder_from_registry(csidl_name):
registry for this guarantees us the correct answer for all CSIDL_*
names.
"""
import _winreg
if PY2:
import _winreg as winreg
else:
import winreg

shell_folder_name = {
"CSIDL_APPDATA": "AppData",
"CSIDL_COMMON_APPDATA": "Common AppData",
"CSIDL_LOCAL_APPDATA": "Local AppData",
}[csidl_name]

key = _winreg.OpenKey(
_winreg.HKEY_CURRENT_USER,
key = winreg.OpenKey(
winreg.HKEY_CURRENT_USER,
r"Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders"
)
directory, _type = _winreg.QueryValueEx(key, shell_folder_name)
directory, _type = winreg.QueryValueEx(key, shell_folder_name)
return directory


Expand Down

0 comments on commit 7ab0a48

Please sign in to comment.