summaryrefslogtreecommitdiffstats
path: root/Lib/urllib2.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/urllib2.py')
-rw-r--r--Lib/urllib2.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/Lib/urllib2.py b/Lib/urllib2.py
index 4ae7df4..f15da21 100644
--- a/Lib/urllib2.py
+++ b/Lib/urllib2.py
@@ -1222,7 +1222,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()):
return addinfourl(open(localfile, 'rb'),
headers, 'file:'+file)
except OSError as msg:
@@ -1230,6 +1230,12 @@ class FileHandler(BaseHandler):
raise URLError(msg)
raise URLError('file not on local host')
+def _safe_gethostbyname(host):
+ try:
+ return socket.gethostbyname(host)
+ except socket.gaierror:
+ return None
+
class FTPHandler(BaseHandler):
def ftp_open(self, req):
import ftplib
@@ -1259,7 +1265,7 @@ class FTPHandler(BaseHandler):
raise URLError(msg)
path, attrs = splitattr(req.get_selector())
dirs = path.split('/')
- dirs = map(unquote, dirs)
+ dirs = list(map(unquote, dirs))
dirs, file = dirs[:-1], dirs[-1]
if dirs and not dirs[0]:
dirs = dirs[1:]