[MERGE] Add and use _get_protocol_factory_for_bytes function (protocol v3 patch 3/7)

Andrew Bennetts andrew at canonical.com
Tue May 6 02:06:26 BST 2008

John Arbash Meinel wrote:
> John Arbash Meinel has voted tweak.
> Status is now: Conditionally approved
> Comment:
> It seems a bit odd to have MESSAGE_VERSION_THREE versus  

Well, I realised that there was no value added by having different version
markers for requests and responses; in v3 the same basic protocol decoding
applies either way.  They are all just messages.  So I decided to make things
simpler and just have MESSAGE_VERSION_THREE rather than needing separate

> I also don't see any direct tests for _get_protocol_factory_for_bytes,  
> which seems like an important function (IMO).

Fair enough.  I've added some:

+class TestGetProtocolFactoryForBytes(tests.TestCase):
+    """_get_protocol_factory_for_bytes identifies the protocol factory a server
+    should use to decode a given request.  Any bytes not part of the version
+    marker string (and thus part of the actual request) are returned alongside
+    the protocol factory.
+    """
+    def test_version_three(self):
+        result = medium._get_protocol_factory_for_bytes(
+            'bzr message 3 (bzr 1.3)\nextra bytes')
+        protocol_factory, remainder = result
+        self.assertEqual(
+            protocol.build_server_protocol_three, protocol_factory)
+        self.assertEqual('extra bytes', remainder)
+    def test_version_two(self):
+        result = medium._get_protocol_factory_for_bytes(
+            'bzr request 2\nextra bytes')
+        protocol_factory, remainder = result
+        self.assertEqual(
+            protocol.SmartServerRequestProtocolTwo, protocol_factory)
+        self.assertEqual('extra bytes', remainder)
+    def test_version_one(self):
+        """Version one requests have no version markers."""
+        result = medium._get_protocol_factory_for_bytes('anything\n')
+        protocol_factory, remainder = result
+        self.assertEqual(
+            protocol.SmartServerRequestProtocolOne, protocol_factory)
+        self.assertEqual('anything\n', remainder)

More information about the bazaar mailing list