[Inteproxy-commits] r62 - in trunk: . inteproxy

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Tue Apr 24 14:55:09 CEST 2007


Author: bh
Date: 2007-04-24 14:55:09 +0200 (Tue, 24 Apr 2007)
New Revision: 62

Added:
   trunk/inteproxy/httpserver.py
Modified:
   trunk/ChangeLog
   trunk/InteProxy.py
Log:
* inteproxy/httpserver.py: New.  Move parts of InteProxy.py here
to form a new base class for HTTP servers that can be run in a
thread and stopped from other threads.

* InteProxy.py (MasterWorkerServer): Derive from
inteproxy.httpserver.HTTPServer
(MasterWorkerServer.serve_forever, MasterWorkerServer.server_close): 
Removed.  They're in the base classe now.


Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2007-04-24 10:40:57 UTC (rev 61)
+++ trunk/ChangeLog	2007-04-24 12:55:09 UTC (rev 62)
@@ -1,3 +1,14 @@
+2007-04-24  Bernhard Herzog  <bh at intevation.de>
+
+	* inteproxy/httpserver.py: New.  Move parts of InteProxy.py here
+	to form a new base class for HTTP servers that can be run in a
+	thread and stopped from other threads.
+
+	* InteProxy.py (MasterWorkerServer): Derive from
+	inteproxy.httpserver.HTTPServer
+	(MasterWorkerServer.serve_forever, MasterWorkerServer.server_close): 
+	Removed.  They're in the base classe now.
+
 2007-04-24  Stephan Holl  <stephan.holl at intevation.de>
 
 	* rpm/inteproxy-sles9.spec: Updated to reflect the backported

Modified: trunk/InteProxy.py
===================================================================
--- trunk/InteProxy.py	2007-04-24 10:40:57 UTC (rev 61)
+++ trunk/InteProxy.py	2007-04-24 12:55:09 UTC (rev 62)
@@ -27,6 +27,7 @@
 from inteproxy.getpassword import getpassword
 from inteproxy.threadpool import ThreadPool
 from inteproxy.feesdialog import handle_fees_and_access_constraints
+from inteproxy.httpserver import HTTPServer
 
 inteproxy_version = "0.1.2"
 
@@ -275,36 +276,17 @@
     return s
 
 
-class MasterWorkerServer(BaseHTTPServer.HTTPServer):
+class MasterWorkerServer(HTTPServer):
 
     do_shutdown = False
 
     def __init__(self, server_address, RequestHandlerClass, num_workers):
-        BaseHTTPServer.HTTPServer.__init__(self, server_address,
-                                           RequestHandlerClass)
+        HTTPServer.__init__(self, server_address, RequestHandlerClass)
         self.thread_pool = ThreadPool(num_workers, lambda f: f())
         sys.stderr.write("[%s] starting %d worker threads\n" \
                          % (log_date_time_string(), num_workers))
         self.thread_pool.start()
 
-    def serve_forever(self):
-        """Handle requests until self.do_shutdown is True."""
-        while not self.do_shutdown:
-            self.handle_request()
-
-    def server_close(self):
-        """Shutdown the server.
-
-        Usually this is called from a thread while another thread
-        executes the server_forever method.  In that case the other
-        thread is most likely blocked while listening for new
-        connections.  After this method returns, the caller will have to
-        do something to unblock the other thread, such as creating a TCP
-        connection to the server.
-        """
-        BaseHTTPServer.HTTPServer.server_close(self)
-        self.do_shutdown = True
-
     def process_request(self, request, client_address):
         """Put the request into the queue to be handled by the worker thread
         """

Added: trunk/inteproxy/httpserver.py
===================================================================
--- trunk/inteproxy/httpserver.py	2007-04-24 10:40:57 UTC (rev 61)
+++ trunk/inteproxy/httpserver.py	2007-04-24 12:55:09 UTC (rev 62)
@@ -0,0 +1,42 @@
+# Copyright (C) 2007 by Intevation GmbH
+# Authors:
+# Bernhard Herzog <bh at intevation.de>
+#
+# This program is free software under the GPL (>=v2)
+# Read the file COPYING coming with the software for details.
+
+"""HTTP server that can run in a thread and be stopped"""
+
+import socket
+import errno
+import threading
+import BaseHTTPServer
+
+
+class HTTPServer(BaseHTTPServer.HTTPServer):
+
+    """HTTP server that can be run in a thread and be stopped"""
+
+    do_shutdown = False
+
+    def getsockname(self):
+        """Return the socket's sockname as a (host, port) tuple"""
+        return self.socket.getsockname()
+
+    def serve_forever(self):
+        """Handle requests until self.do_shutdown is True."""
+        while not self.do_shutdown:
+            self.handle_request()
+
+    def server_close(self):
+        """Shutdown the server.
+
+        Usually this is called from a thread while another thread
+        executes the serve_forever method.  In that case the other
+        thread is most likely blocked while listening for new
+        connections.  After this method returns, the caller will have to
+        do something to unblock the other thread, such as creating a TCP
+        connection to the server.
+        """
+        BaseHTTPServer.HTTPServer.server_close(self)
+        self.do_shutdown = True


Property changes on: trunk/inteproxy/httpserver.py
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + native



More information about the Inteproxy-commits mailing list