### Eclipse Workspace Patch 1.0 #P jython-trunk Index: Lib/test/test_socket_jy.py =================================================================== --- Lib/test/test_socket_jy.py (revision 0) +++ Lib/test/test_socket_jy.py (revision 0) @@ -0,0 +1,25 @@ +import httplib +import socket +import sys +from test import test_support +import unittest + + +class SocketIPv6Test(unittest.TestCase): + + def test_connect_localhost(self): + '''Ensures a correct socket.error message''' + conn = httplib.HTTPConnection('localhost', 18080) + body = "" + headers = {} + try: + conn.request("GET", "/RELEASE-NOTES.txt", body, headers) + except socket.error: + pass # used to get an AssertionError (see bug 1697) + + +def test_main(): + test_support.run_unittest(SocketIPv6Test) + +if __name__ == "__main__": + test_main() Index: Lib/socket.py =================================================================== --- Lib/socket.py (revision 7173) +++ Lib/socket.py (working copy) @@ -617,16 +617,18 @@ for a in java.net.InetAddress.getAllByName(host): if len([f for f in filter_fns if f(a)]): family = {java.net.Inet4Address: AF_INET, java.net.Inet6Address: AF_INET6}[a.getClass()] - if passive_mode and not canonname_mode: - canonname = "" - else: - canonname = asPyString(a.getCanonicalHostName()) - if host is None and passive_mode and not canonname_mode: - sockname = INADDR_ANY - else: - sockname = asPyString(a.getHostAddress()) - # TODO: Include flowinfo and scopeid in a 4-tuple for IPv6 addresses - results.append((family, socktype, proto, canonname, (sockname, port))) + # bug 1697: exclude IPv6 addresses from being returned + if family != AF_INET6: + if passive_mode and not canonname_mode: + canonname = "" + else: + canonname = asPyString(a.getCanonicalHostName()) + if host is None and passive_mode and not canonname_mode: + sockname = INADDR_ANY + else: + sockname = asPyString(a.getHostAddress()) + # TODO: Include flowinfo and scopeid in a 4-tuple for IPv6 addresses + results.append((family, socktype, proto, canonname, (sockname, port))) return results except java.lang.Exception, jlx: raise _map_exception(jlx)