From d52755f41c1545a1e6dcc0f38ebed0a1fd1fa5e8 Mon Sep 17 00:00:00 2001 From: Jeremy Hylton Date: Mon, 2 Oct 2000 23:04:02 +0000 Subject: 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. --- Lib/urllib.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/Lib/urllib.py b/Lib/urllib.py index ff55776..8b3c924 100644 --- a/Lib/urllib.py +++ b/Lib/urllib.py @@ -142,20 +142,23 @@ class URLopener: fp = open(filename, 'rb') return addinfourl(fp, headers, fullurl) type, url = splittype(fullurl) - if not type: type = 'file' + if not type: + type = 'file' if self.proxies.has_key(type): proxy = self.proxies[type] - type, proxy = splittype(proxy) - host, selector = splithost(proxy) + type, proxyhost = splittype(proxy) + host, selector = splithost(proxyhost) url = (host, fullurl) # Signal special case to open_*() + else: + proxy = None name = 'open_' + type self.type = type if '-' in name: # replace - with _ name = string.join(string.split(name, '-'), '_') if not hasattr(self, name): - if data is None: - return self.open_unknown(fullurl) + if proxy: + return self.open_unknown_proxy(proxy, fullurl, data) else: return self.open_unknown(fullurl, data) try: @@ -171,6 +174,11 @@ class URLopener: type, url = splittype(fullurl) 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 def retrieve(self, url, filename=None, reporthook=None, data=None): """retrieve(url) returns (filename, None) for a local object -- cgit v0.12