~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/smart/client.py

  • Committer: Andrew Bennetts
  • Date: 2008-03-28 08:05:51 UTC
  • mto: This revision was merged to the branch mainline in revision 3321.
  • Revision ID: andrew.bennetts@canonical.com-20080328080551-n7f6rejuycnzn0p8
Change _SmartClient's API to accept a medium and a base, rather than a _SharedConnection.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
 
24
24
class _SmartClient(object):
25
25
 
26
 
    def __init__(self, shared_connection):
 
26
    def __init__(self, medium, base):
27
27
        """Constructor.
28
28
 
29
 
        :param shared_connection: a bzrlib.transport._SharedConnection
 
29
        :param medium: a SmartClientMedium
 
30
        :param base: a URL
30
31
        """
31
 
        self._shared_connection = shared_connection
32
 
 
33
 
    def get_smart_medium(self):
34
 
        return self._shared_connection.connection
 
32
        self._medium = medium
 
33
        self._base = base
35
34
 
36
35
    def call(self, method, *args):
37
36
        """Call a method on the remote server."""
47
46
            result, smart_protocol = smart_client.call_expecting_body(...)
48
47
            body = smart_protocol.read_body_bytes()
49
48
        """
50
 
        request = self.get_smart_medium().get_request()
 
49
        request = self._medium.get_request()
51
50
        smart_protocol = protocol.SmartClientRequestProtocolTwo(request)
52
51
        smart_protocol.call(method, *args)
53
52
        return smart_protocol.read_response_tuple(expect_body=True), smart_protocol
61
60
                raise TypeError('args must be byte strings, not %r' % (args,))
62
61
        if type(body) is not str:
63
62
            raise TypeError('body must be byte string, not %r' % (body,))
64
 
        request = self.get_smart_medium().get_request()
 
63
        request = self._medium.get_request()
65
64
        smart_protocol = protocol.SmartClientRequestProtocolOne(request)
66
65
        smart_protocol.call_with_body_bytes((method, ) + args, body)
67
66
        return smart_protocol.read_response_tuple()
75
74
                raise TypeError('args must be byte strings, not %r' % (args,))
76
75
        if type(body) is not str:
77
76
            raise TypeError('body must be byte string, not %r' % (body,))
78
 
        request = self.get_smart_medium().get_request()
 
77
        request = self._medium.get_request()
79
78
        smart_protocol = protocol.SmartClientRequestProtocolTwo(request)
80
79
        smart_protocol.call_with_body_bytes((method, ) + args, body)
81
80
        return smart_protocol.read_response_tuple(expect_body=True), smart_protocol
87
86
        anything but path, so it is only safe to use it in requests sent over
88
87
        the medium from the matching transport.
89
88
        """
90
 
        base = self._shared_connection.base
 
89
        base = self._base
91
90
        if base.startswith('bzr+http://') or base.startswith('bzr+https://'):
92
 
            medium_base = self._shared_connection.base
 
91
            medium_base = self._base
93
92
        else:
94
 
            medium_base = urlutils.join(self._shared_connection.base, '/')
 
93
            medium_base = urlutils.join(self._base, '/')
95
94
            
96
95
        rel_url = urlutils.relative_url(medium_base, transport.base)
97
96
        return urllib.unquote(rel_url)