Merge Dave's fixes for the compatibility tests and web.
authorJelmer Vernooij <jelmer@samba.org>
Sat, 3 Apr 2010 18:26:51 +0000 (20:26 +0200)
committerJelmer Vernooij <jelmer@samba.org>
Sat, 3 Apr 2010 18:26:51 +0000 (20:26 +0200)
1  2 
dulwich/server.py
dulwich/tests/compat/test_server.py
dulwich/tests/compat/test_web.py
dulwich/tests/test_web.py
dulwich/web.py

Simple merge
index a2739d5070ddba236cb0162ecf295286cfeac80c,86a583378e90800fa124e27c7f2e7b5f3048cd0b..1d2847ebf46aaee06614a2591a9f1efeb1b3cba0
@@@ -26,7 -26,11 +26,10 @@@ On *nix, you can kill the tests with Ct
  
  import threading
  
- from dulwich import server
+ from dulwich.server import (
+     DictBackend,
 -    GitBackendRepo,
+     TCPGitServer,
+     )
  from server_utils import (
      ServerTests,
      ShutdownServerMixIn,
@@@ -65,9 -69,8 +68,8 @@@ class GitServerTestCase(ServerTests, Co
          CompatTestCase.tearDown(self)
  
      def _start_server(self, repo):
-         dul_server = TCPGitServer(
-             server.DictBackend({"/": repo}),
-             'localhost', 0)
 -        backend = DictBackend({'/': GitBackendRepo(repo)})
++        backend = DictBackend({'/': repo})
+         dul_server = TCPGitServer(backend, 'localhost', 0)
          threading.Thread(target=dul_server.serve).start()
          self._server = dul_server
          _, port = self._server.socket.getsockname()
index 1ef6c862da955dd6949537cb323b78350132425d,36e1522fb8bbd8deeaafced6a74194a6c6026f8c..5a1c038c3a26bb1c8f6bbacdc17fc3853e074c5e
@@@ -27,6 -27,10 +27,9 @@@ On *nix, you can kill the tests with Ct
  import threading
  from wsgiref import simple_server
  
 -    GitBackendRepo,
+ from dulwich.server import (
+     DictBackend,
+     )
  from dulwich.web import (
      HTTPGitApplication,
      )
@@@ -65,7 -69,8 +68,8 @@@ class WebTests(ServerTests)
      protocol = 'http'
  
      def _start_server(self, repo):
-         app = self._make_app(repo)
 -        backend = DictBackend({'/': GitBackendRepo(repo)})
++        backend = DictBackend({'/': repo})
+         app = self._make_app(backend)
          dul_server = simple_server.make_server('localhost', 0, app,
                                                 server_class=WSGIServer)
          threading.Thread(target=dul_server.serve_forever).start()
index 0a4817fa8e8e6b4be8cf8a89feccbad0c18529fc,aea558a39aa502f48df03bdd237499bd39e6a5f1..17bf499dff32f2ad8a9e33a61cd67927e35b7448
@@@ -109,20 -110,11 +109,11 @@@ class DumbHandlersTestCase(WebTestCase)
  
          tag1 = TestTag('aaa', Blob, '222')
  
-         class TestBackend(object):
+         class TestRepo(object):
 +
-             def __init__(self):
-                 objects = [blob1, blob2, blob3, tag1]
+             def __init__(self, objects, peeled):
                  self._objects = dict((o.sha(), o) for o in objects)
-                 self._peeled = {
-                     'HEAD': '000',
-                     'refs/heads/master': blob1.sha(),
-                     'refs/tags/tag-tag': blob2.sha(),
-                     'refs/tags/blob-tag': blob3.sha(),
-                     }
-             def __getitem__(self, sha):
-                 return self._objects[sha]
+                 self._peeled = peeled
 -                self.repo = self
  
              def get_peeled(self, sha):
                  return self._peeled[sha]
diff --cc dulwich/web.py
index 05369b378e34b00b8b9139dced8efa61be7e7957,06d19e9a26a745674644087578031aefe02fa372..7b790ba8637c12a987205f8be4c380aa89dd4768
@@@ -46,6 -46,22 +46,22 @@@ def date_time_string(timestamp=None)
              weekdays[wd], day, months[month], year, hh, mm, ss)
  
  
 -    return backend.open_repository(url_prefix(mat)).repo
+ def url_prefix(mat):
+     """Extract the URL prefix from a regex match.
+     :param mat: A regex match object.
+     :returns: The URL prefix, defined as the text before the match in the
+         original string. Normalized to start with one leading slash and end with
+         zero.
+     """
+     return '/' + mat.string[:mat.start()].strip('/')
+ def get_repo(backend, mat):
+     """Get a Repo instance for the given backend and URL regex match."""
++    return backend.open_repository(url_prefix(mat))
  def send_file(req, f, content_type):
      """Send a file-like object to the request output.