瀏覽代碼

Remove ShutdownServerMixIn now that we don't support 2.4 & 2.5.

Signed-off-by: Jelmer Vernooij <jelmer@samba.org>
Gary van der Merwe 11 年之前
父節點
當前提交
2fd68981c9

+ 0 - 79
dulwich/tests/compat/server_utils.py

@@ -234,85 +234,6 @@ class ServerTests(object):
         self.assertReposEqual(clone, self._source_repo)
 
 
-class ShutdownServerMixIn:
-    """Mixin that allows serve_forever to be shut down.
-
-    The methods in this mixin are backported from SocketServer.py in the Python
-    2.6.4 standard library. The mixin is unnecessary in 2.6 and later, when
-    BaseServer supports the shutdown method directly.
-    """
-
-    def __init__(self):
-        self.__is_shut_down = threading.Event()
-        self.__serving = False
-
-    def serve_forever(self, poll_interval=0.5):
-        """Handle one request at a time until shutdown.
-
-        Polls for shutdown every poll_interval seconds. Ignores
-        self.timeout. If you need to do periodic tasks, do them in
-        another thread.
-        """
-        self.__serving = True
-        self.__is_shut_down.clear()
-        while self.__serving:
-            # XXX: Consider using another file descriptor or
-            # 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)
-            if r:
-                self._handle_request_noblock()
-        self.__is_shut_down.set()
-
-    serve = serve_forever  # override alias from TCPGitServer
-
-    def shutdown(self):
-        """Stops the serve_forever loop.
-
-        Blocks until the loop has finished. This must be called while
-        serve_forever() is running in another thread, or it will deadlock.
-        """
-        self.__serving = False
-        self.__is_shut_down.wait()
-
-    def handle_request(self):
-        """Handle one request, possibly blocking.
-
-        Respects self.timeout.
-        """
-        # Support people who used socket.settimeout() to escape
-        # handle_request before self.timeout was available.
-        timeout = self.socket.gettimeout()
-        if timeout is None:
-            timeout = self.timeout
-        elif self.timeout is not None:
-            timeout = min(timeout, self.timeout)
-        fd_sets = select.select([self], [], [], timeout)
-        if not fd_sets[0]:
-            self.handle_timeout()
-            return
-        self._handle_request_noblock()
-
-    def _handle_request_noblock(self):
-        """Handle one request, without blocking.
-
-        I assume that select.select has returned that the socket is
-        readable before this function was called, so there should be
-        no risk of blocking in get_request().
-        """
-        try:
-            request, client_address = self.get_request()
-        except socket.error:
-            return
-        if self.verify_request(request, client_address):
-            try:
-                self.process_request(request, client_address)
-            except:
-                self.handle_error(request, client_address)
-                self.close_request(request)
-
-
 # TODO(dborowitz): Come up with a better way of testing various permutations of
 # capabilities. The only reason it is the way it is now is that side-band-64k
 # was only recently introduced into git-receive-pack.

+ 0 - 15
dulwich/tests/compat/test_client.py

@@ -53,9 +53,6 @@ from dulwich.tests.compat.utils import (
     import_repo_to_dir,
     run_git_or_fail,
     )
-from dulwich.tests.compat.server_utils import (
-    ShutdownServerMixIn,
-    )
 
 
 class DulwichClientTestBase(object):
@@ -439,18 +436,6 @@ class HTTPGitServer(BaseHTTPServer.HTTPServer):
         return 'http://%s:%s/' % (self.server_name, self.server_port)
 
 
-if not getattr(HTTPGitServer, 'shutdown', None):
-    _HTTPGitServer = HTTPGitServer
-
-    class TCPGitServer(ShutdownServerMixIn, HTTPGitServer):
-        """Subclass of HTTPGitServer that can be shut down."""
-
-        def __init__(self, *args, **kwargs):
-            # BaseServer is old-style so we have to call both __init__s
-            ShutdownServerMixIn.__init__(self)
-            _HTTPGitServer.__init__(self, *args, **kwargs)
-
-
 class DulwichHttpClientTest(CompatTestCase, DulwichClientTestBase):
 
     min_git_version = (1, 7, 0, 2)

+ 0 - 15
dulwich/tests/compat/test_server.py

@@ -32,7 +32,6 @@ from dulwich.server import (
     )
 from dulwich.tests.compat.server_utils import (
     ServerTests,
-    ShutdownServerMixIn,
     NoSideBand64kReceivePackHandler,
     )
 from dulwich.tests.compat.utils import (
@@ -40,20 +39,6 @@ from dulwich.tests.compat.utils import (
     )
 
 
-if not getattr(TCPGitServer, 'shutdown', None):
-    _TCPGitServer = TCPGitServer
-
-    class TCPGitServer(ShutdownServerMixIn, TCPGitServer):
-        """Subclass of TCPGitServer that can be shut down."""
-
-        def __init__(self, *args, **kwargs):
-            # BaseServer is old-style so we have to call both __init__s
-            ShutdownServerMixIn.__init__(self)
-            _TCPGitServer.__init__(self, *args, **kwargs)
-
-        serve = ShutdownServerMixIn.serve_forever
-
-
 class GitServerTestCase(ServerTests, CompatTestCase):
     """Tests for client/server compatibility.
 

+ 1 - 16
dulwich/tests/compat/test_web.py

@@ -42,7 +42,6 @@ from dulwich.web import (
 
 from dulwich.tests.compat.server_utils import (
     ServerTests,
-    ShutdownServerMixIn,
     NoSideBand64kReceivePackHandler,
     )
 from dulwich.tests.compat.utils import (
@@ -50,20 +49,6 @@ from dulwich.tests.compat.utils import (
     )
 
 
-if getattr(simple_server.WSGIServer, 'shutdown', None):
-    WSGIServer = WSGIServerLogger
-else:
-    class WSGIServer(ShutdownServerMixIn, WSGIServerLogger):
-        """Subclass of WSGIServer that can be shut down."""
-
-        def __init__(self, *args, **kwargs):
-            # BaseServer is old-style so we have to call both __init__s
-            ShutdownServerMixIn.__init__(self)
-            simple_server.WSGIServer.__init__(self, *args, **kwargs)
-
-        serve = ShutdownServerMixIn.serve_forever
-
-
 class WebTests(ServerTests):
     """Base tests for web server tests.
 
@@ -77,7 +62,7 @@ class WebTests(ServerTests):
         backend = DictBackend({'/': repo})
         app = self._make_app(backend)
         dul_server = simple_server.make_server(
-          'localhost', 0, app, server_class=WSGIServer,
+          'localhost', 0, app, server_class=WSGIServerLogger,
           handler_class=WSGIRequestHandlerLogger)
         self.addCleanup(dul_server.shutdown)
         threading.Thread(target=dul_server.serve_forever).start()