]> granicus.if.org Git - python/commitdiff
Fix for issue 7149: a regression in 2.6.3 that causes an exception when
authorRonald Oussoren <ronaldoussoren@mac.com>
Sun, 18 Oct 2009 07:07:00 +0000 (07:07 +0000)
committerRonald Oussoren <ronaldoussoren@mac.com>
Sun, 18 Oct 2009 07:07:00 +0000 (07:07 +0000)
trying to detect proxy settings on OSX.

Lib/urllib.py
Misc/NEWS

index 8b4029db6f3d0740452cfdf5244cd02839c808b8..db8e6160d45088ceee26822ae71b3c007a8f5ff2 100644 (file)
@@ -1340,6 +1340,8 @@ if sys.platform == 'darwin':
         import socket
         from fnmatch import fnmatch
 
+        hostonly, port = splitport(host)
+
         def ip2num(ipAddr):
             parts = ipAddr.split('.')
             parts = map(int, parts)
@@ -1354,6 +1356,8 @@ if sys.platform == 'darwin':
             if proxy_settings['exclude_simple']:
                 return True
 
+        hostIP = None
+
         for value in proxy_settings.get('exceptions', ()):
             # Items in the list are strings like these: *.local, 169.254/16
             if not value: continue
@@ -1361,8 +1365,11 @@ if sys.platform == 'darwin':
             m = re.match(r"(\d+(?:\.\d+)*)(/\d+)?", value)
             if m is not None:
                 if hostIP is None:
-                    hostIP = socket.gethostbyname(host)
-                    hostIP = ip2num(hostIP)
+                    try:
+                        hostIP = socket.gethostbyname(hostonly)
+                        hostIP = ip2num(hostIP)
+                    except socket.error:
+                        continue
 
                 base = ip2num(m.group(1))
                 mask = int(m.group(2)[1:])
index 2ac0d9f8212f19ffa5ba0d6cdde5b99c03d5dcd3..d694056d9270cb18261840d7622bc4ffb4ff09ac 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -411,6 +411,8 @@ Core and Builtins
 Library
 -------
 
+- Issue #7149: urllib fails on OSX in the proxy detection code
+
 - Issue #7069: Make inspect.isabstract() return a boolean.
 
 - Add support to the `ihooks` module for relative imports.