Skip to content
Myr

#4373, fix possible winreg value type difference (#4377)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* #4373, fix possible winreg value type difference * add a test for ProxyOverride and ProxyEnable on win32 * add tests for winreg key ProxyEnable with two possible types * fixing AppVeyor failures

authored by Mingyuan Xia · committed by Cory Benfield · parent e4fc353 · Browse files · 2 files+10 added−3 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+10 added−3 removed

  • tests:+6 added−1 removed
  • other:+4 added−2 removed

2 files+10 added−3 removed

modified:requests/utils.py+4 added-2 removed
50 unmodified lines
51 import _winreg as winreg52 try:53 internetSettings = winreg.OpenKey(winreg.HKEY_CURRENT_USER,54 r'Software\Microsoft\Windows\CurrentVersion\Internet Settings')55 # ProxyEnable could be REG_SZ or REG_DWORD, normalizing it55 proxyEnable = winreg.QueryValueEx(internetSettings,56 'ProxyEnable')[0]56 proxyEnable = int(winreg.QueryValueEx(internetSettings,57 'ProxyEnable')[0])58 # ProxyOverride is almost always a string59 proxyOverride = winreg.QueryValueEx(internetSettings,60 'ProxyOverride')[0]61 except OSError:62 return False
882 unmodified lines
modified:tests/test_utils.py+6 added-1 removed
3 unmodified lines
4import copy5import filecmp6from io import BytesIO7import zipfile8from collections import deque910import pytest11from requests import compat12from requests.cookies import RequestsCookieJar
653 unmodified lines
666 def Close(self):667 pass668669 ie_settings = RegHandle()670 proxyEnableValues = deque([1, "1"])671672 def OpenKey(key, subkey):673 return ie_settings674675 def QueryValueEx(key, value_name):676 if key is ie_settings:677 if value_name == 'ProxyEnable':676 return [1]678 # this could be a string (REG_SZ) or a 32-bit number (REG_DWORD)679 proxyEnableValues.rotate()680 return [proxyEnableValues[0]]681 elif value_name == 'ProxyOverride':682 return [override]683684 monkeypatch.setenv('http_proxy', '')
2 unmodified lines
687 monkeypatch.setenv('no_proxy', '')688 monkeypatch.setenv('NO_PROXY', '')689 monkeypatch.setattr(winreg, 'OpenKey', OpenKey)690 monkeypatch.setattr(winreg, 'QueryValueEx', QueryValueEx)691 assert should_bypass_proxies(url, None) == expected692693694@pytest.mark.parametrize(695 'env_name, value', (
22 unmodified lines