Browse Source

Tweak server handler injection.

Now the server stores a default set of handlers rather than None if
none were passed in. Additionally, callers no longer have to copy
DEFAULT_HANDLERS; the copy is done in the TCPGitServer constructor, and
the dict is updated with any custom handlers.

Change-Id: If617630346bcb57074ec746d8e66d43ba1e00be5
Dave Borowitz 15 years ago
parent
commit
27ef701a57
3 changed files with 10 additions and 4 deletions
  1. 2 0
      NEWS
  2. 4 2
      dulwich/server.py
  3. 4 2
      dulwich/web.py

+ 2 - 0
NEWS

@@ -37,6 +37,8 @@
 
   * Change server capabilities methods to classmethods. (Dave Borowitz)
 
+  * Tweak server handler injection. (Dave Borowitz)
+
 
 0.6.1	2010-07-22
 

+ 4 - 2
dulwich/server.py

@@ -684,7 +684,7 @@ DEFAULT_HANDLERS = {
 class TCPGitRequestHandler(SocketServer.StreamRequestHandler):
 
     def __init__(self, handlers, *args, **kwargs):
-        self.handlers = handlers and handlers or DEFAULT_HANDLERS
+        self.handlers = handlers
         SocketServer.StreamRequestHandler.__init__(self, *args, **kwargs)
 
     def handle(self):
@@ -708,8 +708,10 @@ class TCPGitServer(SocketServer.TCPServer):
         return TCPGitRequestHandler(self.handlers, *args, **kwargs)
 
     def __init__(self, backend, listen_addr, port=TCP_GIT_PORT, handlers=None):
+        self.handlers = dict(DEFAULT_HANDLERS)
+        if handlers is not None:
+            self.handlers.update(handlers)
         self.backend = backend
-        self.handlers = handlers
         logger.info('Listening for TCP connections on %s:%d', listen_addr, port)
         SocketServer.TCPServer.__init__(self, (listen_addr, port),
                                         self._make_handler)

+ 4 - 2
dulwich/web.py

@@ -259,7 +259,7 @@ class HTTPGitRequest(object):
     def __init__(self, environ, start_response, dumb=False, handlers=None):
         self.environ = environ
         self.dumb = dumb
-        self.handlers = handlers and handlers or DEFAULT_HANDLERS
+        self.handlers = handlers
         self._start_response = start_response
         self._cache_headers = []
         self._headers = []
@@ -340,7 +340,9 @@ class HTTPGitApplication(object):
     def __init__(self, backend, dumb=False, handlers=None):
         self.backend = backend
         self.dumb = dumb
-        self.handlers = handlers
+        self.handlers = dict(DEFAULT_HANDLERS)
+        if handlers is not None:
+            self.handlers.update(handlers)
 
     def __call__(self, environ, start_response):
         path = environ['PATH_INFO']