SF.net SVN: jython:[7189] trunk/jython/Lib

[email protected] Sun, 23 Jan 2011 15:51:34 +0000
Newsgroups gmane.comp.lang.jython.cvs
Message-ID <[email protected]>
Revision: 7189
          http://jython.svn.sourceforge.net/jython/?rev=7189&view=rev
Author:   otmarhumbel
Date:     2011-01-23 15:51:34 +0000 (Sun, 23 Jan 2011)

Log Message:
-----------
fix bug #1697 by excluding IPv6 addresses from socket.getaddrinfo();
this is a temporary fix, since we should support IPv6 in the future

Modified Paths:
--------------
    trunk/jython/Lib/socket.py

Added Paths:
-----------
    trunk/jython/Lib/test/test_socket_jy.py

Modified: trunk/jython/Lib/socket.py
===================================================================
--- trunk/jython/Lib/socket.py	2011-01-22 21:24:58 UTC (rev 7188)
+++ trunk/jython/Lib/socket.py	2011-01-23 15:51:34 UTC (rev 7189)
@@ -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)

Added: trunk/jython/Lib/test/test_socket_jy.py
===================================================================
--- trunk/jython/Lib/test/test_socket_jy.py	                        (rev 0)
+++ trunk/jython/Lib/test/test_socket_jy.py	2011-01-23 15:51:34 UTC (rev 7189)
@@ -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()


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.

------------------------------------------------------------------------------
Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)!
Finally, a world-class log management solution at an even better price-free!
Download using promo code Free_Logger_4_Dev2Dev. Offer expires 
February 28th, so secure your free ArcSight Logger TODAY! 
http://p.sf.net/sfu/arcsight-sfd2d