]> granicus.if.org Git - python/commitdiff
Fix Issue9446 - urllib2 tests fail when offline
authorSenthil Kumaran <orsenthil@gmail.com>
Wed, 11 Aug 2010 18:18:22 +0000 (18:18 +0000)
committerSenthil Kumaran <orsenthil@gmail.com>
Wed, 11 Aug 2010 18:18:22 +0000 (18:18 +0000)
Lib/urllib2.py

index d0e81a8084f71476c7e7582c5b21b0918cf9e193..7af882cb38dfe62f073e207eb94f6caf4c0e2797 100644 (file)
@@ -1259,6 +1259,12 @@ def parse_http_list(s):
 
     return [part.strip() for part in res]
 
+def _safe_gethostbyname(host):
+    try:
+        return socket.gethostbyname(host)
+    except socket.gaierror:
+        return None
+
 class FileHandler(BaseHandler):
     # Use local file or FTP depending on form of URL
     def file_open(self, req):
@@ -1300,7 +1306,7 @@ class FileHandler(BaseHandler):
             if host:
                 host, port = splitport(host)
             if not host or \
-                (not port and socket.gethostbyname(host) in self.get_names()):
+                (not port and _safe_gethostbyname(host) in self.get_names()):
                 if host:
                     origurl = 'file://' + host + filename
                 else: