diff options
author | Jeremy Hylton <jeremy@alum.mit.edu> | 2000-10-02 23:04:02 (GMT) |
---|---|---|
committer | Jeremy Hylton <jeremy@alum.mit.edu> | 2000-10-02 23:04:02 (GMT) |
commit | d52755f41c1545a1e6dcc0f38ebed0a1fd1fa5e8 (patch) | |
tree | 79f56e5eeaef06516ed0ded7f9758b0f071f199e /Lib/urllib.py | |
parent | 4dc1a6d6bae5c5828ca1e3473be280650dfadab5 (diff) | |
download | cpython-d52755f41c1545a1e6dcc0f38ebed0a1fd1fa5e8.zip cpython-d52755f41c1545a1e6dcc0f38ebed0a1fd1fa5e8.tar.gz cpython-d52755f41c1545a1e6dcc0f38ebed0a1fd1fa5e8.tar.bz2 |
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.
Diffstat (limited to 'Lib/urllib.py')
-rw-r--r-- | Lib/urllib.py | 18 |
1 files 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 |