summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSenthil Kumaran <orsenthil@gmail.com>2010-08-11 18:18:22 (GMT)
committerSenthil Kumaran <orsenthil@gmail.com>2010-08-11 18:18:22 (GMT)
commit7cc0fe44e0f9caa9c193818d96f1ece9c66abd98 (patch)
treee78916556d153fb4bba1e341462843626ee67733
parentcb4f47c37704dec33135109d4b4d1ba5c31fc26f (diff)
downloadcpython-7cc0fe44e0f9caa9c193818d96f1ece9c66abd98.zip
cpython-7cc0fe44e0f9caa9c193818d96f1ece9c66abd98.tar.gz
cpython-7cc0fe44e0f9caa9c193818d96f1ece9c66abd98.tar.bz2
Fix Issue9446 - urllib2 tests fail when offline
-rw-r--r--Lib/urllib2.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/Lib/urllib2.py b/Lib/urllib2.py
index d0e81a8..7af882c 100644
--- a/Lib/urllib2.py
+++ b/Lib/urllib2.py
@@ -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: