]> granicus.if.org Git - python/commitdiff
Provide a clearer error message when urlopen fails because of an
authorJeremy Hylton <jeremy@alum.mit.edu>
Mon, 2 Oct 2000 23:04:02 +0000 (23:04 +0000)
committerJeremy Hylton <jeremy@alum.mit.edu>
Mon, 2 Oct 2000 23:04:02 +0000 (23:04 +0000)
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

index ff557761ddd77ac6bb826832f1ac10acf4f0d7c8..8b3c9240dbefed5b1d6f582e1e2faeefb2126c4e 100644 (file)
@@ -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