]> granicus.if.org Git - python/commitdiff
Bug #1250170, Patch #1462230: handle socket.gethostname()
authorGeorg Brandl <georg@python.org>
Fri, 31 Mar 2006 17:18:06 +0000 (17:18 +0000)
committerGeorg Brandl <georg@python.org>
Fri, 31 Mar 2006 17:18:06 +0000 (17:18 +0000)
failures gracefully

Lib/mimetools.py
Lib/test/test_urllib2.py
Misc/NEWS

index 0b698ac679260b6c1140a175cc828776fea7b76c..8c1cc199031cf0e5a86520e9549b8dc88e0f1179 100644 (file)
@@ -127,7 +127,10 @@ def choose_boundary():
     import time
     if _prefix is None:
         import socket
-        hostid = socket.gethostbyname(socket.gethostname())
+        try:
+            hostid = socket.gethostbyname(socket.gethostname())
+        except socket.gaierror:
+            hostid = '127.0.0.1'
         try:
             uid = repr(os.getuid())
         except AttributeError:
index 5710444017590e196daa3d285f6d50338715c1cf..7e0bbf064b005321827058e674cbcd58d8464fc0 100644 (file)
@@ -349,13 +349,19 @@ class HandlerTests(unittest.TestCase):
         TESTFN = test_support.TESTFN
         urlpath = sanepathname2url(os.path.abspath(TESTFN))
         towrite = "hello, world\n"
-        for url in [
+        urls = [
             "file://localhost%s" % urlpath,
             "file://%s" % urlpath,
             "file://%s%s" % (socket.gethostbyname('localhost'), urlpath),
-            "file://%s%s" % (socket.gethostbyname(socket.gethostname()),
-                             urlpath),
-            ]:
+            ]
+        try:
+            localaddr = socket.gethostbyname(socket.gethostname())    
+        except socket.gaierror:
+            localaddr = ''
+        if localaddr:
+            urls.append("file://%s%s" % (localaddr, urlpath))
+            
+        for url in urls:
             f = open(TESTFN, "wb")
             try:
                 try:
index 38a608bd557d50d7a280fd1fdc991612a6cedf12..55357d8c2ab3c2e1ee1a9689767d67e7728604e4 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -485,6 +485,9 @@ Extension Modules
 Library
 -------
 
+- Bug #1250170: mimetools now gracefully handles socket.gethostname()
+  failures gracefully.
+
 - patch #1457316: "setup.py upload" now supports --identity to select the
   key to be used for signing the uploaded code.