mirror of
https://github.com/pypa/pip
synced 2023-12-13 21:30:23 +01:00
fix proxy support
This commit is contained in:
parent
7921be1537
commit
60b0401b0a
2 changed files with 49 additions and 3 deletions
|
@ -129,6 +129,7 @@ class URLOpener(object):
|
|||
"""
|
||||
def __init__(self):
|
||||
self.passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
|
||||
self.proxy_handler = None
|
||||
|
||||
def __call__(self, url):
|
||||
"""
|
||||
|
@ -186,6 +187,11 @@ class URLOpener(object):
|
|||
Build an OpenerDirector instance based on the scheme, whether ssl is
|
||||
importable and the --insecure parameter.
|
||||
"""
|
||||
|
||||
args = list(args)
|
||||
if self.proxy_handler:
|
||||
args.extend([self.proxy_handler, urllib2.CacheFTPHandler])
|
||||
|
||||
if kwargs.get('scheme') == 'https':
|
||||
if ssl:
|
||||
https_handler = VerifiedHTTPSHandler()
|
||||
|
@ -211,9 +217,7 @@ class URLOpener(object):
|
|||
self.prompting = prompting
|
||||
proxy = self.get_proxy(proxystr)
|
||||
if proxy:
|
||||
proxy_support = urllib2.ProxyHandler({"http": proxy, "ftp": proxy, "https": proxy})
|
||||
opener = urllib2.build_opener(proxy_support, urllib2.CacheFTPHandler)
|
||||
urllib2.install_opener(opener)
|
||||
self.proxy_handler = urllib2.ProxyHandler({"http": proxy, "ftp": proxy, "https": proxy})
|
||||
|
||||
def parse_credentials(self, netloc):
|
||||
if "@" in netloc:
|
||||
|
|
|
@ -13,6 +13,8 @@ import os
|
|||
import pip
|
||||
import getpass
|
||||
from pip.basecommand import get_proxy
|
||||
from pip.backwardcompat import urllib2
|
||||
from pip.download import urlopen, VerifiedHTTPSHandler
|
||||
from tests.test_pip import here
|
||||
|
||||
|
||||
|
@ -62,3 +64,43 @@ def test_get_proxy():
|
|||
# Undo monkeypatch
|
||||
getpass.getpass = old_getpass
|
||||
|
||||
|
||||
def test_proxy_handlers_present():
|
||||
"""
|
||||
Confirm the proxy handlers are present
|
||||
"""
|
||||
|
||||
try:
|
||||
urlopen.setup(proxystr='http://proxy')
|
||||
o = urlopen.get_opener(scheme='https')
|
||||
finally:
|
||||
#teardown the proxy_handler for other tests.
|
||||
urlopen.proxy_handler = None
|
||||
|
||||
handler_types = [h.__class__ for h in o.handlers]
|
||||
|
||||
if sys.version_info < (2, 6):
|
||||
assert handler_types == [
|
||||
urllib2.ProxyHandler, # this is needed
|
||||
urllib2.UnknownHandler,
|
||||
urllib2.HTTPHandler,
|
||||
urllib2.HTTPDefaultErrorHandler,
|
||||
urllib2.HTTPRedirectHandler,
|
||||
urllib2.FileHandler,
|
||||
urllib2.HTTPSHandler,
|
||||
urllib2.CacheFTPHandler, # and this
|
||||
urllib2.HTTPErrorProcessor
|
||||
], str(handler_types)
|
||||
else:
|
||||
assert handler_types == [
|
||||
urllib2.ProxyHandler, # this is needed
|
||||
urllib2.UnknownHandler,
|
||||
urllib2.HTTPDefaultErrorHandler,
|
||||
urllib2.HTTPRedirectHandler,
|
||||
urllib2.FileHandler,
|
||||
VerifiedHTTPSHandler,
|
||||
urllib2.CacheFTPHandler, # and this
|
||||
urllib2.HTTPErrorProcessor
|
||||
], str(handler_types)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue