patch-nad0017 test_urllib2 fails with ANALYSIS urllib{2}.FileHandler incorrectly assumes host can have only one IP address. APPLIES 3.0, 3.1 (urllib) 2.6, 2.7 (urllib2) diff -r 52039dea55f0 Lib/urllib/request.py --- Lib/urllib/request.py Tue Feb 10 17:58:10 2009 -0800 +++ Lib/urllib/request.py Tue Feb 10 18:00:24 2009 -0800 @@ -1182,8 +1182,9 @@ def get_names(self): if FileHandler.names is None: try: - FileHandler.names = (socket.gethostbyname('localhost'), - socket.gethostbyname(socket.gethostname())) + FileHandler.names = tuple( + socket.gethostbyname_ex('localhost')[2] + + socket.gethostbyname_ex(socket.gethostname())[2]) except socket.gaierror: FileHandler.names = (socket.gethostbyname('localhost'),) return FileHandler.names @@ -1680,6 +1681,8 @@ urlfile = 'file://' + file return addinfourl(open(localname, 'rb'), headers, urlfile) host, port = splitport(host) + # Note: thishost should be changed to return all ip addresses for this + # host or, better, refactored. See duplicate open_local_file. if (not port and socket.gethostbyname(host) in (localhost(), thishost())): urlfile = file @@ -1990,7 +1993,7 @@ _thishost = None def thishost(): - """Return the IP address of the current host.""" + """Return one IP address of the current host.""" global _thishost if _thishost is None: _thishost = socket.gethostbyname(socket.gethostname())