[Jython-checkins] jython (merge 2.5 -> default): merge w/2.5: Fixing socket constant to name mapping for error reporting

alan.kennedy jython-checkins at python.org
Sun Apr 1 20:47:53 CEST 2012


http://hg.python.org/jython/rev/623abab032b2
changeset:   6526:623abab032b2
parent:      6524:491a9451d21d
parent:      6525:1b18d875074e
user:        Alan Kennedy <alan at xhaus.com>
date:        Sun Apr 01 19:46:40 2012 +0100
summary:
  merge w/2.5: Fixing socket constant to name mapping for error reporting

files:
  Lib/socket.py           |  4 +++-
  Lib/test/test_socket.py |  5 +++++
  2 files changed, 8 insertions(+), 1 deletions(-)


diff --git a/Lib/socket.py b/Lib/socket.py
--- a/Lib/socket.py
+++ b/Lib/socket.py
@@ -272,7 +272,9 @@
     sock_module = sys.modules['socket']
     try:
         for name in dir(sock_module):
-            if getattr(sock_module, name) is const_value:
+            if getattr(sock_module, name) is const_value and \
+                (name.startswith('SO_') or name.startswith('SOL_') or \
+                name.startswith('TCP_') or name.startswith('IPPROTO_')):
                 return name
         return "Unknown"
     finally:
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
@@ -275,6 +275,11 @@
         socket.SOL_SOCKET
         socket.SO_REUSEADDR
 
+    def testConstantToNameMapping(self):
+        # Testing for mission critical constants
+        for name in ['SOL_SOCKET', 'IPPROTO_TCP', 'IPPROTO_UDP', 'SO_BROADCAST', 'SO_KEEPALIVE', 'TCP_NODELAY', 'SO_ACCEPTCONN', 'SO_DEBUG']:
+            self.failUnlessEqual(socket._constant_to_name(getattr(socket, name)), name)
+
     def testHostnameRes(self):
         # Testing hostname resolution mechanisms
         hostname = socket.gethostname()

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


More information about the Jython-checkins mailing list