Rev 3321: Deprecate get_shared_medium, in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Tue Apr 1 03:16:27 BST 2008


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 3321
revision-id:pqm at pqm.ubuntu.com-20080401021614-ec34l5pd7xp7bkku
parent: pqm at pqm.ubuntu.com-20080401003613-w51tu4gd3yqogm8s
parent: andrew.bennetts at canonical.com-20080401001026-xepuw2kgo8sgl4tr
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Tue 2008-04-01 03:16:14 +0100
message:
  Deprecate get_shared_medium,
  	and pass medium & base directly into _SmartClient. (Andrew Bennetts)
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/bzrdir.py               bzrdir.py-20060131065624-156dfea39c4387cb
  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/transport/__init__.py   transport.py-20050711165921-4978aa7ce1285ad5
  bzrlib/transport/remote.py     ssh.py-20060608202016-c25gvf1ob7ypbus6-1
    ------------------------------------------------------------
    revno: 3313.2.4
    revision-id:andrew.bennetts at canonical.com-20080401001026-xepuw2kgo8sgl4tr
    parent: andrew.bennetts at canonical.com-20080328085843-pdstuawpwy1hst6r
    committer: Andrew Bennetts <andrew.bennetts at canonical.com>
    branch nick: _SmartClient-takes-medium
    timestamp: Tue 2008-04-01 11:10:26 +1100
    message:
      Add NEWS entry for deprecation.
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
    ------------------------------------------------------------
    revno: 3313.2.3
    revision-id:andrew.bennetts at canonical.com-20080328085843-pdstuawpwy1hst6r
    parent: andrew.bennetts at canonical.com-20080328080743-imj32s5lln6lw3ul
    committer: Andrew Bennetts <andrew.bennetts at canonical.com>
    branch nick: _SmartClient takes medium
    timestamp: Fri 2008-03-28 19:58:43 +1100
    message:
      Deprecate Transport.get_shared_medium.
    modified:
      bzrlib/remote.py               remote.py-20060720103555-yeeg2x51vn0rbtdp-1
      bzrlib/transport/__init__.py   transport.py-20050711165921-4978aa7ce1285ad5
      bzrlib/transport/remote.py     ssh.py-20060608202016-c25gvf1ob7ypbus6-1
    ------------------------------------------------------------
    revno: 3313.2.2
    revision-id:andrew.bennetts at canonical.com-20080328080743-imj32s5lln6lw3ul
    parent: andrew.bennetts at canonical.com-20080328080551-n7f6rejuycnzn0p8
    committer: Andrew Bennetts <andrew.bennetts at canonical.com>
    branch nick: _SmartClient takes medium
    timestamp: Fri 2008-03-28 19:07:43 +1100
    message:
      Add comment.
    modified:
      bzrlib/transport/remote.py     ssh.py-20060608202016-c25gvf1ob7ypbus6-1
    ------------------------------------------------------------
    revno: 3313.2.1
    revision-id:andrew.bennetts at canonical.com-20080328080551-n7f6rejuycnzn0p8
    parent: pqm at pqm.ubuntu.com-20080328064220-ongijg78bfqhvbay
    committer: Andrew Bennetts <andrew.bennetts at canonical.com>
    branch nick: _SmartClient takes medium
    timestamp: Fri 2008-03-28 19:05:51 +1100
    message:
      Change _SmartClient's API to accept a medium and a base, rather than a _SharedConnection.
    modified:
      bzrlib/bzrdir.py               bzrdir.py-20060131065624-156dfea39c4387cb
      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/transport/remote.py     ssh.py-20060608202016-c25gvf1ob7ypbus6-1
=== modified file 'NEWS'
--- a/NEWS	2008-04-01 00:36:13 +0000
+++ b/NEWS	2008-04-01 02:16:14 +0000
@@ -91,6 +91,9 @@
     * ``revision.revision_graph`` is deprecated, with no replacement function.
       The function was size(history) and not desirable. (Robert Collins)
 
+    * ``Transport.get_shared_medium`` is deprecated.  Use
+      ``Transport.get_smart_medium`` instead.  (Andrew Bennetts)
+
     * ``VersionedFile.get_graph`` is deprecated, with no replacement method.
       The method was size(history) and not desirable. (Robert Collins)
 

=== modified file 'bzrlib/bzrdir.py'
--- a/bzrlib/bzrdir.py	2008-03-26 09:50:48 +0000
+++ b/bzrlib/bzrdir.py	2008-03-28 08:05:51 +0000
@@ -2415,15 +2415,14 @@
     def initialize_on_transport(self, transport):
         try:
             # hand off the request to the smart server
-            shared_medium = transport.get_shared_medium()
+            client_medium = transport.get_smart_medium()
         except errors.NoSmartMedium:
             # TODO: lookup the local format from a server hint.
             local_dir_format = BzrDirMetaFormat1()
             return local_dir_format.initialize_on_transport(transport)
-        client = _SmartClient(shared_medium)
+        client = _SmartClient(client_medium, transport.base)
         path = client.remote_path_from_transport(transport)
-        response = _SmartClient(shared_medium).call('BzrDirFormat.initialize',
-                                                    path)
+        response = client.call('BzrDirFormat.initialize', path)
         assert response[0] in ('ok', ), 'unexpected response code %s' % (response,)
         return remote.RemoteBzrDir(transport)
 

=== modified file 'bzrlib/remote.py'
--- a/bzrlib/remote.py	2008-03-27 00:27:41 +0000
+++ b/bzrlib/remote.py	2008-03-28 08:58:43 +0000
@@ -62,11 +62,10 @@
         self._real_bzrdir = None
 
         if _client is None:
-            self._shared_medium = transport.get_shared_medium()
-            self._client = client._SmartClient(self._shared_medium)
+            medium = transport.get_smart_medium()
+            self._client = client._SmartClient(medium, transport.base)
         else:
             self._client = _client
-            self._shared_medium = None
             return
 
         path = self._path_for_remote_call(self._client)
@@ -277,7 +276,7 @@
             self._real_repository = None
         self.bzrdir = remote_bzrdir
         if _client is None:
-            self._client = client._SmartClient(self.bzrdir._shared_medium)
+            self._client = remote_bzrdir._client
         else:
             self._client = _client
         self._format = format
@@ -836,7 +835,7 @@
 
     def _get_parent_map(self, keys):
         """Helper for get_parent_map that performs the RPC."""
-        medium = self._client.get_smart_medium()
+        medium = self._client._medium
         if not medium._remote_is_at_least_1_2:
             # We already found out that the server can't understand
             # Repository.get_parent_map requests, so just fetch the whole
@@ -1055,7 +1054,7 @@
         return self._real_repository.has_signature_for_revision_id(revision_id)
 
     def get_data_stream_for_search(self, search):
-        medium = self._client.get_smart_medium()
+        medium = self._client._medium
         if not medium._remote_is_at_least_1_2:
             self._ensure_real()
             return self._real_repository.get_data_stream_for_search(search)
@@ -1229,7 +1228,7 @@
         if _client is not None:
             self._client = _client
         else:
-            self._client = client._SmartClient(self.bzrdir._shared_medium)
+            self._client = remote_bzrdir._client
         self.repository = remote_repository
         if real_branch is not None:
             self._real_branch = real_branch

=== modified file 'bzrlib/smart/client.py'
--- a/bzrlib/smart/client.py	2008-03-05 15:48:27 +0000
+++ b/bzrlib/smart/client.py	2008-03-28 08:05:51 +0000
@@ -23,15 +23,14 @@
 
 class _SmartClient(object):
 
-    def __init__(self, shared_connection):
+    def __init__(self, medium, base):
         """Constructor.
 
-        :param shared_connection: a bzrlib.transport._SharedConnection
+        :param medium: a SmartClientMedium
+        :param base: a URL
         """
-        self._shared_connection = shared_connection
-
-    def get_smart_medium(self):
-        return self._shared_connection.connection
+        self._medium = medium
+        self._base = base
 
     def call(self, method, *args):
         """Call a method on the remote server."""
@@ -47,7 +46,7 @@
             result, smart_protocol = smart_client.call_expecting_body(...)
             body = smart_protocol.read_body_bytes()
         """
-        request = self.get_smart_medium().get_request()
+        request = self._medium.get_request()
         smart_protocol = protocol.SmartClientRequestProtocolTwo(request)
         smart_protocol.call(method, *args)
         return smart_protocol.read_response_tuple(expect_body=True), smart_protocol
@@ -61,7 +60,7 @@
                 raise TypeError('args must be byte strings, not %r' % (args,))
         if type(body) is not str:
             raise TypeError('body must be byte string, not %r' % (body,))
-        request = self.get_smart_medium().get_request()
+        request = self._medium.get_request()
         smart_protocol = protocol.SmartClientRequestProtocolOne(request)
         smart_protocol.call_with_body_bytes((method, ) + args, body)
         return smart_protocol.read_response_tuple()
@@ -75,7 +74,7 @@
                 raise TypeError('args must be byte strings, not %r' % (args,))
         if type(body) is not str:
             raise TypeError('body must be byte string, not %r' % (body,))
-        request = self.get_smart_medium().get_request()
+        request = self._medium.get_request()
         smart_protocol = protocol.SmartClientRequestProtocolTwo(request)
         smart_protocol.call_with_body_bytes((method, ) + args, body)
         return smart_protocol.read_response_tuple(expect_body=True), smart_protocol
@@ -87,11 +86,11 @@
         anything but path, so it is only safe to use it in requests sent over
         the medium from the matching transport.
         """
-        base = self._shared_connection.base
+        base = self._base
         if base.startswith('bzr+http://') or base.startswith('bzr+https://'):
-            medium_base = self._shared_connection.base
+            medium_base = self._base
         else:
-            medium_base = urlutils.join(self._shared_connection.base, '/')
+            medium_base = urlutils.join(self._base, '/')
             
         rel_url = urlutils.relative_url(medium_base, transport.base)
         return urllib.unquote(rel_url)

=== modified file 'bzrlib/tests/test_remote.py'
--- a/bzrlib/tests/test_remote.py	2008-03-28 06:42:20 +0000
+++ b/bzrlib/tests/test_remote.py	2008-03-28 08:05:51 +0000
@@ -140,7 +140,7 @@
         self.responses = responses
         self._calls = []
         self.expecting_body = False
-        _SmartClient.__init__(self, FakeMedium(fake_medium_base, self._calls))
+        _SmartClient.__init__(self, FakeMedium(self._calls), fake_medium_base)
 
     def call(self, method, *args):
         self._calls.append(('call', method, args))
@@ -162,14 +162,6 @@
 
 class FakeMedium(object):
 
-    def __init__(self, base, client_calls):
-        self.base = base
-        self.connection = FakeConnection(client_calls)
-        self._client_calls = client_calls
-
-
-class FakeConnection(object):
-
     def __init__(self, client_calls):
         self._remote_is_at_least_1_2 = True
         self._client_calls = client_calls

=== modified file 'bzrlib/tests/test_smart_transport.py'
--- a/bzrlib/tests/test_smart_transport.py	2008-03-27 06:10:18 +0000
+++ b/bzrlib/tests/test_smart_transport.py	2008-04-01 02:16:14 +0000
@@ -2047,7 +2047,7 @@
         input = StringIO("\n")
         output = StringIO()
         client_medium = medium.SmartSimplePipesClientMedium(input, output)
-        smart_client = client._SmartClient(client_medium)
+        smart_client = client._SmartClient(client_medium, 'ignored base')
         self.assertRaises(TypeError,
             smart_client.call_with_body_bytes, method, args, body)
         self.assertEqual("", output.getvalue())

=== modified file 'bzrlib/transport/__init__.py'
--- a/bzrlib/transport/__init__.py	2008-03-26 22:03:05 +0000
+++ b/bzrlib/transport/__init__.py	2008-03-28 08:58:43 +0000
@@ -626,6 +626,7 @@
         """
         raise errors.NoSmartMedium(self)
 
+    @deprecated_method(one_four)
     def get_shared_medium(self):
         """Return a smart client shared medium for this transport if possible.
 

=== modified file 'bzrlib/transport/remote.py'
--- a/bzrlib/transport/remote.py	2008-01-15 11:29:22 +0000
+++ b/bzrlib/transport/remote.py	2008-03-28 08:58:43 +0000
@@ -35,6 +35,7 @@
     urlutils,
     )
 from bzrlib.smart import client, medium, protocol
+from bzrlib.symbol_versioning import (deprecated_method, one_four)
 
 
 class _SmartStat(object):
@@ -104,9 +105,14 @@
             self._shared_connection = transport._SharedConnection(medium,
                                                                   credentials,
                                                                   self.base)
+        else:
+            if medium is None:
+                # No medium was specified, so share the medium from the
+                # _from_transport.
+                medium = self._shared_connection.connection
 
         if _client is None:
-            self._client = client._SmartClient(self.get_shared_medium())
+            self._client = client._SmartClient(medium, self.base)
         else:
             self._client = _client
 
@@ -144,6 +150,7 @@
     def get_smart_medium(self):
         return self._get_connection()
 
+    @deprecated_method(one_four)
     def get_shared_medium(self):
         return self._get_shared_connection()
 




More information about the bazaar-commits mailing list