Rev 2220: Rename call2 to call_expecting_body, and other small changes prompted by review. in sftp://bazaar.launchpad.net/%7Ebzr/bzr/hpss/

Andrew Bennetts andrew.bennetts at canonical.com
Mon Apr 16 03:57:46 BST 2007


At sftp://bazaar.launchpad.net/%7Ebzr/bzr/hpss/

------------------------------------------------------------
revno: 2220
revision-id: andrew.bennetts at canonical.com-20070416025619-v6rjozkjjnrg970w
parent: andrew.bennetts at canonical.com-20070414142229-633813p69cryl6gm
committer: Andrew Bennetts <andrew.bennetts at canonical.com>
branch nick: hpss
timestamp: Mon 2007-04-16 12:56:19 +1000
message:
  Rename call2 to call_expecting_body, and other small changes prompted by review.
modified:
  bzrlib/remote.py               remote.py-20060720103555-yeeg2x51vn0rbtdp-1
  bzrlib/smart/client.py         client.py-20061116014825-2k6ada6xgulslami-1
  bzrlib/tests/test_remote.py    test_remote.py-20060720103555-yeeg2x51vn0rbtdp-2
  bzrlib/tests/test_smart_transport.py test_ssh_transport.py-20060608202016-c25gvf1ob7ypbus6-2
  bzrlib/tests/test_transport_implementations.py test_transport_implementations.py-20051227111451-f97c5c7d5c49fce7
=== modified file 'bzrlib/remote.py'
--- a/bzrlib/remote.py	2007-04-12 07:08:33 +0000
+++ b/bzrlib/remote.py	2007-04-16 02:56:19 +0000
@@ -259,7 +259,7 @@
 
         path = self.bzrdir._path_for_remote_call(self._client)
         assert type(revision_id) is str
-        response = self._client.call2(
+        response = self._client.call_expecting_body(
             'Repository.get_revision_graph', path, revision_id)
         assert response[0][0] in ('ok', 'nosuchrevision'), 'unexpected response code %s' % (response[0],)
         if response[0][0] == 'ok':
@@ -301,8 +301,8 @@
             fmt_committers = 'no'
         else:
             fmt_committers = 'yes'
-        response = self._client.call2('Repository.gather_stats', path,
-                                      fmt_revid, fmt_committers)
+        response = self._client.call_expecting_body(
+            'Repository.gather_stats', path, fmt_revid, fmt_committers)
         assert response[0][0] == 'ok', \
             'unexpected response code %s' % (response[0],)
 
@@ -631,7 +631,8 @@
         """
         if path == 'branch.conf':
             path = self.bzrdir._path_for_remote_call(self._client)
-            response = self._client.call2('Branch.get_config_file', path)
+            response = self._client.call_expecting_body(
+                'Branch.get_config_file', path)
             assert response[0][0] == 'ok', \
                 'unexpected response code %s' % (response[0],)
             return StringIO(response[1].read_body_bytes())
@@ -862,8 +863,10 @@
     def _gen_revision_history(self):
         """See Branch._gen_revision_history()."""
         path = self.bzrdir._path_for_remote_call(self._client)
-        response = self._client.call2('Branch.revision_history', path)
-        assert response[0][0] == 'ok', 'unexpected response code %s' % (response[0],)
+        response = self._client.call_expecting_body(
+            'Branch.revision_history', path)
+        assert response[0][0] == 'ok', ('unexpected response code %s'
+                                        % (response[0],))
         result = response[1].read_body_bytes().split('\x00')
         if result == ['']:
             return []

=== modified file 'bzrlib/smart/client.py'
--- a/bzrlib/smart/client.py	2007-03-29 08:46:23 +0000
+++ b/bzrlib/smart/client.py	2007-04-16 02:56:19 +0000
@@ -27,12 +27,18 @@
 
     def call(self, method, *args):
         """Call a method on the remote server."""
-        result, protocol = self.call2(method, *args)
+        result, protocol = self.call_expecting_body(method, *args)
         protocol.cancel_read_body()
         return result
 
-    def call2(self, method, *args):
-        """Call a method and return the result and the protocol object."""
+    def call_expecting_body(self, method, *args):
+        """Call a method and return the result and the protocol object.
+        
+        The body can be read like so::
+
+            result, smart_protocol = smart_client.call_expecting_body(...)
+            body = smart_protocol.read_body_bytes()
+        """
         request = self._medium.get_request()
         smart_protocol = protocol.SmartClientRequestProtocolOne(request)
         smart_protocol.call(method, *args)
@@ -53,5 +59,10 @@
         return smart_protocol.read_response_tuple()
 
     def remote_path_from_transport(self, transport):
-        """Convert transport into a path suitable for using in a request."""
+        """Convert transport into a path suitable for using in a request.
+        
+        Note that the resulting remote path doesn't encode the host name or
+        anything but path, so it is only safe to use it in requests sent over
+        the medium from the matching transport.
+        """
         return unescape(urlparse(transport.base)[2]).encode('utf8')

=== modified file 'bzrlib/tests/test_remote.py'
--- a/bzrlib/tests/test_remote.py	2007-04-05 09:35:26 +0000
+++ b/bzrlib/tests/test_remote.py	2007-04-16 02:56:19 +0000
@@ -137,8 +137,8 @@
         self._calls.append(('call', method, args))
         return self.responses.pop(0)[0]
 
-    def call2(self, method, *args):
-        self._calls.append(('call2', method, args))
+    def call_expecting_body(self, method, *args):
+        self._calls.append(('call_expecting_body', method, args))
         result = self.responses.pop(0)
         return result[0], FakeProtocol(result[1])
 
@@ -342,7 +342,7 @@
         branch = RemoteBranch(bzrdir, None, _client=client)
         result = branch.control_files.get('branch.conf')
         self.assertEqual(
-            [('call2', 'Branch.get_config_file', ('///quack/',))],
+            [('call_expecting_body', 'Branch.get_config_file', ('///quack/',))],
             client._calls)
         self.assertEqual('config file body', result.read())
 
@@ -387,7 +387,8 @@
             responses, transport_path)
         result = repo.gather_stats(None)
         self.assertEqual(
-            [('call2', 'Repository.gather_stats', ('///quack/','','no'))],
+            [('call_expecting_body', 'Repository.gather_stats',
+             ('///quack/','','no'))],
             client._calls)
         self.assertEqual({'revisions': 2, 'size': 18}, result)
 
@@ -404,7 +405,7 @@
             responses, transport_path)
         result = repo.gather_stats(revid)
         self.assertEqual(
-            [('call2', 'Repository.gather_stats',
+            [('call_expecting_body', 'Repository.gather_stats',
               ('///quick/', revid, 'no'))],
             client._calls)
         self.assertEqual({'revisions': 2, 'size': 18,
@@ -426,7 +427,7 @@
             responses, transport_path)
         result = repo.gather_stats(revid, True)
         self.assertEqual(
-            [('call2', 'Repository.gather_stats',
+            [('call_expecting_body', 'Repository.gather_stats',
               ('///buick/', revid, 'yes'))],
             client._calls)
         self.assertEqual({'revisions': 2, 'size': 18,
@@ -462,7 +463,8 @@
             responses, transport_path)
         result = repo.get_revision_graph()
         self.assertEqual(
-            [('call2', 'Repository.get_revision_graph', ('///sinhala/', ''))],
+            [('call_expecting_body', 'Repository.get_revision_graph',
+             ('///sinhala/', ''))],
             client._calls)
         self.assertEqual({r1: [], r2: [r1]}, result)
 
@@ -481,7 +483,8 @@
             responses, transport_path)
         result = repo.get_revision_graph(r2)
         self.assertEqual(
-            [('call2', 'Repository.get_revision_graph', ('///sinhala/', r2))],
+            [('call_expecting_body', 'Repository.get_revision_graph',
+             ('///sinhala/', r2))],
             client._calls)
         self.assertEqual({r11: [], r12: [], r2: [r11, r12], }, result)
 
@@ -495,7 +498,8 @@
         self.assertRaises(errors.NoSuchRevision,
             repo.get_revision_graph, revid)
         self.assertEqual(
-            [('call2', 'Repository.get_revision_graph', ('///sinhala/', revid))],
+            [('call_expecting_body', 'Repository.get_revision_graph',
+             ('///sinhala/', revid))],
             client._calls)
 
         

=== modified file 'bzrlib/tests/test_smart_transport.py'
--- a/bzrlib/tests/test_smart_transport.py	2007-04-13 05:48:30 +0000
+++ b/bzrlib/tests/test_smart_transport.py	2007-04-16 02:56:19 +0000
@@ -1477,6 +1477,7 @@
 
     def test_call_with_body_bytes_unicode_args(self):
         self.assertCallDoesNotBreakMedium('method', (u'args',), 'body')
+        self.assertCallDoesNotBreakMedium('method', ('arg1', u'arg2'), 'body')
 
     def test_call_with_body_bytes_unicode_body(self):
         self.assertCallDoesNotBreakMedium('method', ('args',), u'body')

=== modified file 'bzrlib/tests/test_transport_implementations.py'
--- a/bzrlib/tests/test_transport_implementations.py	2007-04-11 04:26:23 +0000
+++ b/bzrlib/tests/test_transport_implementations.py	2007-04-16 02:56:19 +0000
@@ -376,6 +376,7 @@
         # (we don't want to encode unicode here at all, callers should be
         # strictly passing bytes to put_bytes), but we allow it for backwards
         # compatibility.  At some point we should use a specific exception.
+        # See https://bugs.launchpad.net/bzr/+bug/106898.
         t = self.get_transport()
         if t.is_readonly():
             return




More information about the bazaar-commits mailing list