[Python-checkins] r83950 - python/branches/release27-maint/Lib/urllib2.py
senthil.kumaran
python-checkins at python.org
Wed Aug 11 20:18:23 CEST 2010
Author: senthil.kumaran
Date: Wed Aug 11 20:18:22 2010
New Revision: 83950
Log:
Fix Issue9446 - urllib2 tests fail when offline
Modified:
python/branches/release27-maint/Lib/urllib2.py
Modified: python/branches/release27-maint/Lib/urllib2.py
==============================================================================
--- python/branches/release27-maint/Lib/urllib2.py (original)
+++ python/branches/release27-maint/Lib/urllib2.py Wed Aug 11 20:18:22 2010
@@ -1259,6 +1259,12 @@
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 @@
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:
More information about the Python-checkins
mailing list