mirror of https://github.com/python/cpython
Provide a clearer error message when urlopen fails because of an
invalid proxy setting. Minor change to call of unknown_url; always pass data argument explicitly since data defaults to None. PEP 42: Add as a feature that urllib handle proxy setting that contain only the host and port of the proxy.
This commit is contained in:
parent
4dc1a6d6ba
commit
d52755f41c
|
@ -142,20 +142,23 @@ class URLopener:
|
||||||
fp = open(filename, 'rb')
|
fp = open(filename, 'rb')
|
||||||
return addinfourl(fp, headers, fullurl)
|
return addinfourl(fp, headers, fullurl)
|
||||||
type, url = splittype(fullurl)
|
type, url = splittype(fullurl)
|
||||||
if not type: type = 'file'
|
if not type:
|
||||||
|
type = 'file'
|
||||||
if self.proxies.has_key(type):
|
if self.proxies.has_key(type):
|
||||||
proxy = self.proxies[type]
|
proxy = self.proxies[type]
|
||||||
type, proxy = splittype(proxy)
|
type, proxyhost = splittype(proxy)
|
||||||
host, selector = splithost(proxy)
|
host, selector = splithost(proxyhost)
|
||||||
url = (host, fullurl) # Signal special case to open_*()
|
url = (host, fullurl) # Signal special case to open_*()
|
||||||
|
else:
|
||||||
|
proxy = None
|
||||||
name = 'open_' + type
|
name = 'open_' + type
|
||||||
self.type = type
|
self.type = type
|
||||||
if '-' in name:
|
if '-' in name:
|
||||||
# replace - with _
|
# replace - with _
|
||||||
name = string.join(string.split(name, '-'), '_')
|
name = string.join(string.split(name, '-'), '_')
|
||||||
if not hasattr(self, name):
|
if not hasattr(self, name):
|
||||||
if data is None:
|
if proxy:
|
||||||
return self.open_unknown(fullurl)
|
return self.open_unknown_proxy(proxy, fullurl, data)
|
||||||
else:
|
else:
|
||||||
return self.open_unknown(fullurl, data)
|
return self.open_unknown(fullurl, data)
|
||||||
try:
|
try:
|
||||||
|
@ -171,6 +174,11 @@ class URLopener:
|
||||||
type, url = splittype(fullurl)
|
type, url = splittype(fullurl)
|
||||||
raise IOError, ('url error', 'unknown url type', type)
|
raise IOError, ('url error', 'unknown url type', type)
|
||||||
|
|
||||||
|
def open_unknown_proxy(self, proxy, fullurl, data=None):
|
||||||
|
"""Overridable interface to open unknown URL type."""
|
||||||
|
type, url = splittype(fullurl)
|
||||||
|
raise IOError, ('url error', 'invalid proxy for %s' % type, proxy)
|
||||||
|
|
||||||
# External interface
|
# External interface
|
||||||
def retrieve(self, url, filename=None, reporthook=None, data=None):
|
def retrieve(self, url, filename=None, reporthook=None, data=None):
|
||||||
"""retrieve(url) returns (filename, None) for a local object
|
"""retrieve(url) returns (filename, None) for a local object
|
||||||
|
|
Loading…
Reference in New Issue