From: Georg Brandl Date: Fri, 31 Mar 2006 17:18:06 +0000 (+0000) Subject: Bug #1250170, Patch #1462230: handle socket.gethostname() X-Git-Tag: v2.5a1~120 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=dd2245f2309da358b4c0b56d6a3a411888052f26;p=thirdparty%2FPython%2Fcpython.git Bug #1250170, Patch #1462230: handle socket.gethostname() failures gracefully --- diff --git a/Lib/mimetools.py b/Lib/mimetools.py index 0b698ac67926..8c1cc199031c 100644 --- a/Lib/mimetools.py +++ b/Lib/mimetools.py @@ -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: diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py index 571044401759..7e0bbf064b00 100644 --- a/Lib/test/test_urllib2.py +++ b/Lib/test/test_urllib2.py @@ -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: diff --git a/Misc/NEWS b/Misc/NEWS index 38a608bd557d..55357d8c2ab3 100644 --- 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.