mirror of
https://github.com/python/cpython.git
synced 2025-10-02 05:12:23 +00:00
Fix Issue9446 - urllib2 tests fail when offline
This commit is contained in:
parent
cb4f47c377
commit
7cc0fe44e0
1 changed files with 7 additions and 1 deletions
|
@ -1259,6 +1259,12 @@ def parse_http_list(s):
|
||||||
|
|
||||||
return [part.strip() for part in res]
|
return [part.strip() for part in res]
|
||||||
|
|
||||||
|
def _safe_gethostbyname(host):
|
||||||
|
try:
|
||||||
|
return socket.gethostbyname(host)
|
||||||
|
except socket.gaierror:
|
||||||
|
return None
|
||||||
|
|
||||||
class FileHandler(BaseHandler):
|
class FileHandler(BaseHandler):
|
||||||
# Use local file or FTP depending on form of URL
|
# Use local file or FTP depending on form of URL
|
||||||
def file_open(self, req):
|
def file_open(self, req):
|
||||||
|
@ -1300,7 +1306,7 @@ class FileHandler(BaseHandler):
|
||||||
if host:
|
if host:
|
||||||
host, port = splitport(host)
|
host, port = splitport(host)
|
||||||
if not host or \
|
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:
|
if host:
|
||||||
origurl = 'file://' + host + filename
|
origurl = 'file://' + host + filename
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue