@@ -1450,6 +1450,19 @@ def parse_http_list(s):
14501450 return [part .strip () for part in res ]
14511451
14521452class FileHandler (BaseHandler ):
1453+ # names for the localhost
1454+ names = None
1455+ def get_names (self ):
1456+ if FileHandler .names is None :
1457+ try :
1458+ FileHandler .names = tuple (
1459+ socket .gethostbyname_ex ('localhost' )[2 ] +
1460+ socket .gethostbyname_ex (socket .gethostname ())[2 ])
1461+ except socket .gaierror :
1462+ FileHandler .names = (socket .gethostbyname ('localhost' ),)
1463+ return FileHandler .names
1464+
1465+ # not entirely sure what the rules are here
14531466 def open_local_file (self , req ):
14541467 import email .utils
14551468 import mimetypes
@@ -1470,25 +1483,14 @@ def open_local_file(self, req):
14701483
14711484 file_open = open_local_file
14721485
1473- _local_addresses = None
1474-
14751486def _is_local_authority (authority ):
1476- global _local_addresses
1477-
14781487 if not authority or authority == 'localhost' :
14791488 return True
14801489 try :
14811490 address = socket .gethostbyname (authority )
14821491 except (socket .gaierror , AttributeError ):
14831492 return False
1484- if _local_addresses is None :
1485- try :
1486- _local_addresses = frozenset (
1487- socket .gethostbyname_ex ('localhost' )[2 ] +
1488- socket .gethostbyname_ex (socket .gethostname ())[2 ])
1489- except socket .gaierror :
1490- _local_addresses = frozenset (socket .gethostbyname ('localhost' ),)
1491- return address in _local_addresses
1493+ return address in FileHandler ().get_names ()
14921494
14931495class FTPHandler (BaseHandler ):
14941496 def ftp_open (self , req ):
0 commit comments