This repository has been archived by the owner on Jun 20, 2022. It is now read-only.
forked from psf/requests
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add 'all' proxy selection to select_proxy
It seems it's necessary both in pulling all_proxy from the environment (rebuild_proxies) and deciding which proxy to use (select_proxy). Also added new functional test.
- Loading branch information
Brett Higgins
committed
May 13, 2016
1 parent
1121f8b
commit 4bf8866
Showing
7 changed files
with
92 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -320,17 +320,28 @@ def test_dotted_netmask(mask, expected): | |
assert dotted_netmask(mask) == expected | ||
|
||
|
||
http_proxies = {'http': 'http://http.proxy', | ||
'http://some.host': 'http://some.host.proxy'} | ||
all_proxies = {'all': 'socks5://http.proxy', | ||
'all://some.host': 'socks5://some.host.proxy'} | ||
@pytest.mark.parametrize( | ||
'url, expected', ( | ||
('hTTp://u:[email protected]/path', 'http://some.host.proxy'), | ||
('hTTp://u:[email protected]/path', 'http://http.proxy'), | ||
('hTTps://Other.Host', None), | ||
('file:///etc/motd', None), | ||
'url, expected, proxies', ( | ||
('hTTp://u:[email protected]/path', 'http://some.host.proxy', http_proxies), | ||
('hTTp://u:[email protected]/path', 'http://http.proxy', http_proxies), | ||
('hTTp:///path', 'http://http.proxy', http_proxies), | ||
('hTTps://Other.Host', None, http_proxies), | ||
('file:///etc/motd', None, http_proxies), | ||
('hTTp://u:[email protected]/path', 'socks5://some.host.proxy', all_proxies), | ||
('hTTp://u:[email protected]/path', 'socks5://http.proxy', all_proxies), | ||
('hTTp:///path', 'socks5://http.proxy', all_proxies), | ||
('hTTps://Other.Host', 'socks5://http.proxy', all_proxies), | ||
# XXX: unsure whether this is reasonable behavior | ||
('file:///etc/motd', 'socks5://http.proxy', all_proxies), | ||
)) | ||
def test_select_proxies(url, expected): | ||
def test_select_proxies(url, expected, proxies): | ||
"""Make sure we can select per-host proxies correctly.""" | ||
proxies = {'http': 'http://http.proxy', | ||
'http://some.host': 'http://some.host.proxy'} | ||
assert select_proxy(url, proxies) == expected | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import contextlib | ||
import os | ||
|
||
|
||
@contextlib.contextmanager | ||
def override_environ(**kwargs): | ||
save_env = dict(os.environ) | ||
for key, value in kwargs.items(): | ||
if value is None: | ||
del os.environ[key] | ||
else: | ||
os.environ[key] = value | ||
try: | ||
yield | ||
finally: | ||
os.environ.clear() | ||
os.environ.update(save_env) |