[Jython-checkins] jython: Upgrading SocketServer to 2.7. Step 3: Add jython specific customisations.

alan.kennedy jython-checkins at python.org
Sun Apr 1 17:22:16 CEST 2012


http://hg.python.org/jython/rev/6437b9f366f8
changeset:   6517:6437b9f366f8
user:        Alan Kennedy <alan at xhaus.com>
date:        Sun Apr 01 14:15:30 2012 +0100
summary:
  Upgrading SocketServer to 2.7. Step 3: Add jython specific customisations.

files:
  Lib/SocketServer.py           |  13 ++++++++++---
  Lib/test/test_socketserver.py |   8 ++++++--
  2 files changed, 16 insertions(+), 5 deletions(-)


diff --git a/Lib/SocketServer.py b/Lib/SocketServer.py
--- a/Lib/SocketServer.py
+++ b/Lib/SocketServer.py
@@ -138,6 +138,10 @@
 except ImportError:
     import dummy_threading as threading
 
+select_fn = select.select
+if sys.platform.startswith('java'):
+    select_fn = select.cpython_compatible_select
+
 __all__ = ["TCPServer","UDPServer","ForkingUDPServer","ForkingTCPServer",
            "ThreadingUDPServer","ThreadingTCPServer","BaseRequestHandler",
            "StreamRequestHandler","DatagramRequestHandler",
@@ -222,7 +226,7 @@
                 # connecting to the socket to wake this up instead of
                 # polling. Polling reduces our responsiveness to a
                 # shutdown request and wastes cpu at all other times.
-                r, w, e = select.select([self], [], [], poll_interval)
+                r, w, e = select_fn([self], [], [], poll_interval)
                 if self in r:
                     self._handle_request_noblock()
         finally:
@@ -262,7 +266,7 @@
             timeout = self.timeout
         elif self.timeout is not None:
             timeout = min(timeout, self.timeout)
-        fd_sets = select.select([self], [], [], timeout)
+        fd_sets = select_fn([self], [], [], timeout)
         if not fd_sets[0]:
             self.handle_timeout()
             return
@@ -271,7 +275,7 @@
     def _handle_request_noblock(self):
         """Handle one request, without blocking.
 
-        I assume that select.select has returned that the socket is
+        I assume that select_fn has returned that the socket is
         readable before this function was called, so there should be
         no risk of blocking in get_request().
         """
@@ -426,6 +430,9 @@
 
         """
         self.socket.listen(self.request_queue_size)
+        # Adding a second call to getsockname() because of this issue
+        # http://wiki.python.org/jython/NewSocketModule#Deferredsocketcreationonjython
+        self.server_address = self.socket.getsockname()
 
     def server_close(self):
         """Called to clean-up the server.
diff --git a/Lib/test/test_socketserver.py b/Lib/test/test_socketserver.py
--- a/Lib/test/test_socketserver.py
+++ b/Lib/test/test_socketserver.py
@@ -29,11 +29,15 @@
 
 def signal_alarm(n):
     """Call signal.alarm when it exists (i.e. not on Windows)."""
-    if hasattr(signal, 'alarm'):
+    if hasattr(signal, 'alarm') and not test.test_support.is_jython:
         signal.alarm(n)
 
+select_fn = select.select
+if test.test_support.is_jython:
+    select_fn = select.cpython_compatible_select
+
 def receive(sock, n, timeout=20):
-    r, w, x = select.select([sock], [], [], timeout)
+    r, w, x = select_fn([sock], [], [], timeout)
     if sock in r:
         return sock.recv(n)
     else:

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


More information about the Jython-checkins mailing list