diff options
author | Georg Brandl <georg@python.org> | 2006-03-31 17:18:06 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2006-03-31 17:18:06 (GMT) |
commit | dd2245f2309da358b4c0b56d6a3a411888052f26 (patch) | |
tree | cc2b848af738f6b48fe997d09aebdc2f30902523 /Lib/test | |
parent | 296aef8ebb4701a6fe3af652a230b1107ae5f44a (diff) | |
download | cpython-dd2245f2309da358b4c0b56d6a3a411888052f26.zip cpython-dd2245f2309da358b4c0b56d6a3a411888052f26.tar.gz cpython-dd2245f2309da358b4c0b56d6a3a411888052f26.tar.bz2 |
Bug #1250170, Patch #1462230: handle socket.gethostname()
failures gracefully
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_urllib2.py | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py index 5710444..7e0bbf0 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: |