From dcdadfe39afd9b7cddf1e20efa37babdad61ff77 Mon Sep 17 00:00:00 2001
From: Senthil Kumaran <senthil@uthcode.com>
Date: Sat, 1 Jun 2013 11:12:17 -0700
Subject: Fix thishost helper funtion in urllib. Returns the ipaddress of
 localhost when hostname is resolvable by socket.gethostname for local
 machine. This all fixes certain freebsd builtbot failures.

---
 Lib/urllib/request.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py
index 1279322..30e43e6 100644
--- a/Lib/urllib/request.py
+++ b/Lib/urllib/request.py
@@ -2229,7 +2229,10 @@ def thishost():
     """Return the IP addresses of the current host."""
     global _thishost
     if _thishost is None:
-        _thishost = tuple(socket.gethostbyname_ex(socket.gethostname())[2])
+        try:
+            _thishost = tuple(socket.gethostbyname_ex(socket.gethostname())[2])
+        except socket.gaierror:
+            _thishost = tuple(socket.gethostbyname_ex('localhost')[2])
     return _thishost
 
 _ftperrors = None
-- 
cgit v0.12