[Jython-checkins] jython (merge 2.5 -> default): merge w/ 2.5: Fix for some minor socket issues relating to attributes

alan.kennedy jython-checkins at python.org
Sat Oct 29 20:06:57 CEST 2011


http://hg.python.org/jython/rev/71b3f883f6c5
changeset:   6259:71b3f883f6c5
parent:      6257:3d719476e032
parent:      6258:be3145efdbb1
user:        Alan Kennedy <jython-dev at xhaus.com>
date:        Sat Oct 29 18:59:05 2011 +0100
summary:
  merge w/ 2.5: Fix for some minor socket issues relating to attributes
http://bugs.jython.org/issue1803
http://bugs.jython.org/issue1804

files:
  Lib/socket.py           |  18 +++++++++++++-----
  Lib/test/test_socket.py |  17 ++++++++++++-----
  2 files changed, 25 insertions(+), 10 deletions(-)


diff --git a/Lib/socket.py b/Lib/socket.py
--- a/Lib/socket.py
+++ b/Lib/socket.py
@@ -581,17 +581,25 @@
         return None
     return Protocol.getProtocolByName(protocol_name).getProto()
 
-def _realsocket(family = AF_INET, type = SOCK_STREAM, protocol=0):
+def _realsocket(family = AF_INET, sock_type = SOCK_STREAM, protocol=0):
     assert family in (AF_INET, AF_INET6), "Only AF_INET and AF_INET6 sockets are currently supported on jython"
-    assert type in (SOCK_DGRAM, SOCK_STREAM), "Only SOCK_STREAM and SOCK_DGRAM sockets are currently supported on jython"
-    if type == SOCK_STREAM:
+    assert sock_type in (SOCK_DGRAM, SOCK_STREAM), "Only SOCK_STREAM and SOCK_DGRAM sockets are currently supported on jython"
+    if sock_type == SOCK_STREAM:
         if protocol != 0:
             assert protocol == IPPROTO_TCP, "Only IPPROTO_TCP supported on SOCK_STREAM sockets"
-        return _tcpsocket()
+        else:
+            protocol = IPPROTO_TCP
+        result = _tcpsocket()
     else:
         if protocol != 0:
             assert protocol == IPPROTO_UDP, "Only IPPROTO_UDP supported on SOCK_DGRAM sockets"
-        return _udpsocket()
+        else:
+            protocol = IPPROTO_UDP
+        result = _udpsocket()
+    setattr(result, "family", family)
+    setattr(result, "type",   sock_type)
+    setattr(result, "proto",  protocol)
+    return result
 
 #
 # Attempt to provide IDNA (RFC 3490) support.
diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py
--- a/Lib/test/test_socket.py
+++ b/Lib/test/test_socket.py
@@ -27,11 +27,6 @@
 is_bsd = os_name == 'Mac OS X' or 'BSD' in os_name
 is_solaris = os_name == 'SunOS'
 
-try:
-    True
-except NameError:
-    True, False = 1, 0
-
 class SocketTCPTest(unittest.TestCase):
 
     HOST = HOST
@@ -491,6 +486,18 @@
         name = sock.getsockname()
         self.assertEqual(name, ("0.0.0.0", PORT+1))
 
+    def testSockAttributes(self):
+        # Testing required attributes
+        for family in [socket.AF_INET, socket.AF_INET6]:
+            for sock_type in [socket.SOCK_STREAM, socket.SOCK_DGRAM]:
+                s = socket.socket(family, sock_type)
+                self.assertEqual(s.family, family)
+                self.assertEqual(s.type, sock_type)
+                if sock_type == socket.SOCK_STREAM:
+                    self.assertEqual(s.proto, socket.IPPROTO_TCP)
+                else:
+                    self.assertEqual(s.proto, socket.IPPROTO_UDP)
+
     def testGetSockOpt(self):
         # Testing getsockopt()
         # We know a socket should start without reuse==0

-- 
Repository URL: http://hg.python.org/jython


More information about the Jython-checkins mailing list