← Back to team overview

dulwich-users team mailing list archive

[PATCH 3/7] server: Change capabilities methods to classmethods.

 

From: Dave Borowitz <dborowitz@xxxxxxxxxx>

This makes more sense as currently the correct way to make a handler
with different capabilities is to override this method in a subclass.

Change-Id: Iff42b1c6fdd3a2578acd21896621ada9a2b4f1ac
---
 NEWS                         |    2 ++
 dulwich/server.py            |   25 ++++++++++++++++---------
 dulwich/tests/test_server.py |   22 +++++++++++++++++-----
 3 files changed, 35 insertions(+), 14 deletions(-)

diff --git a/NEWS b/NEWS
index 1f815ff..4f826ca 100644
--- a/NEWS
+++ b/NEWS
@@ -35,6 +35,8 @@
   * ObjectStore.iter_tree_contents can optionally yield tree objects as well.
     (Dave Borowitz).
 
+  * Change server capabilities methods to classmethods. (Dave Borowitz)
+
 
 0.6.1	2010-07-22
 
diff --git a/dulwich/server.py b/dulwich/server.py
index f70fb66..909b571 100644
--- a/dulwich/server.py
+++ b/dulwich/server.py
@@ -161,16 +161,20 @@ class Handler(object):
         self.proto = proto
         self._client_capabilities = None
 
-    def capability_line(self):
-        return " ".join(self.capabilities())
+    @classmethod
+    def capability_line(cls):
+        return " ".join(cls.capabilities())
 
-    def capabilities(self):
-        raise NotImplementedError(self.capabilities)
+    @classmethod
+    def capabilities(cls):
+        raise NotImplementedError(cls.capabilities)
 
-    def innocuous_capabilities(self):
+    @classmethod
+    def innocuous_capabilities(cls):
         return ("include-tag", "thin-pack", "no-progress", "ofs-delta")
 
-    def required_capabilities(self):
+    @classmethod
+    def required_capabilities(cls):
         """Return a list of capabilities that we require the client to have."""
         return []
 
@@ -206,11 +210,13 @@ class UploadPackHandler(Handler):
         self.stateless_rpc = stateless_rpc
         self.advertise_refs = advertise_refs
 
-    def capabilities(self):
+    @classmethod
+    def capabilities(cls):
         return ("multi_ack_detailed", "multi_ack", "side-band-64k", "thin-pack",
                 "ofs-delta", "no-progress", "include-tag")
 
-    def required_capabilities(self):
+    @classmethod
+    def required_capabilities(cls):
         return ("side-band-64k", "thin-pack", "ofs-delta")
 
     def progress(self, message):
@@ -569,7 +575,8 @@ class ReceivePackHandler(Handler):
         self.stateless_rpc = stateless_rpc
         self.advertise_refs = advertise_refs
 
-    def capabilities(self):
+    @classmethod
+    def capabilities(cls):
         return ("report-status", "delete-refs")
 
     def _apply_pack(self, refs):
diff --git a/dulwich/tests/test_server.py b/dulwich/tests/test_server.py
index 04b6f8b..8181c24 100644
--- a/dulwich/tests/test_server.py
+++ b/dulwich/tests/test_server.py
@@ -76,13 +76,24 @@ class TestProto(object):
             return None
 
 
+class TestGenericHandler(Handler):
+
+    def __init__(self):
+        Handler.__init__(self, Backend(), None)
+
+    @classmethod
+    def capabilities(cls):
+        return ('cap1', 'cap2', 'cap3')
+
+    @classmethod
+    def required_capabilities(cls):
+        return ('cap2',)
+
+
 class HandlerTestCase(TestCase):
 
     def setUp(self):
-        super(HandlerTestCase, self).setUp()
-        self._handler = Handler(Backend(), None)
-        self._handler.capabilities = lambda: ('cap1', 'cap2', 'cap3')
-        self._handler.required_capabilities = lambda: ('cap2',)
+        self._handler = TestGenericHandler()
 
     def assertSucceeds(self, func, *args, **kwargs):
         try:
@@ -208,7 +219,8 @@ class TestUploadPackHandler(Handler):
         self.stateless_rpc = False
         self.advertise_refs = False
 
-    def capabilities(self):
+    @classmethod
+    def capabilities(cls):
         return ('multi_ack',)
 
 
-- 
1.7.1




References